diff --git a/advisors/gitee.py b/advisors/gitee.py index 93da5fa8a63e8ee7cdd500a67475e7b333c36cc8..b8615a170d31add436cc92b8f359dc234d53af23 100755 --- a/advisors/gitee.py +++ b/advisors/gitee.py @@ -175,17 +175,19 @@ class Gitee(): print("WARNING: Don't support branch: {} in auto-upgrade.".format(branch)) sys.exit(1) - def get_spec_exception(self): + def get_spec_exception(self, repo): """ - Get well known spec file exceptions + Get well known spec file exception """ specfile_exception_url = self.advisor_url + "advisors/helper/specfile_exceptions.yaml" resp = self.get_gitee(specfile_exception_url) if not resp: print("ERROR: specfile_exceptions.yaml may not exist.") sys.exit(1) - excpt = yaml.load(resp, Loader=yaml.Loader) - return excpt + excpt_list = yaml.load(resp, Loader=yaml.Loader) + if repo in excpt_list: + return excpt_list[repo] + return None def get_version_exception(self): """ @@ -205,11 +207,9 @@ class Gitee(): """ specurl = self.src_openeuler_url + "{repo}.spec" specurl = specurl.format(repo=pkg, br=branch) - excpt_list = self.get_spec_exception() - if pkg in excpt_list: - dir_name = excpt_list[pkg]["dir"] - file_name = excpt_list[pkg]["file"] - specurl = urllib.parse.urljoin(specurl, os.path.join(dir_name, file_name)) + excpt = self.get_spec_exception(pkg) + if excpt: + specurl = urllib.parse.urljoin(specurl, os.path.join(excpt["dir"], excpt["file"])) resp = self.get_gitee(specurl) return resp diff --git a/advisors/simple_update_robot.py b/advisors/simple_update_robot.py index 79b4ca649772dea305d8c2a6d0461e367f3928fc..0097c369615e96ad7672fd0b98159cd81a59e299 100755 --- a/advisors/simple_update_robot.py +++ b/advisors/simple_update_robot.py @@ -41,11 +41,24 @@ from advisors import version_recommend from advisors import match_patches -def download_source_url(pkg, spec, o_ver, n_ver): +def get_spec_path(gt_api, pkg): + """ + Get specfile path in repository + """ + excpt = gt_api.get_spec_exception(pkg) + if excpt: + spec_path = os.path.join(excpt["dir"], excpt["file"]) + else: + spec_path = "./{}.spec".format(pkg) + return spec_path + + +def download_source_url(gt_api, pkg, spec, o_ver, n_ver): """ Download source file from Source or Source0 URL """ - source_str = subprocess.check_output(["spectool -S {}.spec".format(pkg)], + spec_path = get_spec_path(gt_api, pkg) + source_str = subprocess.check_output(["spectool -S {}".format(spec_path)], shell=True).decode("utf-8") if source_str: source = source_str.split('\n')[0].split(' ')[1] @@ -151,7 +164,7 @@ def download_src(gt_api, pkg, spec, o_ver, n_ver): Download source code for upgraded package """ os.chdir(pkg) - source_file = download_source_url(pkg, spec, o_ver, n_ver) + source_file = download_source_url(gt_api, pkg, spec, o_ver, n_ver) if source_file: print(source_file) result = True @@ -205,8 +218,9 @@ def create_spec(gt_api, repo, spec_str, o_ver, n_ver): Create new spec file for upgraded package """ pkg_spec = Spec.from_string(spec_str) - os.rename("{}.spec".format(repo), "{}-old.spec".format(repo)) - file_spec = open(repo + ".spec", "w") + spec_path = get_spec_path(gt_api, repo) + os.rename(spec_path, "{}.old".format(spec_path)) + file_spec = open(spec_path, "w") in_changelog = False for line in spec_str.splitlines(): if line.startswith("Release:"): @@ -276,8 +290,9 @@ def push_create_pr_issue(gt_api, u_pkg, o_ver, u_ver, u_branch): Auto push update repo, create upgrade PR and issue. """ os.chdir(u_pkg) + spec_path = get_spec_path(gt_api, u_pkg) subprocess.call(["git rm *{old_ver}.* -rf".format(old_ver=o_ver)], shell=True) - os.remove("{}-old.spec".format(u_pkg)) + os.remove("{}.old".format(spec_path)) subprocess.call(["git add *"], shell=True) subprocess.call(["git commit -m \"upgrade {pkg} to {ver}\"".format(pkg=u_pkg, ver=u_ver)], shell=True)