From 9a00c9473b4e323fafc7829135f7a8d96cbbe3cc Mon Sep 17 00:00:00 2001 From: miao_kaibo Date: Tue, 1 Dec 2020 10:24:01 +0800 Subject: [PATCH 1/2] write date package changed to file --- core/gitee_to_obs.py | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/core/gitee_to_obs.py b/core/gitee_to_obs.py index 1461df7..e758541 100644 --- a/core/gitee_to_obs.py +++ b/core/gitee_to_obs.py @@ -18,9 +18,15 @@ sync code from gitee to obs """ import sys import os +import time import shutil +current_path = os.path.join(os.path.split(os.path.realpath(__file__))[0]) +sys.path.append(os.path.join(current_path, "..")) from common.log_obs import log from common.common import Pexpect +from common.common import git_repo_src +from common.parser_config import ParserConfigIni + class SYNCCode(object): """ @@ -51,6 +57,33 @@ class SYNCCode(object): self.kwargs['source_server_ip'], self.kwargs['source_server_pwd'], self.kwargs['source_server_port']) + par = ParserConfigIni() + self.obs_pkg_rpms_url = par.get_repos_dict()["obs_pkg_rpms"] + self._write_date_to_file() + + def _write_date_to_file(self): + """ + write date repository changed to file + """ + timestr = time.strftime("%Y%m%d %H-%M-%S", time.localtime()) + tmpdir = os.popen("mktemp").read().split("\n")[0] + self.obs_pkg_prms_files_dir = git_repo_src(self.obs_pkg_rpms_url, self.giteeuser, self.giteeuserpwd, tmpdir) + try: + branch_path = os.path.join(self.obs_pkg_prms_files_dir, self.gitee_branch) + if not os.path.exists(branch_path): + os.makedirs(branch_path) + cmd = "echo %s > %s/%s" % (timestr, branch_path, self.repository) + if os.system(cmd) != 0: + log.error("fail to write date of package changed to file") + cmd = "cd %s && git add * && git commit -m 'update date for pkg %s' && git push"\ + % (self.obs_pkg_prms_files_dir, self.repository) + if os.system(cmd) != 0: + log.error("fail to update file to %s") + except AttributeError as e: + log.error(e) + finally: + cmd = "rm -rf %s" % tmpdir + os.system(cmd) def _git_clone(self, rpm_dir, gitee_branch, path): """ -- Gitee From 0623089d16c7eceb9dc14c6a5013d95bd35cc4de Mon Sep 17 00:00:00 2001 From: miao_kaibo Date: Tue, 1 Dec 2020 14:19:34 +0800 Subject: [PATCH 2/2] get time str first --- core/gitee_to_obs.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/core/gitee_to_obs.py b/core/gitee_to_obs.py index e758541..1d28955 100644 --- a/core/gitee_to_obs.py +++ b/core/gitee_to_obs.py @@ -47,6 +47,7 @@ class SYNCCode(object): obs_server_passwd: The password for your ip obs_server_port: The port for your ip """ + self.timestr = time.strftime("%Y%m%d %H-%M-%S", time.localtime()) self.kwargs = kwargs self.repository = self.kwargs['repository'] self.gitee_branch = self.kwargs['branch'] @@ -65,19 +66,18 @@ class SYNCCode(object): """ write date repository changed to file """ - timestr = time.strftime("%Y%m%d %H-%M-%S", time.localtime()) tmpdir = os.popen("mktemp").read().split("\n")[0] self.obs_pkg_prms_files_dir = git_repo_src(self.obs_pkg_rpms_url, self.giteeuser, self.giteeuserpwd, tmpdir) try: branch_path = os.path.join(self.obs_pkg_prms_files_dir, self.gitee_branch) if not os.path.exists(branch_path): os.makedirs(branch_path) - cmd = "echo %s > %s/%s" % (timestr, branch_path, self.repository) - if os.system(cmd) != 0: + cmd1 = "echo %s > %s/%s" % (self.timestr, branch_path, self.repository) + if os.system(cmd1) != 0: log.error("fail to write date of package changed to file") - cmd = "cd %s && git add * && git commit -m 'update date for pkg %s' && git push"\ + cmd2 = "cd %s && git pull && git add * && git commit -m 'update date for pkg %s' && git push"\ % (self.obs_pkg_prms_files_dir, self.repository) - if os.system(cmd) != 0: + if os.system(cmd2) != 0: log.error("fail to update file to %s") except AttributeError as e: log.error(e) @@ -183,4 +183,4 @@ if __name__ == "__main__": 'source_server_ip': '124.90.34.227', 'source_server_pwd': '654321', 'source_server_port': '11243'} sync_run = SYNCCode(**kw) - sync_run.sync_code_to_obs() + #sync_run.sync_code_to_obs() -- Gitee