Exemple #1
0
 def createTarGZArchive(self, folder_name):
     tar_name = folder_name + '.tar'
     tar_command = [
         'pax', '-wf', tar_name, folder_name]
     execute(tar_command)
     gzip_command = ['gzip', '-f', tar_name]
     execute(gzip_command)
Exemple #2
0
    def account(self):
        '''Return the name and email of the current git user.'''
        exit_code, output = execute([self.git, 'config', 'user.name'])
        name = output.strip()

        exit_code, output = execute([self.git, 'config', 'user.email'])
        email = output.strip()

        return '%s <%s>' % (name, email)
Exemple #3
0
 def publish(self, remote='origin'):
     """
     Publish new branch to remote repo.
     """
     exit_code, output = execute([
         self.git, 'push', '--set-upstream', remote, self.branch_name])
     return output.strip()
Exemple #4
0
 def clone(self, repo_uri, project_name):
     '''Clone the repository if it does not already exists.'''
     command = [self.git, 'clone', repo_uri, project_name]
     exit_code, output = execute(command)
     if exit_code != 0:
         print 'Failed to clone "%s".' % repo_uri
         sys.exit(1)
Exemple #5
0
 def last_commit(self):
     '''Return the comment of the last commit.'''
     command = [
         self.git, 'log', "--pretty=format:'%h - %s'",
         '--date=short', '-1',
         ]
     exit_code, output = execute(command)
     return output.strip()
Exemple #6
0
    def pull(self, repo_uri='origin', branch='master'):
        '''Run git pull on the branch.'''
        command = [self.git, 'pull', repo_uri, branch]

        exit_code, output = execute(command)
        if exit_code != 0:
            print 'Failed to update repo "%s".' % repo_uri
            sys.exit(1)
Exemple #7
0
    def execute(self, *args, **kwargs):
        """
        Shortcut to execute function.

        This is here to avoid importing the execute function and also help
        with testing.
        """
        return execute(*args, **kwargs)
Exemple #8
0
    def branch_name(self):
        """
        Return the name of the current git branch.

        $ git symbolic-ref HEAD
        refs/heads/production
        """
        exit_code, output = execute([self.git, 'symbolic-ref', 'HEAD'])
        return output.strip().split('/')[-1]
Exemple #9
0
    def diffFileNames(self, ref='master'):
        """
        Return a list of (action, filename) that have changed in
        comparison with `ref`.
        """
        result = []
        command = ['git', 'diff', '--name-status', '%s' % (ref)]
        exit_code, output = execute(command)
        if exit_code != 0:
            print 'Failed to diff files.'
            sys.exit(1)

        for line in output.splitlines():
            action, name = line.split('\t')
            action = action.lower()
            result.append((action, name))

        return result
Exemple #10
0
 def revision(self):
     '''Return the revision of the current git branch.'''
     command = [self.git, 'show', '-s', '--pretty=format:%t']
     exit_code, output = execute(command)
     return output.strip()
Exemple #11
0
 def status(self):
     """
     Publish new branch to remote repo.
     """
     exit_code, output = execute([self.git, 'status', '-s'])
     return output.strip()
Exemple #12
0
 def push(self, remote='origin'):
     '''Push current changes.'''
     exit_code, output = execute([self.git, 'push', remote])
     return output.strip()
Exemple #13
0
 def copyFile(self, source, destination, branch='master'):
     command = ['git', 'show', '%s:%s' % (branch, self.fs.join(source))]
     with open(self.fs.join(destination), 'w') as output_file:
         execute(command, output=output_file)