Пример #1
0
 def cmd_bash(self, bash_cmd):
     try:
         return subprocess.check_output('cd %s; %s ;cd -' %
                                        (self.location, bash_cmd),
                                        shell=True)
     except OSError as e:
         return Color.red(e.strerror)
Пример #2
0
    def run(self):
        """
        :param str git_cmd:
        :rtype list(str)
        """
        if len(self.packages) == 0:
            print(Color.red('There is not packages selected'))
            exit(-1)

        global pool_packages
        print(Color.yellow('Following command "git %s" is about to run on:\n' % self.git_cmd))
        for package in self.packages: print("\t" + package.get_name())
        # raw_input(Color.green('\n\nPress Enter to continue...'))

        for package in self.packages:
            pool_packages.add(package.get_name())
            if self.pool:
                self.pool.apply_async(execute_package, [package, self.git_cmd, self.git_args],
                                      callback=lambda output, package=package: competed_package(package, output))
            else:
                output = execute_package(package, self.git_cmd, self.git_args)
                competed_package(package, output)

        if not self.pool: return

        try:
            while len(pool_packages):
                print "Waiting packages: %s" % str(pool_packages)
                time.sleep(1)
        except KeyboardInterrupt: terminate = True; print "Interrupt!!!"
        else: terminate = False;

        if terminate: self.pool.terminate()
        print "Waiting threads to complete"; self.pool.close()
        print "Waiting threads to wrap-up"; self.pool.join()
Пример #3
0
def execute_package(package, git_cmd, git_args):
    """
    :param Package package:
    :param str git_cmd:
    :param list git_args:
    :rtype str:
    """
    try:
        output = Workspace.run_cmd(package, git_cmd, git_args)
    except GitCommandError as e:
        output = Color.red(e.stderr or e.stdout)
    except ValueError as e:
        output = Color.red(e.message)
    except:
        output = Color.red(traceback.format_exc())
    return output
Пример #4
0
    def cmd_commit(self, flags, message):
        if not message: output = Color.red('Commit message cannot be empty')
        elif not self._has_local_changes():
            output = Color.yellow('There is not local changes')
        else:
            flags['-m'] = message
            args = self._get_args_list(flags)
            output = Color.green(self.git.commit(args))

        return output
Пример #5
0
 def cmd_rebase(self, remote, branch):
     cur_remote, cur_branch = self.get_cur_remote_branch()
     self._assert_remote_branch(remote, branch)
     try:
         if self._has_local_changes():
             stashed = self.git.stash(u=True) != u'No local changes to save'
         if remote:
             output = self.git.rebase('%s/%s' % (remote, branch))
         else:
             output = self.git.rebase(branch)
     except GitCommandError as e:
         self.git.rebase(abort=True)
         self.git.checkout(cur_branch)
         print(Color.red("ERR: Rebasing"))
         raise e
     finally:
         if 'stashed' in locals() and stashed: self.git.stash('pop')
     return output
Пример #6
0
    def get_packages(src, all_packages, only_local_changes, only_no_prod, package_names):
        """
        :param string src: Source path
        :param bool only_local_changes:
        :param book only_no_prod:
        :param list(string) packages:
        :return:
        """
        folders = [path.join(src, f) for f in listdir(path.join(src)) if not path.isfile(path.join(src, f))]
        packages = [Package(pf) for pf in folders if path.isdir(path.join(pf, '.git'))]
        if len(packages) == 0:
            print(Color.red('Empty workspace. None found `./*/.git` folders'))
            exit(-1)

        return [package for package in packages
                if all_packages
                or (only_local_changes and package._has_local_changes())
                or (packages and package.get_name() in package_names)
                or (only_no_prod and package.get_cur_remote_branch(True) != environ['prod_branch'])]