1 ##############################################################################
2 # Copyright (c) 2015 Huawei Technologies Co.,Ltd and others.
4 # All rights reserved. This program and the accompanying materials
5 # are made available under the terms of the Apache License, Version 2.0
6 # which accompanies this distribution, and is available at
7 # http://www.apache.org/licenses/LICENSE-2.0
8 ##############################################################################
13 from subprocess import CalledProcessError
14 from vstf.common.utils import check_call
16 LOG = logging.getLogger(__name__)
19 @contextlib.contextmanager
20 def my_chdir(file_path):
21 old_cwd = os.path.realpath(os.curdir)
23 LOG.info("cd %s", file_path)
26 LOG.info("cd %s", old_cwd)
29 class SourceCodeManager(object):
32 super(SourceCodeManager, self).__init__()
33 self.base_path = '/opt/vstf/'
36 def _git_pull(url, dest):
37 if not os.path.isdir(dest):
38 check_call("git clone %s %s" % (url, dest), shell=True)
41 check_call("git pull", shell=True)
47 check_call("make && make install", shell=True)
48 except CalledProcessError:
49 LOG.info("retry make again")
50 check_call("make clean; make && make install", shell=True)
52 def src_install(self, cfg):
53 for key, item in cfg.items():
54 repo_type = item['repo_type']
56 install = item['install']
58 LOG.info("installing src repo:%s", key)
59 if repo_type == "git":
60 target = self.base_path + key
61 self._git_pull(url, target)
64 raise Exception("unsupported repo type:%s" % repo_type)
66 LOG.info("skip src repo:%s", key)
70 if __name__ == '__main__':
73 parser = argparse.ArgumentParser()
74 parser.add_argument('--config', help='config file to parse')
75 args = parser.parse_args()
76 logging.basicConfig(level=logging.INFO)
77 cfg = json.load(open(args.config))
78 mgr = SourceCodeManager()