Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openeuler
openEuler-Advisor
提交
3f6080bf
O
openEuler-Advisor
项目概览
openeuler
/
openEuler-Advisor
通知
34
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看板
体验新版 GitCode,发现更多精彩内容 >>
提交
3f6080bf
编写于
7月 08, 2020
作者:
S
solarhu
提交者:
Gitee
7月 08, 2020
浏览文件
操作
浏览文件
下载
差异文件
!32 修改注释
Merge pull request !32 from 魔箭胖胖/master
上级
2340aca7
c24d71fe
变更
4
展开全部
显示空白变更内容
内联
并排
Showing
4 changed file
with
1023 addition
and
389 deletion
+1023
-389
packageship/packageship/application/initsystem/data_import.py
...ageship/packageship/application/initsystem/data_import.py
+314
-129
packageship/packageship/application/initsystem/datamerge.py
packageship/packageship/application/initsystem/datamerge.py
+133
-50
packageship/packageship/libs/dbutils/sqlalchemy_helper.py
packageship/packageship/libs/dbutils/sqlalchemy_helper.py
+98
-45
packageship/packageship/pkgship.py
packageship/packageship/pkgship.py
+478
-165
未找到文件。
packageship/packageship/application/initsystem/data_import.py
浏览文件 @
3f6080bf
此差异已折叠。
点击以展开。
packageship/packageship/application/initsystem/datamerge.py
浏览文件 @
3f6080bf
'''
Integration of multiple sqlite file data, including
reading sqlite database and inserting data
'''
#!/usr/bin/python3
"""
Description: Integration of multiple sqlite file data, including reading sqlite database and inserting data
Class: MergeData
"""
from
sqlalchemy.exc
import
SQLAlchemyError
from
packageship.application.models.temporarydb
import
src_package
from
packageship.application.models.temporarydb
import
src_requires
...
...
@@ -16,30 +17,50 @@ LOGGER = Log(__name__)
class
MergeData
():
'''
Load data from sqlite database
'''
"""
Description: Load data from sqlite database
Attributes:
db_file: Database file
db_type: Connected database type
datum_database: Base database name
"""
def
__init__
(
self
,
db_file
):
"""
Description: Class instance initialization
Args:
db_file: Database file
"""
self
.
db_file
=
db_file
self
.
db_type
=
'sqlite:///'
self
.
datum_database
=
'maintenance.information'
@
staticmethod
def
__columns
(
cursor
):
'''
functional description:Returns all the column names queried by the current cursor
'''
"""
Description: functional description:Returns all the column names queried by the current cursor
Args:
cursor: Cursor
Returns:
The first columns
Raises:
"""
return
[
col
[
0
]
for
col
in
cursor
.
description
]
def
get_package_data
(
self
):
'''
get binary package or source package data
'''
"""
Description: get binary package or source package data
Args:
Returns:
All source package data queried
Raises:
SQLAlchemyError: An error occurred while executing the sql statement
"""
try
:
with
DBHelper
(
db_name
=
self
.
db_file
,
db_type
=
self
.
db_type
,
import_database
=
True
)
\
with
DBHelper
(
db_name
=
self
.
db_file
,
db_type
=
self
.
db_type
,
import_database
=
True
)
\
as
database
:
src_packages_data
=
database
.
session
.
execute
(
"select pkgKey,name,version,rpm_license,url,rpm_sourcerpm from packages"
)
...
...
@@ -51,11 +72,17 @@ class MergeData():
return
None
def
get_requires_data
(
self
):
'''
get dependent package data of binary package or source package
'''
"""
Description: get dependent package data of binary package or source package
Args:
Returns:
All dependent data queried
Raises:
SQLAlchemyError: An error occurred while executing the sql statement
"""
try
:
with
DBHelper
(
db_name
=
self
.
db_file
,
db_type
=
self
.
db_type
,
import_database
=
True
)
\
with
DBHelper
(
db_name
=
self
.
db_file
,
db_type
=
self
.
db_type
,
import_database
=
True
)
\
as
database
:
requires
=
database
.
session
.
execute
(
"select pkgKey,name from requires"
)
...
...
@@ -66,11 +93,17 @@ class MergeData():
return
None
def
get_provides
(
self
):
'''
get the dependency package provided by the binary package
'''
"""
Description: get the dependency package provided by the binary package
Args:
Returns:
Query the component data provided by all binary packages
Raises:
SQLAlchemyError: An error occurred while executing the sql statement
"""
try
:
with
DBHelper
(
db_name
=
self
.
db_file
,
db_type
=
self
.
db_type
,
import_database
=
True
)
\
with
DBHelper
(
db_name
=
self
.
db_file
,
db_type
=
self
.
db_type
,
import_database
=
True
)
\
as
database
:
requires
=
database
.
session
.
execute
(
"select pkgKey,name from provides"
)
...
...
@@ -81,9 +114,15 @@ class MergeData():
return
None
def
get_maintenance_info
(
self
):
'''
Obtain the information of the maintainer
'''
"""
Description: Obtain the information of the maintainer
Args:
Returns:
Maintainer related information
Raises:
SQLAlchemyError: An error occurred while executing the sql statement
"""
try
:
if
not
hasattr
(
self
,
'mainter_infos'
):
self
.
mainter_infos
=
dict
()
...
...
@@ -99,9 +138,17 @@ class MergeData():
LOGGER
.
logger
.
error
(
sql_error
)
def
src_file_merge
(
self
,
src_package_key
,
db_file
):
'''
Source code related data integration
'''
"""
Description: Source code related data integration
Args:
src_package_key: The relevant key value of the source package
db_file: Database file
Returns:
Key value after successful data combination
(0, False) or (src_package_key, True)
Raises:
SQLAlchemyError: An error occurred while executing the sql statement
"""
self
.
get_maintenance_info
()
self
.
__compose_src_package
()
...
...
@@ -131,9 +178,15 @@ class MergeData():
return
(
src_package_key
,
True
)
def
__compose_src_package
(
self
):
'''
Combine source package data
'''
"""
Description: Combine source package data
Args:
Returns:
Raises:
"""
if
getattr
(
self
,
'src_package_datas'
,
None
)
is
None
:
self
.
src_package_datas
=
[]
...
...
@@ -160,9 +213,15 @@ class MergeData():
)
def
__compose_src_rquires
(
self
):
'''
Combine source package dependent package data
'''
"""
Description: Combine source package dependent package data
Args:
Returns:
Raises:
"""
if
getattr
(
self
,
'src_requires_dicts'
,
None
)
is
None
:
self
.
src_requires_dicts
=
dict
()
...
...
@@ -179,9 +238,15 @@ class MergeData():
)
def
__compose_bin_package
(
self
):
'''
Combine binary package data
'''
"""
Description: Combine binary package data
Args:
Returns:
Raises:
AttributeError
"""
if
getattr
(
self
,
'bin_package_datas'
,
None
)
is
None
:
self
.
bin_package_datas
=
[]
...
...
@@ -205,9 +270,14 @@ class MergeData():
)
def
__compose_bin_requires
(
self
):
'''
Combining binary dependent package data
'''
"""
Description: Combining binary dependent package data
Args:
Returns:
Raises:
"""
if
getattr
(
self
,
'bin_requires_dicts'
,
None
)
is
None
:
self
.
bin_requires_dicts
=
dict
()
...
...
@@ -222,9 +292,15 @@ class MergeData():
})
def
__compose_bin_provides
(
self
):
'''
Combine binary package data
'''
"""
Description: Combine binary package data
Args:
Returns:
Raises:
"""
if
getattr
(
self
,
'bin_provides_dicts'
,
None
)
is
None
:
self
.
bin_provides_dicts
=
dict
()
...
...
@@ -239,10 +315,17 @@ class MergeData():
})
def
bin_file_merge
(
self
,
bin_package_key
,
db_file
):
'''
Binary package related data integration
'''
"""
Description: Binary package related data integration
Args:
bin_package_key: Primary key of binary package
db_file: Database file
Returns:
Key value after successful data combination
(0, False) or (bin_package_key, True)
Raises:
SQLAlchemyError: An error occurred while executing the sql statement
"""
self
.
__compose_bin_package
()
# binary package dependent package integration
...
...
packageship/packageship/libs/dbutils/sqlalchemy_helper.py
浏览文件 @
3f6080bf
'''
Simple encapsulation of sqlalchemy orm framework operation database
'''
#!/usr/bin/python3
"""
Description: Simple encapsulation of sqlalchemy orm framework operation database
Class: DBHelper
"""
import
os
from
sqlalchemy
import
create_engine
from
sqlalchemy
import
MetaData
...
...
@@ -18,22 +19,34 @@ from packageship import system_config
class
DBHelper
():
'''
Database connection, operation public class
'''
"""
Description: Database connection, operation public class
Attributes:
user_name: Username
password: Password
ip_address: Ip address
port: Port
db_name: Database name
db_type: Database type
session: Session
"""
# The base class inherited by the data model
BASE
=
declarative_base
()
def
__init__
(
self
,
user_name
=
None
,
passwrod
=
None
,
ip_address
=
None
,
# pylint: disable=R0913
port
=
None
,
db_name
=
None
,
db_type
=
None
,
**
kwargs
):
"""
Description: Class instance initialization
"""
self
.
user_name
=
user_name
self
.
_readconfig
=
ReadConfig
()
if
self
.
user_name
is
None
:
self
.
user_name
=
self
.
_readconfig
.
get_database
(
'user_name'
)
self
.
passw
ro
d
=
passwrod
if
self
.
passw
ro
d
is
None
:
self
.
passw
ro
d
=
self
.
_readconfig
.
get_database
(
'password'
)
self
.
passw
or
d
=
passwrod
if
self
.
passw
or
d
is
None
:
self
.
passw
or
d
=
self
.
_readconfig
.
get_database
(
'password'
)
self
.
ip_address
=
ip_address
...
...
@@ -67,9 +80,15 @@ class DBHelper():
self
.
session
=
None
def
_create_engine
(
self
):
'''
Create a database connection object
'''
"""
Description: Create a database connection object
Args:
Returns:
Raises:
DisconnectionError: A disconnect is detected on a raw DB-API connection.
"""
if
self
.
db_type
.
startswith
(
'sqlite'
):
if
not
self
.
db_name
:
raise
DbnameNoneException
(
...
...
@@ -78,11 +97,11 @@ class DBHelper():
self
.
db_type
+
self
.
db_name
,
encoding
=
'utf-8'
,
convert_unicode
=
True
,
connect_args
=
{
'check_same_thread'
:
False
})
else
:
if
all
([
self
.
user_name
,
self
.
passw
ro
d
,
self
.
ip_address
,
self
.
port
,
self
.
db_name
]):
if
all
([
self
.
user_name
,
self
.
passw
or
d
,
self
.
ip_address
,
self
.
port
,
self
.
db_name
]):
# create connection object
self
.
engine
=
create_engine
(
URL
(
**
{
'database'
:
self
.
db_name
,
'username'
:
self
.
user_name
,
'password'
:
self
.
passw
ro
d
,
'password'
:
self
.
passw
or
d
,
'host'
:
self
.
ip_address
,
'port'
:
self
.
port
,
'drivername'
:
self
.
db_type
}),
...
...
@@ -93,9 +112,14 @@ class DBHelper():
'A disconnect is detected on a raw DB-API connection'
)
def
_db_file_path
(
self
):
'''
load the path stored in the sqlite database
'''
"""
Description: load the path stored in the sqlite database
Args:
Returns:
Raises:
"""
self
.
database_file_path
=
self
.
_readconfig
.
get_system
(
'data_base_path'
)
if
not
self
.
database_file_path
:
...
...
@@ -104,9 +128,15 @@ class DBHelper():
os
.
makedirs
(
self
.
database_file_path
)
def
__enter__
(
self
):
'''
functional description:Create a context manager for the database connection
'''
"""
Description: functional description:Create a context manager for the database connection
Args:
Returns:
Class instance
Raises:
"""
session
=
sessionmaker
()
if
getattr
(
self
,
'engine'
)
is
None
:
...
...
@@ -117,28 +147,42 @@ class DBHelper():
return
self
def
__exit__
(
self
,
exc_type
,
exc_val
,
exc_tb
):
'''
functional description:Release the database connection pool and close the connection
'''
"""
Description: functional description:Release the database connection pool and close the connection
Args:
Returns:
exc_type: Abnormal type
exc_val: Abnormal value
exc_tb: Abnormal table
Raises:
"""
self
.
session
.
close
()
@
classmethod
def
create_all
(
cls
,
db_name
=
None
):
'''
functional description:Create all database tables
parameter:
return value:
exception description:
modify record:
'''
"""
Description: functional description:Create all database tables
Args:
db_name: Database name
Returns:
Raises:
"""
cls
.
BASE
.
metadata
.
create_all
(
bind
=
cls
(
db_name
=
db_name
).
engine
)
def
create_table
(
self
,
tables
):
'''
Create a single table
'''
"""
Description: Create a single table
Args:
tables: Table
Returns:
Raises:
"""
meta
=
MetaData
(
self
.
engine
)
for
table_name
in
DBHelper
.
BASE
.
metadata
.
tables
.
keys
():
if
table_name
in
tables
:
...
...
@@ -147,12 +191,16 @@ class DBHelper():
table
.
create
()
def
add
(
self
,
entity
):
'''
functional description:Insert a single data entity
parameter:
return value:
"""
Description: Insert a single data entity
Args:
entity: Data entity
Return:
If the addition is successful, return the corresponding entity, otherwise return None
'''
Raises:
ContentNoneException: An exception occurred while content is none
SQLAlchemyError: An exception occurred while creating the database
"""
if
entity
is
None
:
raise
ContentNoneException
(
...
...
@@ -168,12 +216,17 @@ class DBHelper():
return
entity
def
batch_add
(
self
,
dicts
,
model
):
'''
functional description:tables for adding databases in bulk
parameter:
:param dicts:Entity dictionary data to be added
:param model:Solid model class
'''
"""
Description:tables for adding databases in bulk
Args:
dicts:Entity dictionary data to be added
model:Solid model class
Returns:
Raises:
TypeError: An exception occurred while incoming type does not meet expectations
SQLAlchemyError: An exception occurred while creating the database
"""
if
model
is
None
:
raise
ContentNoneException
(
'solid model must be specified'
)
...
...
packageship/packageship/pkgship.py
浏览文件 @
3f6080bf
此差异已折叠。
点击以展开。
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录