提交 1814be46 编写于 作者: Y Yiru Wang Mac

fix search logic based on new database structure

...@@ -21,6 +21,7 @@ import subprocess ...@@ -21,6 +21,7 @@ import subprocess
import os.path import os.path
import re import re
import datetime import datetime
import version_recommend
def download_source_url(spec, o_ver, n_ver): def download_source_url(spec, o_ver, n_ver):
""" """
...@@ -91,7 +92,6 @@ def create_spec(repo, spec_str, o_ver, n_ver, src_fn=None): ...@@ -91,7 +92,6 @@ def create_spec(repo, spec_str, o_ver, n_ver, src_fn=None):
if __name__ == "__main__": if __name__ == "__main__":
pars = argparse.ArgumentParser() pars = argparse.ArgumentParser()
pars.add_argument("pkg", type=str, help="The package to be upgraded") pars.add_argument("pkg", type=str, help="The package to be upgraded")
pars.add_argument("-o", "--old_version", type=str, help="Current upstream version of package")
pars.add_argument("-n", "--new_version", type=str, help="New upstream version of package will be upgrade to") pars.add_argument("-n", "--new_version", type=str, help="New upstream version of package will be upgrade to")
pars.add_argument("-s", "--create_spec", help="Create spec file", action="store_true") pars.add_argument("-s", "--create_spec", help="Create spec file", action="store_true")
pars.add_argument("-d", "--download", help="Download upstream source code", action="store_true") pars.add_argument("-d", "--download", help="Download upstream source code", action="store_true")
...@@ -101,12 +101,15 @@ if __name__ == "__main__": ...@@ -101,12 +101,15 @@ if __name__ == "__main__":
args = pars.parse_args() args = pars.parse_args()
my_gitee = gitee.Gitee() my_gitee = gitee.Gitee()
my_version = version_recommend.VersionType()
spec_string= my_gitee.get_spec(args.pkg) spec_string= my_gitee.get_spec(args.pkg)
s_spec = Spec.from_string(spec_string) s_spec = Spec.from_string(spec_string)
cur_ver = replace_macros(s_spec.version, s_spec)
if args.fork: if args.fork:
my_gitee.fork_repo(args.pkg) if not my_gitee.fork_repo(args.pkg):
print("The repo of {pkg} seems to have been forked.".format(pkg=args.pkg))
if args.clone: if args.clone:
user=my_gitee.token["user"] user=my_gitee.token["user"]
...@@ -114,7 +117,7 @@ if __name__ == "__main__": ...@@ -114,7 +117,7 @@ if __name__ == "__main__":
os.chdir(args.pkg) os.chdir(args.pkg)
if args.download: if args.download:
source_file = download_source_url(s_spec, args.old_version, args.new_version) source_file = download_source_url(s_spec, cur_ver, args.new_version)
if source_file: if source_file:
print(source_file) print(source_file)
else: else:
...@@ -130,7 +133,11 @@ if __name__ == "__main__": ...@@ -130,7 +133,11 @@ if __name__ == "__main__":
print("I'm too naive to handle complicated package.") print("I'm too naive to handle complicated package.")
print("This package has multiple in-house patches.") print("This package has multiple in-house patches.")
sys.exit(1) sys.exit(1)
create_spec(args.pkg, spec_string, args.old_version, args.new_version) if(my_version.compare(args.new_version, cur_ver) ==1):
create_spec(args.pkg, spec_string, cur_ver, args.new_version)
else:
print("Please check version of {pkg} will upgrade to, it's current version is {version}.".format(
pkg=args.pkg, version=cur_ver))
if args.PR: if args.PR:
my_gitee.create_pr(my_gitee.token["user"], args.pkg) my_gitee.create_pr(my_gitee.token["user"], args.pkg)
...@@ -7,23 +7,84 @@ from typing import List ...@@ -7,23 +7,84 @@ from typing import List
__ALL__ = ["VersionRecommend"] __ALL__ = ["VersionRecommend"]
"""
The base class of the version recommend, used to get the latest version and maintain version.
"""
class VersionType(object): class VersionType(object):
"""Base class for version recommend"""
def __init__(self): def __init__(self):
"""
Initialize.
:param None: No parameter
:returns: None
:raises: None
"""
self._version_type = None self._version_type = None
def version_match(self, pkg_version): def version_match(self, pkg_version):
"""
Version match.
:param pkg_version: Package version
:returns: None
:raises: None
"""
pass pass
def latest_version(self, version_entry): def latest_version(self, version_entry):
"""
Get the latest version.
:param version_entry: Package version list
:returns: None
:raises: None
"""
version_entry.sort(reverse=True) version_entry.sort(reverse=True)
return version_entry[0] return version_entry[0]
def maintain_version(self, version_entry, current_version, pkg_type): def maintain_version(self, version_entry, current_version, pkg_type):
"""
Get the maintain version.
:param version_entry: Package version list
:param current_version: Current version
:param pkg_type: Package type
:returns : Maintain version
:raises: None
"""
_ = version_entry, pkg_type _ = version_entry, pkg_type
return current_version return current_version
def _max(self, z1, z2): def compare(self, z1, z2):
"""
Get the max version.
:param z1: The first version
:param z2: The second version
:returns 1: z1 great then z2
:return -1: z2 great then z1
:return 0: z1 equal then z2
:raises: None
"""
return self._compare(self, z1, z2)
def _compare(self, z1, z2):
"""
Get the max version.
:param z1: The first version
:param z2: The second version
:returns 1: z1 great then z2
:return -1: z2 great then z1
:return 0: z1 equal then z2
:raises: None
"""
d1 = tuple(self._split(z1)) # 第一个参数版本号拆分,获取里面的数字/字母,得到序列 d1 = tuple(self._split(z1)) # 第一个参数版本号拆分,获取里面的数字/字母,得到序列
d2 = tuple(self._split(z2)) # 第二个参数版本号拆分,获取里面的数字/字母,得到序列 d2 = tuple(self._split(z2)) # 第二个参数版本号拆分,获取里面的数字/字母,得到序列
len1 = len(d1) len1 = len(d1)
...@@ -42,14 +103,30 @@ class VersionType(object): ...@@ -42,14 +103,30 @@ class VersionType(object):
return -1 return -1
if len1 > len2: if len1 > len2:
return 1 return 1
else: elif len1 < len2:
return -1 return -1
else:
return 0
def get_version_mode(self): def get_version_mode(self):
"""
Get the version mode.
:param: None
:returns: Version type
:raises: None
"""
return self._version_type return self._version_type
def _split(self, x): def _split(self, x):
for f, s in re.findall(r'([\d.]+)|([^\d.]+)', x): """
Split the input args.
:param x: Input args
:returns: The split result
:raises: None
"""
for f, s in re.findall(r'([\d]+)|([^\d.]+)', x):
if f: if f:
float(f) float(f)
yield f yield f
...@@ -58,8 +135,17 @@ class VersionType(object): ...@@ -58,8 +135,17 @@ class VersionType(object):
class VersionTypeXYZW(VersionType): class VersionTypeXYZW(VersionType):
"""Version type Class for x.y.z.w"""
def version_match(self, pkg_version): def version_match(self, pkg_version):
"""
Version match.
:param pkg_version: Package version
:returns True: Version match success
:returns False: version match fail
:raises: None
"""
version = pkg_version.strip() version = pkg_version.strip()
digital_list = re.split(r'[._-]', version) digital_list = re.split(r'[._-]', version)
if len(digital_list) != 4: # 通过 '.'分割后,应该剩下4位 if len(digital_list) != 4: # 通过 '.'分割后,应该剩下4位
...@@ -75,6 +161,15 @@ class VersionTypeXYZW(VersionType): ...@@ -75,6 +161,15 @@ class VersionTypeXYZW(VersionType):
return True return True
def maintain_version(self, version_entry, current_version, pkg_type): def maintain_version(self, version_entry, current_version, pkg_type):
"""
Get the maintain version.
:param version_entry: Package version list
:param current_version: Current version
:param pkg_type: Package type
:returns : Maintain version
:raises: None
"""
if len(version_entry) == 1: # 仅一个版本,当前即为最新版本 if len(version_entry) == 1: # 仅一个版本,当前即为最新版本
return version_entry[0] return version_entry[0]
...@@ -94,13 +189,20 @@ class VersionTypeXYZW(VersionType): ...@@ -94,13 +189,20 @@ class VersionTypeXYZW(VersionType):
if len(version) <= 3: if len(version) <= 3:
continue continue
if self._max(version[3], w) > 0: if self._compare(version[3], w) > 0:
w = version[3] w = version[3]
xyz.append(w) xyz.append(w)
return '.'.join(xyz) return '.'.join(xyz)
def latest_version(self, version_entry): def latest_version(self, version_entry):
"""
Get latest version.
:param version_entry: Package version list
:returns: latest version
:raises: None
"""
if len(version_entry) == 1: # 仅一个版本,当前即为最新版本 if len(version_entry) == 1: # 仅一个版本,当前即为最新版本
return version_entry[0] return version_entry[0]
version_list = [] version_list = []
...@@ -108,7 +210,7 @@ class VersionTypeXYZW(VersionType): ...@@ -108,7 +210,7 @@ class VersionTypeXYZW(VersionType):
version_list.append(re.split(r'[._-]', version)) # 将 version 拆分为列表,方便后续比较 version_list.append(re.split(r'[._-]', version)) # 将 version 拆分为列表,方便后续比较
x = '0' x = '0'
for version in version_list: # 第一轮比较取出最大的第一位 for version in version_list: # 第一轮比较取出最大的第一位
if self._max(x, version[0]) < 0: if self._compare(x, version[0]) < 0:
x = version[0] x = version[0]
version_candidate = [] version_candidate = []
...@@ -124,7 +226,7 @@ class VersionTypeXYZW(VersionType): ...@@ -124,7 +226,7 @@ class VersionTypeXYZW(VersionType):
for version in version_list: # 第二轮比较取出最大的第二位 for version in version_list: # 第二轮比较取出最大的第二位
if len(version) <= 1: # 过滤仅一位的版本号 if len(version) <= 1: # 过滤仅一位的版本号
continue continue
if self._max(y, version[1]) < 0: if self._compare(y, version[1]) < 0:
y = version[1] y = version[1]
version_candidate.clear() version_candidate.clear()
...@@ -140,7 +242,7 @@ class VersionTypeXYZW(VersionType): ...@@ -140,7 +242,7 @@ class VersionTypeXYZW(VersionType):
for version in version_list: # 第三轮比较取出最大的第三位 for version in version_list: # 第三轮比较取出最大的第三位
if len(version) <= 2: # 过滤仅二位的版本号 if len(version) <= 2: # 过滤仅二位的版本号
continue continue
if self._max(z, version[2]) < 0: if self._compare(z, version[2]) < 0:
z = version[2] z = version[2]
version_candidate.clear() version_candidate.clear()
...@@ -158,7 +260,7 @@ class VersionTypeXYZW(VersionType): ...@@ -158,7 +260,7 @@ class VersionTypeXYZW(VersionType):
for version in version_list: # 最后一位最大版本必须惟一,直接返回结果 for version in version_list: # 最后一位最大版本必须惟一,直接返回结果
if len(version) <= 3: # 过滤仅三位的版本号 if len(version) <= 3: # 过滤仅三位的版本号
continue continue
if self._max(w, version[3]) < 0: if self._compare(w, version[3]) < 0:
w = version[3] w = version[3]
for version in version_list: # 最后一位最大版本必须惟一,直接返回结果 for version in version_list: # 最后一位最大版本必须惟一,直接返回结果
...@@ -170,13 +272,29 @@ class VersionTypeXYZW(VersionType): ...@@ -170,13 +272,29 @@ class VersionTypeXYZW(VersionType):
return '' return ''
def __init__(self): def __init__(self):
"""
Initialize.
:param None: No parameter
:returns: None
:raises: None
"""
super().__init__() super().__init__()
self._version_type = 'x.y.z.w' self._version_type = 'x.y.z.w'
class VersionTypeXYZ(VersionType): class VersionTypeXYZ(VersionType):
"""Version type Class for x.y.z"""
def version_match(self, pkg_version): def version_match(self, pkg_version):
"""
Version match.
:param pkg_version: Package version
:returns True: Version match success
:returns False: version match fail
:raises: None
"""
version = pkg_version.strip() version = pkg_version.strip()
digital_list = re.split(r'[._-]', version) digital_list = re.split(r'[._-]', version)
if len(digital_list) != 3: # 通过 '.'分割后,应该剩下3位 if len(digital_list) != 3: # 通过 '.'分割后,应该剩下3位
...@@ -190,6 +308,15 @@ class VersionTypeXYZ(VersionType): ...@@ -190,6 +308,15 @@ class VersionTypeXYZ(VersionType):
return True return True
def maintain_version(self, version_entry, current_version, pkg_type): def maintain_version(self, version_entry, current_version, pkg_type):
"""
Get the maintain version.
:param version_entry: Package version list
:param current_version: Current version
:param pkg_type: Package type
:returns : Maintain version
:raises: None
"""
if len(version_entry) == 1: # 仅一个版本,当前即为最新版本 if len(version_entry) == 1: # 仅一个版本,当前即为最新版本
return version_entry[0] return version_entry[0]
...@@ -209,13 +336,20 @@ class VersionTypeXYZ(VersionType): ...@@ -209,13 +336,20 @@ class VersionTypeXYZ(VersionType):
if len(version) <= 2: if len(version) <= 2:
continue continue
if self._max(version[2], z) > 0: if self._compare(version[2], z) > 0:
z = version[2] z = version[2]
xy.append(z) xy.append(z)
return '.'.join(xy) return '.'.join(xy)
def latest_version(self, version_entry): def latest_version(self, version_entry):
"""
Get latest version.
:param version_entry: Package version list
:returns: latest version
:raises: None
"""
if len(version_entry) == 1: # 仅一个版本,当前即为最新版本 if len(version_entry) == 1: # 仅一个版本,当前即为最新版本
return version_entry[0] return version_entry[0]
version_list = [] version_list = []
...@@ -223,7 +357,7 @@ class VersionTypeXYZ(VersionType): ...@@ -223,7 +357,7 @@ class VersionTypeXYZ(VersionType):
version_list.append(re.split(r'[._-]', version)) # 将 version 拆分为列表,方便后续比较 version_list.append(re.split(r'[._-]', version)) # 将 version 拆分为列表,方便后续比较
x = '0' x = '0'
for version in version_list: # 第一轮比较取出最大的第一位 for version in version_list: # 第一轮比较取出最大的第一位
if self._max(x, version[0]) < 0: if self._compare(x, version[0]) < 0:
x = version[0] x = version[0]
version_candidate = [] version_candidate = []
...@@ -239,7 +373,7 @@ class VersionTypeXYZ(VersionType): ...@@ -239,7 +373,7 @@ class VersionTypeXYZ(VersionType):
for version in version_list: # 第二轮比较取出最大的第二位 for version in version_list: # 第二轮比较取出最大的第二位
if len(version) <= 1: # 过滤仅一位的版本号 if len(version) <= 1: # 过滤仅一位的版本号
continue continue
if self._max(y, version[1]) < 0: if self._compare(y, version[1]) < 0:
y = version[1] y = version[1]
version_candidate.clear() version_candidate.clear()
...@@ -255,7 +389,7 @@ class VersionTypeXYZ(VersionType): ...@@ -255,7 +389,7 @@ class VersionTypeXYZ(VersionType):
for version in version_list: # 第三轮比较取出最大的第三位 for version in version_list: # 第三轮比较取出最大的第三位
if len(version) <= 2: # 过滤仅二位的版本号 if len(version) <= 2: # 过滤仅二位的版本号
continue continue
if self._max(z, version[2]) < 0: if self._compare(z, version[2]) < 0:
z = version[2] z = version[2]
for version in version_list: # 最后一位最大版本必须惟一,直接返回结果 for version in version_list: # 最后一位最大版本必须惟一,直接返回结果
...@@ -267,13 +401,29 @@ class VersionTypeXYZ(VersionType): ...@@ -267,13 +401,29 @@ class VersionTypeXYZ(VersionType):
return '' return ''
def __init__(self): def __init__(self):
"""
Initialize.
:param None: No parameter
:returns: None
:raises: None
"""
super().__init__() super().__init__()
self._version_type = 'x.y.z' self._version_type = 'x.y.z'
class VersionTypeXY(VersionType): class VersionTypeXY(VersionType):
"""Version type Class for x.y"""
def version_match(self, pkg_version): def version_match(self, pkg_version):
"""
Version match.
:param pkg_version: Package version
:returns True: Version match success
:returns False: version match fail
:raises: None
"""
version = pkg_version.strip() version = pkg_version.strip()
digital_list = re.split(r'[._-]', version) digital_list = re.split(r'[._-]', version)
if len(digital_list) != 2: # 通过 '.'分割后,应该剩下2位 if len(digital_list) != 2: # 通过 '.'分割后,应该剩下2位
...@@ -285,10 +435,24 @@ class VersionTypeXY(VersionType): ...@@ -285,10 +435,24 @@ class VersionTypeXY(VersionType):
return True return True
def __init__(self): def __init__(self):
"""
Initialize.
:param None: No parameter
:returns: None
:raises: None
"""
super().__init__() super().__init__()
self._version_type = 'x.y' self._version_type = 'x.y'
def latest_version(self, version_entry): def latest_version(self, version_entry):
"""
Get latest version.
:param version_entry: Package version list
:returns: latest version
:raises: None
"""
if len(version_entry) == 1: # 仅一个版本,当前即为最新版本 if len(version_entry) == 1: # 仅一个版本,当前即为最新版本
return version_entry[0] return version_entry[0]
version_list = [] version_list = []
...@@ -296,7 +460,7 @@ class VersionTypeXY(VersionType): ...@@ -296,7 +460,7 @@ class VersionTypeXY(VersionType):
version_list.append(re.split(r'[._-]', version)) # 将 version 拆分为列表,方便后续比较 version_list.append(re.split(r'[._-]', version)) # 将 version 拆分为列表,方便后续比较
x = '0' x = '0'
for version in version_list: # 第一轮比较取出最大的第一位 for version in version_list: # 第一轮比较取出最大的第一位
if self._max(x, version[0]) < 0: if self._compare(x, version[0]) < 0:
x = version[0] x = version[0]
version_candidate = [] version_candidate = []
...@@ -312,7 +476,7 @@ class VersionTypeXY(VersionType): ...@@ -312,7 +476,7 @@ class VersionTypeXY(VersionType):
for version in version_list: # 第二轮比较取出最大的第二位 for version in version_list: # 第二轮比较取出最大的第二位
if len(version) <= 1: # 过滤仅一位的版本号 if len(version) <= 1: # 过滤仅一位的版本号
continue continue
if self._max(y, version[1]) < 0: if self._compare(y, version[1]) < 0:
y = version[1] y = version[1]
version_candidate.clear() version_candidate.clear()
...@@ -330,7 +494,7 @@ class VersionTypeXY(VersionType): ...@@ -330,7 +494,7 @@ class VersionTypeXY(VersionType):
for version in version_list: # 第三轮比较取出最大的第三位 for version in version_list: # 第三轮比较取出最大的第三位
if len(version) <= 2: # 过滤仅二位的版本号 if len(version) <= 2: # 过滤仅二位的版本号
continue continue
if self._max(z, version[2]) < 0: if self._compare(z, version[2]) < 0:
z = version[2] z = version[2]
for version in version_list: # 最后一位最大版本必须惟一,直接返回结果 for version in version_list: # 最后一位最大版本必须惟一,直接返回结果
...@@ -342,6 +506,15 @@ class VersionTypeXY(VersionType): ...@@ -342,6 +506,15 @@ class VersionTypeXY(VersionType):
return '' return ''
def maintain_version(self, version_entry, current_version, pkg_type): def maintain_version(self, version_entry, current_version, pkg_type):
"""
Get the maintain version.
:param version_entry: Package version list
:param current_version: Current version
:param pkg_type: Package type
:returns : Maintain version
:raises: None
"""
version_candidate = [] version_candidate = []
version_digital = re.split(r'[._-]', current_version) # 将版本号做拆分 version_digital = re.split(r'[._-]', current_version) # 将版本号做拆分
x = [version_digital[0]] x = [version_digital[0]]
...@@ -358,15 +531,24 @@ class VersionTypeXY(VersionType): ...@@ -358,15 +531,24 @@ class VersionTypeXY(VersionType):
if len(version) <= 1: if len(version) <= 1:
continue continue
if self._max(version[1], y) > 0: if self._compare(version[1], y) > 0:
y = version[1] y = version[1]
x.append(y) x.append(y)
return '.'.join(x) return '.'.join(x)
class VersionTypeX(VersionType): class VersionTypeX(VersionType):
"""Version type Class for x"""
def version_match(self, pkg_version): def version_match(self, pkg_version):
"""
Version match.
:param pkg_version: Package version
:returns True: Version match success
:returns False: version match fail
:raises: None
"""
version = pkg_version.strip() version = pkg_version.strip()
digital_list = re.split(r'[._-]', version) digital_list = re.split(r'[._-]', version)
if len(digital_list) != 1: # 通过 '.'分割后,应该剩下1位 if len(digital_list) != 1: # 通过 '.'分割后,应该剩下1位
...@@ -376,6 +558,13 @@ class VersionTypeX(VersionType): ...@@ -376,6 +558,13 @@ class VersionTypeX(VersionType):
return True return True
def latest_version(self, version_entry): def latest_version(self, version_entry):
"""
Get latest version.
:param version_entry: Package version list
:returns: latest version
:raises: None
"""
if 1 == len(version_entry): # 仅一个版本,当前即为最新版本 if 1 == len(version_entry): # 仅一个版本,当前即为最新版本
return version_entry[0] return version_entry[0]
version_list: List[List[str]] = [] version_list: List[List[str]] = []
...@@ -383,7 +572,7 @@ class VersionTypeX(VersionType): ...@@ -383,7 +572,7 @@ class VersionTypeX(VersionType):
version_list.append(re.split(r'[._-]', version)) # 将 version 拆分为列表,方便后续比较 version_list.append(re.split(r'[._-]', version)) # 将 version 拆分为列表,方便后续比较
x = '0' x = '0'
for version in version_list: # 第一轮比较取出最大的第一位 for version in version_list: # 第一轮比较取出最大的第一位
if self._max(x, version[0]) < 0: if self._compare(x, version[0]) < 0:
x = version[0] x = version[0]
version_candidate = [] version_candidate = []
...@@ -399,13 +588,22 @@ class VersionTypeX(VersionType): ...@@ -399,13 +588,22 @@ class VersionTypeX(VersionType):
for version in version_list: # 第二轮比较取出最大的第二位 for version in version_list: # 第二轮比较取出最大的第二位
if len(version) <= 1: # 过滤仅一位的版本号 if len(version) <= 1: # 过滤仅一位的版本号
continue continue
if self._max(y, version[1]) < 0: if self._compare(y, version[1]) < 0:
y = version[1] y = version[1]
x.append(y) x.append(y)
return '.'.join(x) return '.'.join(x)
def maintain_version(self, version_entry, current_version, pkg_type): def maintain_version(self, version_entry, current_version, pkg_type):
"""
Get the maintain version.
:param version_entry: Package version list
:param current_version: Current version
:param pkg_type: Package type
:returns : Maintain version
:raises: None
"""
version_candidate = [] version_candidate = []
version_digital = re.split(r'[._-]', current_version) # 将版本号做拆分 version_digital = re.split(r'[._-]', current_version) # 将版本号做拆分
x = [version_digital[0]] x = [version_digital[0]]
...@@ -422,19 +620,35 @@ class VersionTypeX(VersionType): ...@@ -422,19 +620,35 @@ class VersionTypeX(VersionType):
if len(version) <= 1: if len(version) <= 1:
continue continue
if self._max(version[1], y) > 0: if self._compare(version[1], y) > 0:
y = version[1] y = version[1]
x.append(y) x.append(y)
return '.'.join(x) return '.'.join(x)
def __init__(self): def __init__(self):
"""
Initialize.
:param None: No parameter
:returns: None
:raises: None
"""
super().__init__() super().__init__()
self._version_type = 'x' self._version_type = 'x'
class VersionTypeYyyyXY(VersionType): class VersionTypeYyyyXY(VersionType):
"""Version type Class for yyyy.x.y"""
def version_match(self, pkg_version): def version_match(self, pkg_version):
"""
Version match.
:param pkg_version: Package version
:returns True: Version match success
:returns False: version match fail
:raises: None
"""
version = pkg_version.strip() version = pkg_version.strip()
digital_list = re.split(r'[._-]', version) digital_list = re.split(r'[._-]', version)
if len(digital_list) != 3: # 通过 '.'分割后,应该剩下3位 if len(digital_list) != 3: # 通过 '.'分割后,应该剩下3位
...@@ -462,13 +676,29 @@ class VersionTypeYyyyXY(VersionType): ...@@ -462,13 +676,29 @@ class VersionTypeYyyyXY(VersionType):
return True return True
def __init__(self): def __init__(self):
"""
Initialize.
:param None: No parameter
:returns: None
:raises: None
"""
super().__init__() super().__init__()
self._version_type = 'yyyy.x.y' self._version_type = 'yyyy.x.y'
class VersionTypeYyyyX(VersionType): class VersionTypeYyyyX(VersionType):
"""Version type Class for yyyy.x"""
def version_match(self, pkg_version): def version_match(self, pkg_version):
"""
Version match.
:param pkg_version: Package version
:returns True: Version match success
:returns False: version match fail
:raises: None
"""
version = pkg_version.strip() version = pkg_version.strip()
digital_list = re.split(r'[._-]', version) digital_list = re.split(r'[._-]', version)
if len(digital_list) != 2: # 通过 '.'分割后,应该剩下2位 if len(digital_list) != 2: # 通过 '.'分割后,应该剩下2位
...@@ -485,13 +715,29 @@ class VersionTypeYyyyX(VersionType): ...@@ -485,13 +715,29 @@ class VersionTypeYyyyX(VersionType):
return True return True
def __init__(self): def __init__(self):
"""
Initialize.
:param None: No parameter
:returns: None
:raises: None
"""
super().__init__() super().__init__()
self._version_type = 'yyyy.x' self._version_type = 'yyyy.x'
class VersionTypeYyyyW(VersionType): class VersionTypeYyyyW(VersionType):
"""Version type Class for yyyyw"""
def version_match(self, pkg_version): def version_match(self, pkg_version):
"""
Version match.
:param pkg_version: Package version
:returns True: Version match success
:returns False: version match fail
:raises: None
"""
version = pkg_version.strip() version = pkg_version.strip()
if len(version) != 5: # 共5 位 if len(version) != 5: # 共5 位
return False return False
...@@ -505,13 +751,29 @@ class VersionTypeYyyyW(VersionType): ...@@ -505,13 +751,29 @@ class VersionTypeYyyyW(VersionType):
return True return True
def __init__(self): def __init__(self):
"""
Initialize.
:param None: No parameter
:returns: None
:raises: None
"""
super().__init__() super().__init__()
self._version_type = 'yyyyw' self._version_type = 'yyyyw'
class VersionTypeYyyyMmDd(VersionType): class VersionTypeYyyyMmDd(VersionType):
"""Version type Class for yyyy.mm.dd"""
def version_match(self, pkg_version): def version_match(self, pkg_version):
"""
Version match.
:param pkg_version: Package version
:returns True: Version match success
:returns False: version match fail
:raises: None
"""
version = pkg_version.strip() version = pkg_version.strip()
digital_list = re.split(r'[._-]', version) digital_list = re.split(r'[._-]', version)
if len(digital_list) != 3: # 通过 '.'分割后,应该剩下3位 if len(digital_list) != 3: # 通过 '.'分割后,应该剩下3位
...@@ -544,17 +806,34 @@ class VersionTypeYyyyMmDd(VersionType): ...@@ -544,17 +806,34 @@ class VersionTypeYyyyMmDd(VersionType):
else: else:
return True return True
except ValueError as e: # 时间格式非法 except ValueError as e: # 时间格式非法
_ = e
print('Time foramt failed %s.', version) print('Time foramt failed %s.', version)
return False return False
def __init__(self): def __init__(self):
"""
Initialize.
:param None: No parameter
:returns: None
:raises: None
"""
super().__init__() super().__init__()
self._version_type = 'yyyy.mm.dd' self._version_type = 'yyyy.mm.dd'
class VersionTypeYyyyMm(VersionType): class VersionTypeYyyyMm(VersionType):
"""Version type Class for yyyy.mm"""
def version_match(self, pkg_version): def version_match(self, pkg_version):
"""
Version match.
:param pkg_version: Package version
:returns True: Version match success
:returns False: version match fail
:raises: None
"""
version = pkg_version.strip() version = pkg_version.strip()
digital_list = re.split(r'[._-]', version) digital_list = re.split(r'[._-]', version)
if len(digital_list) != 2: # 通过 '.'分割后,应该剩下2位 if len(digital_list) != 2: # 通过 '.'分割后,应该剩下2位
...@@ -576,13 +855,29 @@ class VersionTypeYyyyMm(VersionType): ...@@ -576,13 +855,29 @@ class VersionTypeYyyyMm(VersionType):
return True return True
def __init__(self): def __init__(self):
"""
Initialize.
:param None: No parameter
:returns: None
:raises: None
"""
super().__init__() super().__init__()
self._version_type = 'yyyy.mm' self._version_type = 'yyyy.mm'
class VersionTypeYyyyMm(VersionType): class VersionTypeYyyymm(VersionType):
"""Version type Class for yyyy.mm"""
def version_match(self, pkg_version): def version_match(self, pkg_version):
"""
Version match.
:param pkg_version: Package version
:returns True: Version match success
:returns False: version match fail
:raises: None
"""
version = pkg_version.strip() version = pkg_version.strip()
if len(version) != 6: # 长度为6 if len(version) != 6: # 长度为6
return False return False
...@@ -608,13 +903,28 @@ class VersionTypeYyyyMm(VersionType): ...@@ -608,13 +903,28 @@ class VersionTypeYyyyMm(VersionType):
return True return True
def __init__(self): def __init__(self):
"""
Initialize.
:param None: No parameter
:returns: None
:raises: None
"""
super().__init__() super().__init__()
self._version_type = 'yyyymm' self._version_type = 'yyyymm'
class VersionTypeXYymmZ(VersionType): class VersionTypeXYymmZ(VersionType):
"""Version type Class for x.yymm.z"""
def version_match(self, pkg_version): def version_match(self, pkg_version):
"""
Version match.
:param pkg_version: Package version
:returns True: Version match success
:returns False: version match fail
:raises: None
"""
version = pkg_version.strip() version = pkg_version.strip()
digital_list = re.split(r'[._-]', version) digital_list = re.split(r'[._-]', version)
if len(digital_list) != 3: # 通过 '.'分割后,应该剩下3位 if len(digital_list) != 3: # 通过 '.'分割后,应该剩下3位
...@@ -636,13 +946,29 @@ class VersionTypeXYymmZ(VersionType): ...@@ -636,13 +946,29 @@ class VersionTypeXYymmZ(VersionType):
return True return True
def __init__(self): def __init__(self):
"""
Initialize.
:param None: No parameter
:returns: None
:raises: None
"""
super().__init__() super().__init__()
self._version_type = 'x.yymm.z' self._version_type = 'x.yymm.z'
class VersionTypeYyyymmdd(VersionType): class VersionTypeYyyymmdd(VersionType):
"""Version type Class for yyyymmdd"""
def version_match(self, pkg_version): def version_match(self, pkg_version):
"""
Version match.
:param pkg_version: Package version
:returns True: Version match success
:returns False: version match fail
:raises: None
"""
version = pkg_version.strip() version = pkg_version.strip()
if len(version) != 8: # 日期长度满足 8 位要求 if len(version) != 8: # 日期长度满足 8 位要求
return False return False
...@@ -666,17 +992,33 @@ class VersionTypeYyyymmdd(VersionType): ...@@ -666,17 +992,33 @@ class VersionTypeYyyymmdd(VersionType):
else: else:
return True return True
except ValueError as e: # 时间格式非法 except ValueError as e: # 时间格式非法
_ = e
print('Time format failed %s,', version) print('Time format failed %s,', version)
return False return False
def __init__(self): def __init__(self):
"""
Initialize.
:param None: No parameter
:returns: None
:raises: None
"""
super().__init__() super().__init__()
self._version_type = 'yyyymmdd' self._version_type = 'yyyymmdd'
class VersionRecommend(object): class VersionRecommend(object):
"""Version recommend Class for open source"""
def __init__(self, version_entry, current_version, pkg_type): def __init__(self, version_entry, current_version, pkg_type):
"""
Initialize.
:param version_entry: The version list of open source
:param current_version: The current version of open source
:returns: None
:raises: None
"""
self.latest_version = current_version # 提供初值,避免 current_version 为空导致后面出现异常 self.latest_version = current_version # 提供初值,避免 current_version 为空导致后面出现异常
self.maintain_version = current_version self.maintain_version = current_version
self.version_type = self._version_match(version_entry) self.version_type = self._version_match(version_entry)
...@@ -689,7 +1031,13 @@ class VersionRecommend(object): ...@@ -689,7 +1031,13 @@ class VersionRecommend(object):
self.maintain_version = self._get_maintain_version(version_entry, current_version, pkg_type) self.maintain_version = self._get_maintain_version(version_entry, current_version, pkg_type)
def _version_match(self, version_entry): def _version_match(self, version_entry):
"""
Version match function.
:param version_entry: The version list of open source
:returns: The method input version list
:raises: None
"""
version_method = {VersionTypeXYZW(): 0, version_method = {VersionTypeXYZW(): 0,
VersionTypeXYZ(): 0, VersionTypeXYZ(): 0,
VersionTypeXY(): 0, VersionTypeXY(): 0,
...@@ -698,8 +1046,7 @@ class VersionRecommend(object): ...@@ -698,8 +1046,7 @@ class VersionRecommend(object):
VersionTypeYyyyX(): 0, VersionTypeYyyyX(): 0,
VersionTypeYyyyW(): 0, VersionTypeYyyyW(): 0,
VersionTypeYyyyMmDd(): 0, VersionTypeYyyyMmDd(): 0,
VersionTypeYyyyMm(): 0, VersionTypeYyyymm(): 0,
VersionTypeYyyyMm(): 0,
VersionTypeXYymmZ(): 0, VersionTypeXYymmZ(): 0,
VersionTypeYyyymmdd(): 0} VersionTypeYyyymmdd(): 0}
if not version_entry: if not version_entry:
...@@ -720,7 +1067,16 @@ class VersionRecommend(object): ...@@ -720,7 +1067,16 @@ class VersionRecommend(object):
else: else:
return method return method
def _version_valid(self, version): @staticmethod
def _version_valid(version):
"""
Version valid check.
:param version: The version of open source
:returns True: valid version
:returns False: invalid version
:raises: None
"""
m = re.match("^[0-9a-zA-Z._-]*$", version) m = re.match("^[0-9a-zA-Z._-]*$", version)
if m is None: # 版本号应该是 数字/小写字母/下划线/. 组成 if m is None: # 版本号应该是 数字/小写字母/下划线/. 组成
return False return False
...@@ -758,10 +1114,3 @@ class VersionRecommend(object): ...@@ -758,10 +1114,3 @@ class VersionRecommend(object):
return '' return ''
else: else:
return self.version_type.maintain_version(version_entry, current_version, pkg_type) return self.version_type.maintain_version(version_entry, current_version, pkg_type)
if __name__ == '__main__':
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)
# 特性描述
- SR-PKG-MANAGE02-AR01: 包静态信息建档管理
- SR-PKG-MANAGE02-AR02: 包动态信息跟踪(生命周期)
- SR-PKG-MANAGE01-AR11: 包补丁分类管理
- SR-PKG-MANAGE03-AR01: 特性与包关联模块
- 支持网页前端显示
- 支持软件责任人及软件维护级别的存储和更改
# 依赖组件
- git, svn, pypi
- openEuler-Advisor/ upstream-info
# License
Mulan V2
# 流程分析
## 外部接口清单
| 序号 | 接口名称 | 类型 | 说明 | 入参 | 出参 | 特性号 |
| - | - | - | - | - | - | - |
| 1 | /packages | GET | 支持查看所有软件包静态信息、对应特性、动态信息及issue数量统计信息 | dbName | *packages-info* | all |
| 2 | /packages/packageInfo | GET | 支持查看指定软件包详细静态信息 | dbName, srcName | *packages-info-detailed* | MANAGE02-AR01 |
| 3 | /packages/lifeCycle | PUT | 支持更新指定软件包信息字段 | dbName, srcName, [end-of-life], [maintainer], [maintainlevel] | null | MANAGE02-AR02 |
| 4 | /packages/issueTrace | GET | 支持查看指定软件包issue详细信息 | dbName, srcName | *packages-issue* | MANAGE01-AR11 |
| 5 | /packages/issueTrace/patched | GET | 支持下载指定软件包指定issue的补丁包 | dbName, srcName, issueId | *packages-issue-patched* | MANAGE01-AR11 |
### 外部接口请求、回显格式
*需和前台对齐回显格式
- *packages-info*:
静态信息:name, version, release, url, rpm_license, feature, maintainer, maintainlevel;
动态信息&动态信息统计:name, version,release, published time, end time, maintainer status, latest version, latest publish time
动态信息统计:name, version,release, 需求, cve&安全问题, 缺陷
- *packages-info-detailed*: name, version, release, url, rpm_license, maintainer, maintainlevel, summary, description, required, subpack, subpack-provides, subpack-requires-component, subpack-requires-binary(if exist)
- *packages-issue*: list: issudId, issue-url, issue-content, issue-status, issue-download
# 功能设计
## 主体流程分析
计算生命周期结束日期:
![avatar](./pkgimg/lifecycle_2.png)
## 数据表设计
针对不同的版本,设计多个字段相同,表名不同的table (注:表名应于对应依赖数据库名称相同):
- Mainline
| 序号 | 名称 | 说明 | 类型 | 键 | 允许空 | 默认值 |
| - | - | - | - | - | - | - |
| 1 | id | 条目序号 | Int | Primary | NO | - |
| 2 | name | 源码包名 | String | NO | YES | - |
| 3 | url | URL | String | NO | YES | - |
| 4 | rpm_license | license | String | NO | YES | - |
| 5 | version | 版本号 | String | NO | YES | - |
| 6 | release | release号 | String | NO | YES | - |
| 7 | version_time | 当前版本发布时间 | String | NO | YES | - |
| 8 | end_time | 结束当前版本生命周期的时间 | String | NO | YES | - |
| 9 | maintainer_status | 生命周期状态 | String | NO | YES | "Available" |
| 10 | latest_version | 最新版本号 | String | NO | YES | - |
| 11 | latest_version_time | 最新版本发布时间 | String | NO | YES | - |
| 12 | demand | 需求 | Int | NO | NO | 0 |
| 13 | cve | cve及安全漏洞 | Int | NO | NO | 0 |
| 14 | defect | 缺陷 | Int | NO | NO | 0 |
| 15 | maintainer | 维护人 | String | NO | YES | - |
| 16 | maintainlevel | 维护级别 | Int| NO | YES | - |
| 17 | feature | 对应特性 | String | NO | YES | - |
| 18 | version_control | 版本控制(git,svn) | String | NO | YES | - |
| 19 | src_repo | 上游社区repo源 | String | NO | YES | - |
| 20 | tag_prefix | 版本标签 | String | NO | YES | - |
回显简单事例:
![avatar](./pkgimg/lifecycle_display.png)
生命周期终止时间定义:
1. 若最新版本和当前版本一致,生命周期终止时间为最新发布日期的6个月后;
2. 若最新版本高于当前版本,生命周期终止时间为最新发布日期的3个月后。
![avatar](./pkgimg/issue_display.png)
\ No newline at end of file
...@@ -200,7 +200,11 @@ class InitDataBase(): ...@@ -200,7 +200,11 @@ class InitDataBase():
raise ContentNoneException( raise ContentNoneException(
'The path to the sqlite file in the database initialization configuration \ 'The path to the sqlite file in the database initialization configuration \
is incorrect ') is incorrect ')
<<<<<<< HEAD
if not os.path.exists(src_db_file) or not os.path.exists(bin_db_file): if not os.path.exists(src_db_file) or not os.path.exists(bin_db_file):
=======
if os.path.exists(src_db_file) or os.path.exists(bin_db_file):
>>>>>>> dec3661c6c56512ebee173dc68694716d8c6b041
raise FileNotFoundError("sqlite file {src} or {bin} does not exist, please \ raise FileNotFoundError("sqlite file {src} or {bin} does not exist, please \
check and try again".format(src=src_db_file, bin=bin_db_file)) check and try again".format(src=src_db_file, bin=bin_db_file))
# 3. Obtain temporary source package files and binary package files # 3. Obtain temporary source package files and binary package files
......
---
version_control: github version_control: github
src_repo: yaml/pyyaml src_repo: yaml/pyyaml
tag_prefix: ^v tag_prefix: "^"
separator: . separator: "."
git_url: https://github.com/yaml/pyyaml.git
git_tag:
- 2020-03-18 5.3.1
- 2020-01-06 5.3
- 2018-08-16 4.1-retracted
- 2019-12-21 5.3b1
- 2019-11-25 5.2b1
- 2019-12-02 5.2
- 2019-03-08 5.1b7
- 2019-03-07 5.1b6
- 2019-03-07 5.1b5
- 2019-03-06 5.1b4
- 2019-02-27 5.1b3
- 2019-02-26 5.1b2
- 2019-02-24 5.1b1
- 2019-07-30 5.1.2
- 2019-06-06 5.1.1
- 2019-03-13 5.1
- 2018-06-29 4.2b2
- 2018-06-28 4.2b1
- 2018-06-26 4.1
- 2018-07-03 3.13rc1
- 2018-07-03 3.13b1
- 2018-07-05 3.13
- 2016-08-27 3.12
- 2014-03-26 3.11
- 2011-05-29 3.10
- 2009-08-30 3.09
- 2008-12-30 3.08
- 2008-12-28 3.07
- 2008-10-03 3.06
- 2007-05-12 3.05
- 2006-08-20 3.04
- 2006-06-18 3.03
- 2006-05-15 3.02
- 2006-05-07 3.01
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册