9 from subprocess import CalledProcessError
10 from vstf.common.utils import check_call
12 LOG = logging.getLogger(__name__)
15 @contextlib.contextmanager
16 def my_chdir(file_path):
17 old_cwd = os.path.realpath(os.curdir)
19 LOG.info("cd %s", file_path)
22 LOG.info("cd %s", old_cwd)
25 class SourceCodeManager(object):
27 super(SourceCodeManager, self).__init__()
28 self.base_path = '/opt/vstf/'
31 def _git_pull(url, dest):
32 if not os.path.isdir(dest):
33 check_call("git clone %s %s" % (url, dest), shell=True)
36 check_call("git pull", shell=True)
42 check_call("make && make install", shell=True)
43 except CalledProcessError:
44 LOG.info("retry make again")
45 check_call("make clean; make && make install", shell=True)
47 def src_install(self, cfg):
48 for key, item in cfg.items():
49 repo_type = item['repo_type']
51 install = item['install']
53 LOG.info("installing src repo:%s", key)
54 if repo_type == "git":
55 target = self.base_path + key
56 self._git_pull(url, target)
59 raise Exception("unsupported repo type:%s" % repo_type)
61 LOG.info("skip src repo:%s", key)
65 if __name__ == '__main__':
68 parser = argparse.ArgumentParser()
69 parser.add_argument('--config', help='config file to parse')
70 args = parser.parse_args()
71 logging.basicConfig(level=logging.INFO)
72 cfg = json.load(open(args.config))
73 mgr = SourceCodeManager()