Пример #1
0
    def get_branches(self):
        os.chdir(self.options_common['master_repos_dir'])

        is_clone = False
        if os.path.exists(self.repo_key):
            if self.force:
                shutil.rmtree(self.repo_key)
                is_clone = True
        else:
            is_clone = True

        if is_clone:
            cmd = ['git', 'clone', self.options['url'], self.repo_key]
            exec_cmd(cmd)

        os.chdir(self.repo_key)
        cmd = ['git', 'branch', '-r']
        res = exec_cmd(cmd)
        res_lines = res[0].split('\n')
        brs = []
        for item in res_lines:
            if '->' in item:
                continue
            brs.append(item.strip().replace('origin/', ''))

        return brs
Пример #2
0
    def npm_install(self, branch='', path=''):
        if branch and not path:
            path = self.get_branch_path(branch)

        if not path:
            raise Exception('path or branch is required')

        os.chdir(path)
        cmd = 'sudo -u {} {} install'.format(self.cmd_exec_user, self.cmds['npm'])
        exec_cmd(cmd, True, is_debug=self.debug)
Пример #3
0
    def deploy_branch(self, br):
        os.chdir(self.checkout_path)
        cp_from = '{}/{}'.format(self.options_common['master_repos_dir'],
                                    self.repo_key)
        domain = self.get_domain(br)

        is_cp = False
        if os.path.exists(domain):
            if self.force:
                shutil.rmtree(domain)
                is_cp = True
        else:
            is_cp = True

        if is_cp:
            cmd = ['cp', '-a', cp_from, domain]
            exec_cmd(cmd, is_debug=self.debug)

        os.chdir(domain)
        if br == 'master':
            exec_cmd(['git', 'checkout', br], is_debug=self.debug)
            cmd = ['git', 'pull', '--rebase', 'origin', br]
            exec_cmd(cmd, True, is_debug=self.debug)
        else:
            exec_cmd(['git', 'checkout', '-b', br, 'origin/'+br], True, is_debug=self.debug)

        if self.packager == 'npm':
            self.npm_install(branch=br)

        if self.build_option is not None:
            self.build(branch=br)

        print('Deploy {} in {} as {}'.format(br, self.repo_key, domain))
Пример #4
0
 def update(self, repo_key, branch, debug=0):
     self.init(repo_key, debug=0)
     br_path = self.get_branch_path(branch)
     os.chdir(br_path)
     cmd = ['git', 'pull', '--rebase', 'origin', branch]
     res = exec_cmd(cmd)
     pprint(res)
Пример #5
0
    def build(self, branch='', path=''):
        if self.build_option is None:
            raise Exception('build option is not set')

        option = self.build_option

        if branch and not path:
            path = self.get_branch_path(branch)

        if not path:
            raise Exception('path or branch is required')
        os.chdir(path)

        if option['tool'] == 'webpack':
            cmd = '{}/node_modules/.bin/webpack --mode=production'.format(path)
            exec_cmd(cmd, True, is_shell_option=True, is_debug=self.debug)
Пример #6
0
    def update(self, repo_key, branch, payload, debug=0):
        self.init(repo_key, debug=0)
        br_path = self.get_branch_path(branch)
        if os.path.exists(br_path):
            os.chdir(br_path)
            cmd = ['git', 'pull', '--rebase', 'origin', branch]
            res = exec_cmd(cmd, True)

            if self.check_npm_inatall_target(payload):
                self.npm_install(branch=branch)

            if self.check_build_target(payload):
                self.build(branch=branch)

            print('Updated ' + br_path)
        else:
            self.deploy_branch(branch)
Пример #7
0
    def get_branches(self):
        os.chdir(self.options_common['master_repos_dir'])

        is_clone = False
        if os.path.exists(self.repo_key):
            if self.force:
                shutil.rmtree(self.repo_key)
                is_clone = True
        else:
            is_clone = True

        if is_clone:
            cmd = ['git', 'clone', self.options['url'], self.repo_key]
            exec_cmd(cmd, True, is_debug=self.debug)
            os.chdir(self.repo_key)

            if self.packager == 'npm':
                self.npm_install(path=self.master_path)

                if len(self.options['cmds_before_build']) > 0:
                    for cmd in self.options['cmds_before_build']:
                        exec_cmd(cmd, True, is_debug=self.debug)


        if not is_clone:
            os.chdir(self.repo_key)
            cmd = ['git', 'fetch', 'origin']
            res = exec_cmd(cmd, is_debug=self.debug)

        cmd = ['git', 'branch', '-r']
        res = exec_cmd(cmd, is_debug=self.debug)
        res_lines = res[0].split('\n')
        brs = []
        for item in res_lines:
            if '->' in item:
                continue

            br = item.strip().replace('origin/', '')
            if 'ignore_branches' in self.options and br in self.options['ignore_branches']:
                continue

            brs.append(br)

        return brs
Пример #8
0
    def deploy_branch(self, br):
        os.chdir(self.checkout_path)
        cp_from = '{}/{}'.format(self.options_common['master_repos_dir'],
                                    self.repo_key)
        domain = self.get_domain(br)

        is_cp = False
        if os.path.exists(domain):
            if self.force:
                shutil.rmtree(domain)
                is_cp = True
        else:
            is_cp = True

        if is_cp:
            cmd = ['cp', '-a', cp_from, domain]
            exec_cmd(cmd)

        os.chdir(domain)
        if br == 'master':
            exec_cmd(['git', 'checkout', br])
        else:
            exec_cmd(['git', 'checkout', '-b', br, 'origin/'+br])
        print('Deploy {} in {} as {}'.format(br, self.repo_key, domain))