Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openeuler
openEuler-Advisor
提交
ace3b282
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看板
提交
ace3b282
编写于
9月 03, 2020
作者:
J
jiangpengju
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
重构单包查询的代码,主要优化点源码包生成子包,子包提供的组件和二进包所需要的组件,及其这些组件被哪些二进制包所依赖和被哪些二进制包所提供。
上级
f48313d2
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
141 addition
and
100 deletion
+141
-100
packageship/packageship/application/apps/package/function/packages.py
...packageship/application/apps/package/function/packages.py
+141
-97
packageship/test/common_files/correct_test_result_json/get_single_package.json
...on_files/correct_test_result_json/get_single_package.json
+0
-2
packageship/test/test_module/single_package_tests/test_get_singlepack.py
...t/test_module/single_package_tests/test_get_singlepack.py
+0
-1
未找到文件。
packageship/packageship/application/apps/package/function/packages.py
浏览文件 @
ace3b282
...
...
@@ -8,6 +8,7 @@ import math
from
flask
import
current_app
,
jsonify
from
sqlalchemy
import
text
from
sqlalchemy.exc
import
SQLAlchemyError
,
DisconnectionError
...
...
@@ -20,7 +21,6 @@ from packageship.application.models.package import PackagesMaintainer
from
packageship.application.models.package
import
PackagesIssue
from
packageship.application.models.package
import
SrcRequires
from
packageship.application.models.package
import
BinPack
from
packageship.application.models.package
import
BinRequires
from
packageship.application.models.package
import
BinProvides
from
packageship.libs.exception
import
Error
from
packageship.application.models.package
import
Packages
...
...
@@ -159,8 +159,8 @@ def sing_pack(srcname, tablename):
pack_info_dict
=
SinglePackInfoSchema
(
many
=
False
).
dump
(
package_info_obj
)
pack_info_dict
=
parsing_maintainner
(
srcname
,
pack_info_dict
)
issue_count
=
database_name
.
session
.
query
(
PackagesIssue
).
filter_by
(
pkg_name
=
package_info_obj
.
name
).
count
()
issue_count
=
database_name
.
session
.
query
(
PackagesIssue
).
filter_by
(
pkg_name
=
package_info_obj
.
name
).
count
()
pack_info_dict
[
"issue"
]
=
issue_count
buildrequired
=
buildrequired_search
(
srcname
,
tablename
)
pack_info_dict
[
"buildrequired"
]
=
buildrequired
...
...
@@ -180,7 +180,8 @@ def sing_pack(srcname, tablename):
ResponseCode
.
response_json
(
ResponseCode
.
DIS_CONNECTION_DB
))
def
parsing_maintainner
(
srcname
,
pack_info_dict
):
def
parsing_maintainner
(
srcname
,
pack_info_dict
):
"""
Single package query maintainer and maintainlevel
Args:
...
...
@@ -190,8 +191,8 @@ def parsing_maintainner(srcname,pack_info_dict):
"""
with
DBHelper
(
db_name
=
"lifecycle"
)
as
database_name
:
maintainer_obj
=
database_name
.
session
.
query
(
PackagesMaintainer
).
filter_by
(
name
=
srcname
).
first
()
maintainer_obj
=
database_name
.
session
.
query
(
PackagesMaintainer
).
filter_by
(
name
=
srcname
).
first
()
if
maintainer_obj
is
None
:
pack_info_dict
[
"maintainer"
]
=
None
pack_info_dict
[
"maintainlevel"
]
=
None
...
...
@@ -238,104 +239,147 @@ def buildrequired_search(srcname, tablename):
return
builddep
def
_sub_pack
(
srcname
,
tablename
):
def
helper
(
cls
):
"""
Auxiliary function
The returned data format is converted,
the main function is to convert a dictionary to a list
Args:
cls: Data before conversion
Returns:
Converted data
"""
for
obj
in
cls
:
if
"provides"
in
obj
:
obj
[
"provides"
]
=
list
(
obj
[
"provides"
].
values
())
for
values_p
in
obj
[
"provides"
]:
if
'requiredby'
in
values_p
:
values_p
[
'requiredby'
]
=
list
(
values_p
[
'requiredby'
].
values
())
if
"requires"
in
obj
:
obj
[
"requires"
]
=
list
(
obj
[
"requires"
].
values
())
for
values_r
in
obj
[
"requires"
]:
if
"providedby"
in
values_r
:
values_r
[
'providedby'
]
=
list
(
values_r
[
'providedby'
].
values
())
def
_sub_pack
(
src_name
,
table_name
):
"""
One-level installation dependency of the source package
to generate the binary package
Args:
srcname: The name of the source package
tablename: The name of the table in the database
Returns:
One-level installation dependency of the source package to
generate the binary package
"""
with
DBHelper
(
db_name
=
tablename
)
as
data_name
:
src_pack_obj
=
data_name
.
session
.
query
(
SrcPack
).
filter_by
(
name
=
srcname
).
first
()
if
src_pack_obj
is
None
:
return
[]
# Sub-packages generated by the source package
bin_pack_set
=
data_name
.
session
.
query
(
BinPack
).
filter_by
(
src_name
=
src_pack_obj
.
name
).
all
()
pack_list
=
list
()
for
bin_pack_obj
in
bin_pack_set
:
bin_pack_dict
=
dict
()
bin_pack_dict
[
'id'
]
=
bin_pack_obj
.
pkgKey
bin_pack_dict
[
'name'
]
=
bin_pack_obj
.
name
# Sub-package lookup provided components
bin_provides_set
=
data_name
.
session
.
query
(
BinProvides
).
filter_by
(
pkgKey
=
bin_pack_obj
.
pkgKey
).
all
()
provide_list
=
provide_
(
tablename
,
bin_provides_set
)
bin_pack_dict
[
'provides'
]
=
provide_list
bin_require_set
=
data_name
.
session
.
query
(
BinRequires
).
filter_by
(
pkgKey
=
bin_pack_obj
.
pkgKey
).
all
()
require_list
=
require_
(
tablename
,
bin_require_set
)
bin_pack_dict
[
'requires'
]
=
require_list
pack_list
.
append
(
bin_pack_dict
)
return
pack_list
def
provide_
(
tablename
,
bin_provides_set
):
"""
pkgKey goes to the bin_pack table to obtain
bin_name corresponding to requiredby
Args:
tablename: table name
bin_provides_set: Query set provided by the binary package
Returns:
provide_list: Provided list
"""
with
DBHelper
(
db_name
=
tablename
)
as
data_name
:
provide_list
=
[]
for
bin_provides_obj
in
bin_provides_set
:
bin_provides_dict
=
dict
()
bin_provides_dict
[
'id'
]
=
bin_provides_obj
.
id
bin_provides_dict
[
'name'
]
=
bin_provides_obj
.
name
reqired_set
=
data_name
.
session
.
query
(
BinRequires
).
filter_by
(
name
=
bin_provides_obj
.
name
).
all
()
required_pkgkey_list
=
[
reqired_obj
.
pkgKey
for
reqired_obj
in
reqired_set
]
required_bin_set
=
data_name
.
session
.
query
(
BinPack
).
filter
(
BinPack
.
pkgKey
.
in_
(
required_pkgkey_list
)).
all
()
requiredby
=
[
required_bin_obj
.
name
for
required_bin_obj
in
required_bin_set
]
bin_provides_dict
[
'requiredby'
]
=
requiredby
provide_list
.
append
(
bin_provides_dict
)
return
provide_list
def
require_
(
tablename
,
bin_require_set
):
"""
pkgKey goes to the bin_pack table to obtain
bin_name corresponding to provideBy
Args:
tablename: table name
bin_provides_set: Query set provided by the binary package
Returns:
require_list: require list
"""
with
DBHelper
(
db_name
=
tablename
)
as
data_name
:
# Sub-package to find the required components
require_list
=
[]
for
bin_require_obj
in
bin_require_set
:
bin_require_dict
=
dict
()
bin_require_dict
[
'id'
]
=
bin_require_obj
.
id
bin_require_dict
[
'name'
]
=
bin_require_obj
.
name
provide_set
=
data_name
.
session
.
query
(
BinProvides
).
filter_by
(
name
=
bin_require_obj
.
name
).
all
()
provide_pkg_list
=
[
provide_obj
.
pkgKey
for
provide_obj
in
provide_set
]
required_bin_set
=
data_name
.
session
.
query
(
BinPack
).
filter
(
BinPack
.
pkgKey
.
in_
(
provide_pkg_list
)).
all
()
providedby
=
[
required_bin_obj
.
name
for
required_bin_obj
in
required_bin_set
]
bin_require_dict
[
'providedby'
]
=
providedby
require_list
.
append
(
bin_require_dict
)
return
require_list
with
DBHelper
(
db_name
=
table_name
)
as
database
:
sql_str
=
"""
SELECT DISTINCT
b2.pkgKey AS sub_id,
b2.name AS sub_name,
pro.id AS sub_pro_id,
pro.name AS sub_pro_name,
b1.name AS sub_reqby_name
FROM
( select pkgKey,name,src_name from bin_pack where src_name=:src_name) b2
left join bin_provides pro on b2.pkgKey=pro.pkgKey
LEFT JOIN bin_requires req ON req.name = pro.name
LEFT JOIN bin_pack b1 ON req.pkgKey = b1.pkgKey;
"""
res
=
{}
res_pro
=
database
.
session
.
execute
(
text
(
sql_str
),
{
"src_name"
:
src_name
}).
fetchall
()
for
pro_obj
in
res_pro
:
if
pro_obj
.
sub_name
not
in
res
:
res
[
pro_obj
.
sub_name
]
=
{
"id"
:
pro_obj
.
sub_id
,
"name"
:
pro_obj
.
sub_name
,
"provides"
:
{
pro_obj
.
sub_pro_name
:
{
"id"
:
pro_obj
.
sub_pro_id
,
"name"
:
pro_obj
.
sub_pro_name
,
"requiredby"
:
{
pro_obj
.
sub_reqby_name
:
pro_obj
.
sub_reqby_name
}
if
pro_obj
.
sub_reqby_name
else
{}
}
}
if
pro_obj
.
sub_pro_name
else
{}
}
else
:
pro_info
=
res
[
pro_obj
.
sub_name
][
"provides"
]
if
pro_obj
.
sub_pro_name
in
pro_info
:
pro_info
[
pro_obj
.
sub_pro_name
][
"requiredby"
].
update
(
{
pro_obj
.
sub_reqby_name
:
pro_obj
.
sub_reqby_name
})
else
:
pro_info
.
update
(
{
pro_obj
.
sub_pro_name
:
{
"id"
:
pro_obj
.
sub_pro_id
,
"name"
:
pro_obj
.
sub_pro_name
,
"requiredby"
:
{
pro_obj
.
sub_reqby_name
:
pro_obj
.
sub_reqby_name
}
if
pro_obj
.
sub_reqby_name
else
{}
}
if
pro_obj
.
sub_pro_name
else
{}
}
)
sql_re
=
"""
SELECT DISTINCT
b2.pkgKey AS sub_id,
b2.name AS sub_name,
req.id AS sub_req_id,
req.name AS sub_req_name,
b1.name AS sub_proby_name
FROM
( SELECT pkgKey, name, src_name FROM bin_pack WHERE src_name = :src_name ) b2
LEFT JOIN bin_requires req ON b2.pkgKey = req.pkgKey
LEFT JOIN bin_provides pro ON pro.name = req.name
LEFT JOIN bin_pack b1 ON pro.pkgKey = b1.pkgKey;
"""
res_req
=
database
.
session
.
execute
(
text
(
sql_re
),
{
"src_name"
:
src_name
}).
fetchall
()
for
req_obj
in
res_req
:
sub_pkg_info
=
res
[
req_obj
.
sub_name
]
# if req_obj.sub_name not in sub_pkg_info:
if
"requires"
not
in
sub_pkg_info
:
if
not
req_obj
.
sub_req_name
:
sub_pkg_info
[
'requires'
]
=
{}
else
:
sub_pkg_info
.
update
(
{
"requires"
:
{
req_obj
.
sub_req_name
:
{
"id"
:
req_obj
.
sub_req_id
,
"name"
:
req_obj
.
sub_req_name
,
"providedby"
:
{
req_obj
.
sub_proby_name
:
req_obj
.
sub_proby_name
}
if
req_obj
.
sub_proby_name
else
{}
}
}
}
)
else
:
req_info
=
sub_pkg_info
[
"requires"
]
if
req_obj
.
sub_req_name
in
req_info
:
req_info
[
req_obj
.
sub_req_name
][
"providedby"
].
update
(
{
req_obj
.
sub_proby_name
:
req_obj
.
sub_proby_name
})
else
:
req_info
.
update
(
{
req_obj
.
sub_req_name
:
{
"id"
:
req_obj
.
sub_req_id
,
"name"
:
req_obj
.
sub_req_name
,
"providedby"
:
{
req_obj
.
sub_proby_name
:
req_obj
.
sub_proby_name
}
if
req_obj
.
sub_proby_name
else
{}
}
}
)
helper
([
values
for
k
,
values
in
res
.
items
()])
return
(
list
(
res
.
values
()))
packageship/test/common_files/correct_test_result_json/get_single_package.json
浏览文件 @
ace3b282
...
...
@@ -38,7 +38,6 @@
"id"
:
1
,
"name"
:
"Ac"
,
"providedby"
:
[
"C1"
,
"C1"
]
}
...
...
@@ -59,7 +58,6 @@
"id"
:
2
,
"name"
:
"Ac"
,
"providedby"
:
[
"C1"
,
"C1"
]
},
...
...
packageship/test/test_module/single_package_tests/test_get_singlepack.py
浏览文件 @
ace3b282
...
...
@@ -134,7 +134,6 @@ class TestGetSinglePack(ReadTestBase):
self
.
assertEqual
(
ResponseCode
.
CODE_MSG_MAP
.
get
(
ResponseCode
.
SUCCESS
),
resp_dict
.
get
(
"msg"
),
msg
=
"Error in status prompt return"
)
self
.
assertIn
(
"data"
,
resp_dict
,
msg
=
"Error in data format return"
)
self
.
assertTrue
(
compare_two_values
(
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录