Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openeuler
openEuler-Advisor
提交
90879b52
O
openEuler-Advisor
项目概览
openeuler
/
openEuler-Advisor
通知
41
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看板
提交
90879b52
编写于
7月 03, 2020
作者:
S
Shinwell_Hu
提交者:
Gitee
7月 03, 2020
浏览文件
操作
浏览文件
下载
差异文件
!12 [version-recommend]修复若干python 代码格式规范问题
Merge pull request !12 from licihua/next
上级
1250f437
589857fc
变更
1
显示空白变更内容
内联
并排
Showing
1 changed file
with
124 addition
and
100 deletion
+124
-100
advisors/version_recommend.py
advisors/version_recommend.py
+124
-100
未找到文件。
advisors/version_recommend.py
浏览文件 @
90879b52
...
...
@@ -3,18 +3,24 @@
import
re
import
datetime
import
time
from
typing
import
List
__ALL__
=
[
"VersionRecommend"
]
class
VersionType
:
class
VersionType
(
object
):
def
__init__
(
self
):
self
.
_version_type
=
None
def
version_match
(
self
,
pkg_version
):
pass
def
latest_version
(
self
,
version_entry
):
version_entry
.
sort
(
reverse
=
True
)
version_entry
.
sort
(
reverse
=
True
)
return
version_entry
[
0
]
def
maintain_version
(
self
,
version_entry
,
current_version
,
pkg_type
):
_
=
version_entry
,
pkg_type
return
current_version
def
_max
(
self
,
z1
,
z2
):
...
...
@@ -39,13 +45,9 @@ class VersionType:
else
:
return
-
1
def
__init__
(
self
):
self
.
_version_type
=
''
def
get_version_mode
(
self
):
return
self
.
_version_type
def
_split
(
self
,
x
):
for
f
,
s
in
re
.
findall
(
r
'([\d.]+)|([^\d.]+)'
,
x
):
if
f
:
...
...
@@ -55,8 +57,8 @@ class VersionType:
yield
s
class
VersionTypeXYZW
(
VersionType
):
class
VersionType_x_y_z_w
(
VersionType
):
def
version_match
(
self
,
pkg_version
):
version
=
pkg_version
.
strip
()
digital_list
=
re
.
split
(
r
'[._-]'
,
version
)
...
...
@@ -168,10 +170,12 @@ class VersionType_x_y_z_w(VersionType):
return
''
def
__init__
(
self
):
super
().
__init__
()
self
.
_version_type
=
'x.y.z.w'
class
VersionType_x_y_z
(
VersionType
):
class
VersionTypeXYZ
(
VersionType
):
def
version_match
(
self
,
pkg_version
):
version
=
pkg_version
.
strip
()
digital_list
=
re
.
split
(
r
'[._-]'
,
version
)
...
...
@@ -263,10 +267,12 @@ class VersionType_x_y_z(VersionType):
return
''
def
__init__
(
self
):
super
().
__init__
()
self
.
_version_type
=
'x.y.z'
class
VersionType_x_y
(
VersionType
):
class
VersionTypeXY
(
VersionType
):
def
version_match
(
self
,
pkg_version
):
version
=
pkg_version
.
strip
()
digital_list
=
re
.
split
(
r
'[._-]'
,
version
)
...
...
@@ -279,6 +285,7 @@ class VersionType_x_y(VersionType):
return
True
def
__init__
(
self
):
super
().
__init__
()
self
.
_version_type
=
'x.y'
def
latest_version
(
self
,
version_entry
):
...
...
@@ -292,7 +299,6 @@ class VersionType_x_y(VersionType):
if
self
.
_max
(
x
,
version
[
0
])
<
0
:
x
=
version
[
0
]
version_candidate
=
[]
for
version
in
version_list
:
# 将第一位最大的列入候选列表,准备第二位比较
if
x
==
version
[
0
]:
...
...
@@ -309,7 +315,6 @@ class VersionType_x_y(VersionType):
if
self
.
_max
(
y
,
version
[
1
])
<
0
:
y
=
version
[
1
]
version_candidate
.
clear
()
for
version
in
version_list
:
# x.y 版本类型中会小概率出现三位版本号,需要将第二位最大的列入候选列表,准备第三位比较
if
len
(
version
)
<=
1
:
# 过滤仅一位的版本号
...
...
@@ -339,8 +344,7 @@ class VersionType_x_y(VersionType):
def
maintain_version
(
self
,
version_entry
,
current_version
,
pkg_type
):
version_candidate
=
[]
version_digital
=
re
.
split
(
r
'[._-]'
,
current_version
)
# 将版本号做拆分
x
=
[]
x
.
append
(
version_digital
[
0
])
x
=
[
version_digital
[
0
]]
for
version
in
version_entry
:
version_temp
=
re
.
split
(
r
'[._-]'
,
version
)
if
version_digital
[
0
]
==
version_temp
[
0
]:
# 如果版本号与当前版本前两位一致,说明是维护分支版本
...
...
@@ -359,7 +363,9 @@ class VersionType_x_y(VersionType):
x
.
append
(
y
)
return
'.'
.
join
(
x
)
class
VersionType_x
(
VersionType
):
class
VersionTypeX
(
VersionType
):
def
version_match
(
self
,
pkg_version
):
version
=
pkg_version
.
strip
()
digital_list
=
re
.
split
(
r
'[._-]'
,
version
)
...
...
@@ -370,9 +376,9 @@ class VersionType_x(VersionType):
return
True
def
latest_version
(
self
,
version_entry
):
if
len
(
version_entry
)
==
1
:
# 仅一个版本,当前即为最新版本
if
1
==
len
(
version_entry
)
:
# 仅一个版本,当前即为最新版本
return
version_entry
[
0
]
version_list
=
[]
version_list
:
List
[
List
[
str
]]
=
[]
for
version
in
version_entry
:
version_list
.
append
(
re
.
split
(
r
'[._-]'
,
version
))
# 将 version 拆分为列表,方便后续比较
x
=
'0'
...
...
@@ -402,8 +408,7 @@ class VersionType_x(VersionType):
def
maintain_version
(
self
,
version_entry
,
current_version
,
pkg_type
):
version_candidate
=
[]
version_digital
=
re
.
split
(
r
'[._-]'
,
current_version
)
# 将版本号做拆分
x
=
[]
x
.
append
(
version_digital
[
0
])
x
=
[
version_digital
[
0
]]
for
version
in
version_entry
:
version_temp
=
re
.
split
(
r
'[._-]'
,
version
)
if
version_digital
[
0
]
==
version_temp
[
0
]:
# 如果版本号与当前版本前两位一致,说明是维护分支版本
...
...
@@ -421,11 +426,14 @@ class VersionType_x(VersionType):
y
=
version
[
1
]
x
.
append
(
y
)
return
'.'
.
join
(
x
)
def
__init__
(
self
):
super
().
__init__
()
self
.
_version_type
=
'x'
class
VersionType_yyyy_x_y
(
VersionType
):
class
VersionTypeYyyyXY
(
VersionType
):
def
version_match
(
self
,
pkg_version
):
version
=
pkg_version
.
strip
()
digital_list
=
re
.
split
(
r
'[._-]'
,
version
)
...
...
@@ -454,10 +462,12 @@ class VersionType_yyyy_x_y(VersionType):
return
True
def
__init__
(
self
):
super
().
__init__
()
self
.
_version_type
=
'yyyy.x.y'
class
VersionType_yyyy_x
(
VersionType
):
class
VersionTypeYyyyX
(
VersionType
):
def
version_match
(
self
,
pkg_version
):
version
=
pkg_version
.
strip
()
digital_list
=
re
.
split
(
r
'[._-]'
,
version
)
...
...
@@ -475,10 +485,12 @@ class VersionType_yyyy_x(VersionType):
return
True
def
__init__
(
self
):
super
().
__init__
()
self
.
_version_type
=
'yyyy.x'
class
VersionType_yyyyw
(
VersionType
):
class
VersionTypeYyyyW
(
VersionType
):
def
version_match
(
self
,
pkg_version
):
version
=
pkg_version
.
strip
()
if
len
(
version
)
!=
5
:
# 共5 位
...
...
@@ -493,9 +505,12 @@ class VersionType_yyyyw(VersionType):
return
True
def
__init__
(
self
):
super
().
__init__
()
self
.
_version_type
=
'yyyyw'
class
VersionType_yyyy_mm_dd
(
VersionType
):
class
VersionTypeYyyyMmDd
(
VersionType
):
def
version_match
(
self
,
pkg_version
):
version
=
pkg_version
.
strip
()
digital_list
=
re
.
split
(
r
'[._-]'
,
version
)
...
...
@@ -515,7 +530,7 @@ class VersionType_yyyy_mm_dd(VersionType):
try
:
if
'_'
in
version
:
d_time
=
time
.
mktime
(
time
.
strptime
(
version
,
"%Y_%m_%d"
))
elif
'-'
in
version
:
elif
'-'
in
version
:
d_time
=
time
.
mktime
(
time
.
strptime
(
version
,
"%Y-%m-%d"
))
elif
'.'
in
version
:
d_time
=
time
.
mktime
(
time
.
strptime
(
version
,
"%Y.%m.%d"
))
...
...
@@ -528,15 +543,17 @@ class VersionType_yyyy_mm_dd(VersionType):
return
False
else
:
return
True
except
:
# 时间格式非法
except
ValueError
as
e
:
# 时间格式非法
print
(
'Time foramt failed %s.'
,
version
)
return
False
def
__init__
(
self
):
super
().
__init__
()
self
.
_version_type
=
'yyyy.mm.dd'
class
VersionType_yyyy_mm
(
VersionType
):
class
VersionTypeYyyyMm
(
VersionType
):
def
version_match
(
self
,
pkg_version
):
version
=
pkg_version
.
strip
()
digital_list
=
re
.
split
(
r
'[._-]'
,
version
)
...
...
@@ -559,20 +576,21 @@ class VersionType_yyyy_mm(VersionType):
return
True
def
__init__
(
self
):
super
().
__init__
()
self
.
_version_type
=
'yyyy.mm'
class
VersionType_yyyymm
(
VersionType
):
class
VersionTypeYyyyMm
(
VersionType
):
def
version_match
(
self
,
pkg_version
):
version
=
pkg_version
.
strip
()
if
len
(
version
)
!=
6
:
# 长度为6
return
False
if
not
version
.
isdigit
():
#
时间格式为数字
if
not
version
.
isdigit
():
#
时间格式为数字
return
False
digital_list
=
[]
digital_list
.
append
(
version
[
0
:
4
])
digital_list
.
append
(
version
[
4
:])
digital_list
=
[
version
[
0
:
4
],
version
[
4
:]]
if
len
(
digital_list
[
0
])
!=
4
:
# 第一位为发布年份,位数为4位
return
False
...
...
@@ -590,9 +608,12 @@ class VersionType_yyyymm(VersionType):
return
True
def
__init__
(
self
):
super
().
__init__
()
self
.
_version_type
=
'yyyymm'
class
VersionType_x_yymm_z
(
VersionType
):
class
VersionTypeXYymmZ
(
VersionType
):
def
version_match
(
self
,
pkg_version
):
version
=
pkg_version
.
strip
()
digital_list
=
re
.
split
(
r
'[._-]'
,
version
)
...
...
@@ -608,17 +629,19 @@ class VersionType_x_yymm_z(VersionType):
month
=
str
(
digital_list
[
1
][
-
2
:])
if
year
>
datetime
.
datetime
.
now
().
year
[
-
2
:]:
# 年份不能大于当前年份,不用考虑20000 年前的情况
return
False
if
month
>
12
or
month
==
0
:
if
month
>
'12'
or
month
==
'0'
:
return
False
if
len
(
digital_list
[
2
])
>
2
:
# 迭代号不大于2位
return
False
return
True
def
__init__
(
self
):
super
().
__init__
()
self
.
_version_type
=
'x.yymm.z'
class
VersionType_yyyymmdd
(
VersionType
):
class
VersionTypeYyyymmdd
(
VersionType
):
def
version_match
(
self
,
pkg_version
):
version
=
pkg_version
.
strip
()
if
len
(
version
)
!=
8
:
# 日期长度满足 8 位要求
...
...
@@ -642,17 +665,17 @@ class VersionType_yyyymmdd(VersionType):
return
False
else
:
return
True
except
:
# 时间格式非法
except
ValueError
as
e
:
# 时间格式非法
print
(
'Time format failed %s,'
,
version
)
return
False
def
__init__
(
self
):
super
().
__init__
()
self
.
_version_type
=
'yyyymmdd'
class
VersionRecommend
(
object
):
class
VersionRecommend
:
def
__init__
(
self
,
version_entry
,
current_version
,
pkg_type
):
self
.
latest_version
=
current_version
# 提供初值,避免 current_version 为空导致后面出现异常
self
.
maintain_version
=
current_version
...
...
@@ -667,18 +690,18 @@ class VersionRecommend:
def
_version_match
(
self
,
version_entry
):
version_method
=
{
VersionType
_x_y_z_w
():
0
,
VersionType
_x_y_z
():
0
,
VersionType
_x_y
():
0
,
VersionType
_x
():
0
,
VersionType
_yyyy_x_y
():
0
,
VersionType
_yyyy_x
():
0
,
VersionType
_yyyyw
():
0
,
VersionType
_yyyy_mm_d
d
():
0
,
VersionType
_yyyy_mm
():
0
,
VersionType
_yyyymm
():
0
,
VersionType
_x_yymm_z
():
0
,
VersionType
_yyyymmdd
():
0
}
version_method
=
{
VersionType
XYZW
():
0
,
VersionType
XYZ
():
0
,
VersionType
XY
():
0
,
VersionType
X
():
0
,
VersionType
YyyyXY
():
0
,
VersionType
YyyyX
():
0
,
VersionType
YyyyW
():
0
,
VersionType
YyyyMmD
d
():
0
,
VersionType
YyyyMm
():
0
,
VersionType
YyyyMm
():
0
,
VersionType
XYymmZ
():
0
,
VersionType
Yyyymmdd
():
0
}
if
not
version_entry
:
return
None
for
version
in
version_entry
[:]:
...
...
@@ -698,7 +721,7 @@ class VersionRecommend:
return
method
def
_version_valid
(
self
,
version
):
m
=
re
.
match
(
'^[a-z0-9_\-\.]*$'
,
version
)
m
=
re
.
match
(
"^[0-9a-zA-Z._-]*$"
,
version
)
if
m
is
None
:
# 版本号应该是 数字/小写字母/下划线/. 组成
return
False
...
...
@@ -738,6 +761,7 @@ class VersionRecommend:
if
__name__
==
'__main__'
:
version_recommend
=
VersionRecommend
([
'0.1'
,
'0.2'
,
'1.2.3'
,
'1.2.4'
,
'1.2.6'
,
'1.3.0'
,
'2.0.1'
,
'1.2'
,
'1.4'
,
'1.5-rc'
,
'2.0-rc'
],
'1.2.3'
,
0
)
version_recommend
=
VersionRecommend
(
[
'0.1'
,
'0.2'
,
'1.2.3'
,
'1.2.4'
,
'1.2.6'
,
'1.3.0'
,
'1.5-rc'
,
'2.0-rc'
],
'1.2.3'
,
0
)
print
(
'latest_version'
,
version_recommend
.
latest_version
)
print
(
'maintain_version'
,
version_recommend
.
maintain_version
)
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录