Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openeuler
pyporter
提交
2ba3f2ce
P
pyporter
项目概览
openeuler
/
pyporter
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
pyporter
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
2ba3f2ce
编写于
7月 07, 2020
作者:
B
BruceGW
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix PEP8 checkstyle warnings
上级
e5b65c59
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
52 addition
and
56 deletion
+52
-56
pyporter
pyporter
+52
-56
未找到文件。
pyporter
浏览文件 @
2ba3f2ce
...
...
@@ -2,7 +2,7 @@
"""
This is a packager bot for python modules from pypi.org
"""
#******************************************************************************
#
******************************************************************************
# 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.
...
...
@@ -31,28 +31,29 @@ import os
import
platform
from
pathlib
import
Path
import
hashlib
# python3-wget is not default available on openEuler yet.
# import wget
json_file_template
=
'{pkg_name}.json'
name_tag_template
=
'Name:
\t\t
{pkg_name}'
summary_tag_template
=
'Summary:
\t
{pkg_sum}'
version_tag_template
=
'Version:
\t
{pkg_ver}'
name_tag_template
=
'Name:
\t\t
{pkg_name}'
summary_tag_template
=
'Summary:
\t
{pkg_sum}'
version_tag_template
=
'Version:
\t
{pkg_ver}'
release_tag_template
=
'Release:
\t
1'
license_tag_template
=
'License:
\t
{pkg_lic}'
home_tag_template
=
'URL:
\t\t
{pkg_home}'
license_tag_template
=
'License:
\t
{pkg_lic}'
home_tag_template
=
'URL:
\t\t
{pkg_home}'
source_tag_template
=
'Source0:
\t
{pkg_source}'
buildreq_tag_template
=
'BuildRequires:
\t
{req}'
# TODO List
# 1. Need a reliable way to get description of module .. Partially done
# 2. requires_dist has some dependency restirction, need to present
# 3. dependency outside python (i.e. pycurl depends on libcurl) doesn't exist in pipy
class
PyPorter
:
__url_template
=
'https://pypi.org/pypi/{pkg_name}/json'
__build_noarch
=
True
...
...
@@ -60,7 +61,7 @@ class PyPorter:
__module_name
=
""
__spec_name
=
""
__pkg_name
=
""
def
__init__
(
self
,
pkg
):
"""
receive json from pypi.org
...
...
@@ -69,15 +70,14 @@ class PyPorter:
resp
=
""
with
urllib
.
request
.
urlopen
(
url
)
as
u
:
self
.
__json
=
json
.
loads
(
u
.
read
().
decode
(
'utf-8'
))
if
(
self
.
__json
is
not
None
)
:
if
self
.
__json
is
not
None
:
self
.
__module_name
=
self
.
__json
[
"info"
][
"name"
]
self
.
__spec_name
=
"python-"
+
self
.
__module_name
self
.
__pkg_name
=
"python3-"
+
self
.
__module_name
self
.
__build_noarch
=
self
.
__get_buildarch
()
def
get_spec_name
(
self
):
return
self
.
__spec_name
return
self
.
__spec_name
def
get_module_name
(
self
):
return
self
.
__module_name
...
...
@@ -87,7 +87,7 @@ class PyPorter:
def
get_version
(
self
):
return
self
.
__json
[
"info"
][
"version"
]
def
get_summary
(
self
):
return
self
.
__json
[
"info"
][
"summary"
]
...
...
@@ -141,13 +141,6 @@ class PyPorter:
idx
=
r
.
find
(
";"
)
mod
=
transform_module_name
(
r
[:
idx
])
print
(
"Requires:
\t
"
+
mod
)
if
self
.
__json
[
"info"
][
"license"
]
!=
""
:
return
self
.
__json
[
"info"
][
"license"
]
for
k
in
self
.
__json
[
"info"
][
"classifiers"
]:
if
k
.
startswith
(
"License"
):
ks
=
k
.
split
(
"::"
)
return
ks
[
2
].
strip
()
return
""
def
__get_buildarch
(
self
):
"""
...
...
@@ -194,7 +187,7 @@ class PyPorter:
if
paragraph
>=
2
:
del
res
[
-
1
]
return
"
\n
"
.
join
(
res
)
if
res
!=
[]
:
if
res
:
return
"
\n
"
.
join
(
res
)
elif
paragraph
==
0
:
return
self
.
__json
[
"info"
][
"description"
]
...
...
@@ -202,12 +195,12 @@ class PyPorter:
return
self
.
__json
[
"info"
][
"summary"
]
def
get_build_requires
(
self
):
req_list
=
[]
req_list
=
[]
rds
=
self
.
__json
[
"info"
][
"requires_dist"
]
if
rds
is
not
None
:
for
rp
in
rds
:
br
=
refine_requires
(
rp
)
if
(
br
==
""
)
:
if
br
==
""
:
continue
#
# Do not output BuildRequires:
...
...
@@ -215,36 +208,38 @@ class PyPorter:
# than can help to build all rpm withoud trap into
# build dependency nightmare
#
#print(buildreq_tag_template.format(req=br))
name
=
str
.
lstrip
(
br
).
split
(
" "
)
#
print(buildreq_tag_template.format(req=br))
name
=
str
.
lstrip
(
br
).
split
(
" "
)
req_list
.
append
(
name
[
0
])
return
req_list
def
prepare_build_requires
(
self
):
print
(
buildreq_tag_template
.
format
(
req
=
'python3-devel'
))
print
(
buildreq_tag_template
.
format
(
req
=
'python3-setuptools'
))
if
(
self
.
__build_noarch
==
False
)
:
if
not
self
.
__build_noarch
:
print
(
buildreq_tag_template
.
format
(
req
=
'python3-cffi'
))
print
(
buildreq_tag_template
.
format
(
req
=
'gcc'
))
print
(
buildreq_tag_template
.
format
(
req
=
'gdb'
))
def
prepare_pkg_build
(
self
):
print
(
"%py3_build"
)
def
prepare_pkg_install
(
self
):
print
(
"%py3_install"
)
def
prepare_pkg_files
(
self
):
if
self
.
__build_noarch
:
print
(
"%dir %{python3_sitelib}/*"
)
else
:
print
(
"%dir %{python3_sitearch}/*"
)
def
store_json
(
self
,
spath
):
"""
save json file
"""
fname
=
json_file_template
.
format
(
pkg_name
=
self
.
__pkg_name
)
json_file
=
os
.
path
.
join
(
spath
,
fname
)
# if file exist, do nothing
if
path
.
exists
(
json_file
)
and
path
.
isfile
(
json_file
):
with
open
(
json_file
,
'r'
)
as
f
:
...
...
@@ -267,7 +262,7 @@ def transform_module_name(n):
if
ns
[
0
].
startswith
(
"python-"
):
ns
[
0
]
=
ns
[
0
].
replace
(
"python-"
,
"python3-"
)
else
:
ns
[
0
]
=
"python3-"
+
ns
[
0
]
ns
[
0
]
=
"python3-"
+
ns
[
0
]
if
ns
[
0
].
find
(
"/"
)
!=
-
1
or
ns
[
0
].
find
(
"."
)
!=
-
1
:
return
""
"""
...
...
@@ -297,7 +292,7 @@ def download_source(porter, tgtpath):
"""
download source file from url, and save it to target path
"""
if
(
os
.
path
.
exists
(
tgtpath
)
==
False
):
if
not
os
.
path
.
exists
(
tgtpath
):
print
(
"download path %s does not exist
\n
"
,
tgtpath
)
return
False
s_info
=
porter
.
get_source_info
()
...
...
@@ -321,17 +316,17 @@ def prepare_rpm_build_env(root):
"""
prepare environment for rpmbuild
"""
if
(
os
.
path
.
exists
(
root
)
==
False
):
if
not
os
.
path
.
exists
(
root
):
print
(
"Root path %s does not exist
\n
"
&
buildroot
)
return
""
buildroot
=
os
.
path
.
join
(
root
,
"rpmbuild"
)
if
(
os
.
path
.
exists
(
buildroot
)
==
False
):
if
not
os
.
path
.
exists
(
buildroot
):
os
.
mkdir
(
buildroot
)
for
sdir
in
[
'SPECS'
,
'BUILD'
,
'SOURCES'
,
'SRPMS'
,
'RPMS'
,
'BUILDROOT'
]:
bpath
=
os
.
path
.
join
(
buildroot
,
sdir
)
if
(
os
.
path
.
exists
(
bpath
)
==
False
):
if
not
os
.
path
.
exists
(
bpath
):
os
.
mkdir
(
bpath
)
return
buildroot
...
...
@@ -356,6 +351,7 @@ def try_pip_install_package(pkg):
#
return
True
def
package_installed
(
pkg
):
print
(
pkg
)
ret
=
subprocess
.
call
([
"rpm"
,
"-qi"
,
pkg
])
...
...
@@ -373,6 +369,7 @@ def dependencies_ready(req_list):
# return req
return
""
def
build_package
(
specfile
):
"""
build rpm package with rpmbuild
...
...
@@ -383,28 +380,29 @@ def build_package(specfile):
def
build_install_rpm
(
porter
,
rootpath
):
ret
=
build_rpm
(
porter
,
rootpath
)
if
(
ret
!=
""
)
:
if
ret
!=
""
:
return
ret
arch
=
"noarch"
if
(
porter
.
is_build_noarch
()
):
if
porter
.
is_build_noarch
(
):
arch
=
"noarch"
else
:
arch
=
platform
.
machine
()
pkgname
=
os
.
path
.
join
(
rootpath
,
"rpmbuild"
,
"RPMS"
,
arch
,
porter
.
get_pkg_name
()
+
"*"
)
ret
=
subprocess
.
call
([
"rpm"
,
"-ivh"
,
pkgname
])
if
(
ret
!=
0
)
:
if
ret
!=
0
:
return
"Install failed
\n
"
return
""
def
build_rpm
(
porter
,
rootpath
):
"""
full process to build rpm
"""
buildroot
=
prepare_rpm_build_env
(
rootpath
)
if
(
buildroot
==
""
)
:
buildroot
=
prepare_rpm_build_env
(
rootpath
)
if
buildroot
==
""
:
return
False
specfile
=
os
.
path
.
join
(
buildroot
,
"SPECS"
,
porter
.
get_spec_name
()
+
".spec"
)
...
...
@@ -427,11 +425,11 @@ def build_spec(porter, output):
print out the spec file
"""
if
os
.
path
.
isdir
(
output
):
output
=
os
.
path
.
join
(
output
,
porter
.
get_spec_name
()
+
".spec"
)
output
=
os
.
path
.
join
(
output
,
porter
.
get_spec_name
()
+
".spec"
)
tmp
=
sys
.
stdout
if
(
output
!=
""
)
:
if
output
!=
""
:
sys
.
stdout
=
open
(
output
,
'w+'
)
print
(
"%global _empty_manifest_terminate_build 0"
)
print
(
name_tag_template
.
format
(
pkg_name
=
porter
.
get_spec_name
()))
print
(
version_tag_template
.
format
(
pkg_ver
=
porter
.
get_version
()))
...
...
@@ -454,7 +452,7 @@ def build_spec(porter, output):
porter
.
prepare_build_requires
()
build_req_list
=
porter
.
get_build_requires
()
build_req_list
=
porter
.
get_build_requires
()
print
(
"%description -n "
+
porter
.
get_pkg_name
())
print
(
porter
.
get_description
())
...
...
@@ -534,47 +532,45 @@ def do_args(root):
return
parser
def
porter_creator
(
t_str
,
pkg
):
if
(
t_str
==
"python"
)
:
if
t_str
==
"python"
:
return
PyPorter
(
pkg
)
return
None
if
__name__
==
"__main__"
:
dft_root_path
=
os
.
path
.
join
(
str
(
Path
.
home
()))
dft_root_path
=
os
.
path
.
join
(
str
(
Path
.
home
()))
parser
=
do_args
(
dft_root_path
)
args
=
parser
.
parse_args
()
porter
=
porter_creator
(
args
.
type
,
args
.
pkg
)
if
(
porter
is
None
)
:
if
porter
is
None
:
print
(
"Type %s is not supported now
\n
"
%
args
.
type
)
sys
.
exit
(
1
)
if
(
args
.
requires
):
reqlist
=
porter
.
get_build_requires
()
if
reqlist
is
not
None
:
for
req
in
reqlist
:
if
args
.
requires
:
req_list
=
porter
.
get_build_requires
()
if
req_list
is
not
None
:
for
req
in
req_list
:
print
(
req
)
elif
(
args
.
spec
)
:
elif
args
.
spec
:
build_spec
(
porter
,
args
.
output
)
elif
(
args
.
build
)
:
elif
args
.
build
:
ret
=
build_rpm
(
porter
,
args
.
rootpath
)
if
ret
!=
""
:
print
(
"build failed : BuildRequire : %s
\n
"
%
ret
)
sys
.
exit
(
1
)
elif
(
args
.
buildinstall
)
:
elif
args
.
buildinstall
:
ret
=
build_install_rpm
(
porter
,
args
.
rootpath
)
if
ret
!=
""
:
print
(
"Build & install failed
\n
"
)
sys
.
exit
(
1
)
elif
(
args
.
download
)
:
elif
args
.
download
:
download_source
(
porter
,
args
.
path
)
elif
(
args
.
json
)
:
elif
args
.
json
:
porter
.
store_json
(
args
.
path
)
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录