Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openeuler
openEuler-Advisor
提交
7ddab1ed
O
openEuler-Advisor
项目概览
openeuler
/
openEuler-Advisor
通知
43
Star
4
Fork
4
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
O
openEuler-Advisor
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
7ddab1ed
编写于
7月 03, 2020
作者:
O
openeuler-ci-bot
提交者:
Gitee
7月 03, 2020
浏览文件
操作
浏览文件
下载
差异文件
!23 给check_license增加了必要的警告
Merge pull request !23 from Shinwell_Hu/improve_license
上级
eb8f7de1
a7350662
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
45 addition
and
47 deletion
+45
-47
advisors/check_licenses.py
advisors/check_licenses.py
+45
-47
未找到文件。
advisors/check_licenses.py
浏览文件 @
7ddab1ed
#!/usr/bin/python3
#******************************************************************************
# Copyright (c) Huawei Technologies Co., Ltd. 2020-2020. All rights reserved.
# licensed under the Mulan PSL v2.
# You can use this software according to the terms and conditions of the Mulan PSL v2.
# You may obtain a copy of Mulan PSL v2 at:
# http://license.coscl.org.cn/MulanPSL2
# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
# PURPOSE.
# See the Mulan PSL v2 for more details.
# Author: wangchuangGG
# Create: 2020-06-27
# ******************************************************************************/
"""
Caution:
This script is for information only. It's known to provide false result in situations.
(1) This is a script that checks whether the licenses in the LICENSE file
in the tar package and the licenses in the SPEC file are the same.
If they are the same, output:
...
...
@@ -25,20 +42,6 @@
-d Specify the decompression path of the tar package,
default: /var/tmp/tmp_tarball
"""
#******************************************************************************
# Copyright (c) Huawei Technologies Co., Ltd. 2020-2020. All rights reserved.
# licensed under the Mulan PSL v2.
# You can use this software according to the terms and conditions of the Mulan PSL v2.
# You may obtain a copy of Mulan PSL v2 at:
# http://license.coscl.org.cn/MulanPSL2
# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
# PURPOSE.
# See the Mulan PSL v2 for more details.
# Author: wangchuangGG
# Create: 2020-06-27
# Description: provide a tool to check licenses in tar package and spec file
# ******************************************************************************/
import
argparse
import
configparser
...
...
@@ -49,9 +52,11 @@ import hashlib
import
tarfile
import
bz2
import
shutil
import
download
#
import download
import
chardet
import
logging
from
pyrpm.spec
import
Spec
,
replace_macros
logging
.
basicConfig
(
format
=
'%(message)s'
,
level
=
logging
.
INFO
)
licenses_for_license
=
[]
...
...
@@ -121,6 +126,9 @@ def extract_tar(tarball_path, extraction_path):
if
not
os
.
path
.
isfile
(
tarball_path
):
logging
.
error
(
"%s is not a tarball file"
,
tarball_path
)
exit
(
1
)
#cmd_list = ["tar", "xvf", tarball_path]
#subprocess.call(cmd_list)
with
tarfile
.
open
(
tarball_path
)
as
content
:
content
.
extractall
(
path
=
extraction_path
)
...
...
@@ -229,33 +237,22 @@ def scan_licenses_in_SPEC(specfile):
If no spec file or open file failed,
the program will exit with an error.
"""
if
not
specfile
.
endswith
(
".spec"
):
logging
.
error
(
"%s is not a spec file"
,
specfile
)
exit
(
1
)
try
:
with
open
(
specfile
,
'r'
)
as
specfd
:
lines
=
specfd
.
readlines
()
except
FileNotFoundError
:
logging
.
error
(
"no SPEC file found!"
)
exit
(
1
)
for
line
in
lines
:
if
line
.
startswith
(
"#"
):
continue
excludes
=
[
"and"
,
"AND"
]
if
line
.
startswith
(
"License"
):
splits
=
line
.
split
(
":"
)[
1
:]
words
=
":"
.
join
(
splits
).
strip
()
if
words
in
license_translations
:
real_words
=
license_translations
.
get
(
words
,
words
)
add_license_from_spec_file
(
real_words
)
else
:
words
=
clean_license_string
(
words
).
split
()
for
word
in
words
:
if
word
not
in
excludes
:
real_word
=
license_translations
.
get
(
word
,
word
)
logging
.
debug
(
"after translate license_string ==> "
"real_license: %s ==> %s"
,
word
,
real_word
)
add_license_from_spec_file
(
real_word
)
s_spec
=
Spec
.
from_file
(
specfile
)
license
=
replace_macros
(
s_spec
.
license
,
s_spec
)
excludes
=
[
"and"
,
"AND"
]
if
license
in
license_translations
:
real_words
=
license_translations
.
get
(
license
,
license
)
add_license_from_spec_file
(
real_words
)
else
:
words
=
clean_license_string
(
license
).
split
()
for
word
in
words
:
if
word
not
in
excludes
:
real_word
=
license_translations
.
get
(
word
,
word
)
logging
.
debug
(
"after translate license_string ==> "
"real_license: %s ==> %s"
,
word
,
real_word
)
add_license_from_spec_file
(
real_word
)
logging
.
debug
(
"
\n
all licenses from SPEC file is: %s"
,
licenses_for_spec
)
...
...
@@ -335,21 +332,22 @@ def process_licenses(args, download_path):
tarball_name
=
os
.
path
.
basename
(
tarball_path
)
extract_tar_name
=
os
.
path
.
splitext
(
tarball_name
)[
0
]
extract_file_name
=
os
.
path
.
splitext
(
extract_tar_name
)[
0
]
scan_licenses_in_LICENSE
(
os
.
path
.
join
(
download_path
,
extract_file_name
))
#scan_licenses_in_LICENSE(os.path.join(download_path, extract_file_name))
scan_licenses_in_LICENSE
(
download_path
)
specfile
=
args
.
specfile
scan_licenses_in_SPEC
(
specfile
)
if
check_licenses_is_same
():
logging
.
info
(
"licenses from LICENSES are same as form SPEC:"
"%s <==> %s"
,
licenses_for_license
,
licenses_for_spec
)
"%s == %s"
,
licenses_for_license
,
licenses_for_spec
)
sys
.
exit
(
0
)
else
:
logging
.
info
(
"licenses from LICENSES are not same as form SPEC:"
"%s <=
=
> %s"
,
licenses_for_license
,
licenses_for_spec
)
"%s <=> %s"
,
licenses_for_license
,
licenses_for_spec
)
if
args
.
writespec
:
overwrite_spec
(
specfile
)
exit
(
0
)
exit
(
0
)
sys
.
exit
(
1
)
if
__name__
==
'__main__'
:
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录