Exemple #1
0
    def copy_to(self, dst, plugin_parent='plugins'):
        if self.is_plugin:
            plugin_yml_path = fs.join(self.path, 'module.yml')
            if not fs.exists(plugin_yml_path):
                plugin_yml_path = fs.join(self.path, 'plugin.yml')

            if fs.exists(plugin_yml_path):
                import yaml
                info = yaml.load(open(plugin_yml_path))
                fullname = '{}@{}'.format(info['name'], info['version'])
                dst = fs.join(dst, plugin_parent, fullname)
                fs.makedirs(dst)
            else:
                logger.error('module.yml or plugin.yml not exists')
                sys.exit(1)

        logger.info('Copy project: {!r} from {!r} to {!r}'.format(
            self.name, self.path, dst))

        for dirname in fs.listdir(self.path):
            dirpath = fs.join(self.path, dirname)
            if dirname in (EXCLUDE_DIRS + EXCLUDE_FILES) \
                    or dirname.startswith('.'):
                continue
            fs.copy(dirpath,
                    dst,
                    exclude_dirs=EXCLUDE_DIRS,
                    exclude_files=['*.exe', '*.bat']
                    if not IS_WINDOWS else ['*.sh'])
        return dst
Exemple #2
0
 def compress(project_name, name, postfix):
     logger.info('Compress from {!r} to {!r}'.format(
         project_name, DIST_ROOT))
     compress_path = fs.compress(project_name,
                                 DIST_ROOT,
                                 name=name,
                                 postfix=postfix)
Exemple #3
0
 def check(self, dst=PROJECT_ROOT, branch='develop'):
     logger.info('----------------------' * 3)
     logger.info('Check project: {!r}'.format(self.name))
     if self.exists():
         self.remove()
     self.clone(dst)
     self.checkout_branch(dst, branch=branch)
Exemple #4
0
 def download(cls, url, target_path):
     r = requests.get(url)
     if (r.status_code != 200):
         logger.info('Project build faild')
         logger.info('{} do not exists'.format(url))
         sys.exit()
     with open(target_path, 'wb') as code:
         code.write(r.content)
Exemple #5
0
 def get_output(cmd):
     p = Popen(cmd, shell=True, stdout=PIPE, stderr=PIPE, stdin=PIPE)
     p.wait()
     out = p.stdout.readlines()
     logger.info(out)
     result = p.communicate()
     if result[1]:
         logger.info('Warning:{}'.format(result[1]))
     return out
Exemple #6
0
    def download(self, dst=PROJECT_ROOT):
        logger.info('Download from {!r} to {!r}'.format(self.url, dst))
        filename = self.url.split('/')[-1]
        dst = fs.join(dst, filename)

        req = requests.get(self.url, stream=True)
        with open(dst, 'wb') as f:
            for chunk in req.iter_content(chunk_size=1024):
                if chunk:
                    f.write(chunk)
        return dst
Exemple #7
0
 def step_build(self, build_tasks):
     if self.build_system == 'all':
         self.build_system = build_tasks.keys()
     else:
         self.build_system = [self.build_system]
     for task in self.build_system:
         self.target_dir = join(DIST_ROOT, build_tasks[task]['name'])
         for step_commad in build_tasks[task]['steps']:
             step_build = Step(self.source_dir, self.target_dir,
                               self.project_name, self.project_version,
                               self.module_names)
             func, args = step_build.step_commad(step_commad)
             logger.info(args)
             func(*args)
Exemple #8
0
    def add_date(time_format, manifest_file):
        if not time_format:
            time_format = '%Y-%m-%d %H:%S'
        try:
            format_time = time.strftime('{}'.format(time_format),
                                        time.localtime(time.time()))
        except:
            logger.info('time format Irregular,user the default time format')
            time_format = '%Y-%m-%d %H:%S'
            format_time = time.strftime('{}'.format(time_format),
                                        time.localtime(time.time()))

        format_time = {"build_date": format_time}
        with open(manifest_file) as f:
            content = yaml.load(f)
        content.update(format_time)
        with open(manifest_file, 'w') as f:
            yaml.dump(content, f)
Exemple #9
0
    def with_module(module_names):
        if module_names == '':
            logger.info('Need not modules')
        else:
            for module_name in module_names.split(','):
                module_string = ''
                module_version = []
                module_url = REPO_URL[module_name]
                module_names = [
                    f for f in os.listdir(DIST_ROOT)
                    if os.path.isfile(os.path.join(DIST_ROOT, f))
                ]
                module_names = [f for f in module_names if module_name in f]
                if len(module_names) == 0:
                    content = requests.get(module_url).text
                    module_names = re.findall(
                        r'>({}.*)</a>'.format(module_name), content)
                if len(module_names) == 0:
                    logger.info(
                        'Can not find the {} package ,dispatcher build failed'.
                        format(module_name))
                    sys.exit()
                for name in module_names:
                    module_string += name
                module_version = re.findall('[-@](\d+\.\d+\.\d+)',
                                            module_string)
                module_version = max(module_version)

                for diff_version_module in REPO_NAME[module_name]:
                    source_name = diff_version_module.format(module_version)
                    link_name = diff_version_module.format('latest')
                    source = join(module_url, source_name)
                    target = join(DIST_ROOT, 'platform-ant-dispatcher/repo/',
                                  source_name)
                    if os.path.exists(join(DIST_ROOT, source_name)):
                        fs.copy(join(DIST_ROOT, source_name), target)
                    else:
                        Step.download(source, target)

                    fs.chdir(join(DIST_ROOT, 'platform-ant-dispatcher/repo/'))
                    check_call('ln -s {} {}'.format(source_name, link_name),
                               shell=True)
                    fs.chdir('../../../')
Exemple #10
0
    def check(self, dst=PROJECT_ROOT):
        logger.info('----------------------' * 3)
        logger.info('Check project: {!r}'.format(self.name))
        if not fs.exists(dst):
            fs.makedirs(dst)
            fs.chdir(dst)

        if self.exists():
            self.remove()
        compress_path = self.download(dst)
        logger.info('Uncompress from {!r} to {!r}'.format(compress_path, dst))
        fs.uncompress(compress_path, dst=PROJECT_ROOT, temp_dir=PROJECT_ROOT)
Exemple #11
0
 def clear_old_dir(dst):
     if fs.exists(dst):
         logger.info('Clear {!r}'.format(dst))
         fs.remove(dst)