diff --git a/core/gitee_to_obs.py b/core/gitee_to_obs.py index 1461df737599dd8d5431f9bc362ee394f47b4e33..1d28955bb6958a6b902904ae3ce9887bcabc1583 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): """ @@ -41,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'] @@ -51,6 +58,32 @@ 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 + """ + 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) + 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") + 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(cmd2) != 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): """ @@ -150,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()