Exemplo n.º 1
0
def get_config(path, option=None):
    if os.path.isfile(path):
        path = os.path.dirname(path)

    cmd = ['git', 'config']

    if option is not None:
        cmd.extend(['--get', option])
    else:
        cmd.extend(['-l'])

    command = Command(cmd, path, env={'PAGER': ''})
    out = command.run_sync()

    if option is not None:
        return out.strip('\n\t ')

    retval = {}
    for line in out.splitlines():
        if '=' not in line:
            continue
        key, value = line.split('=', 1)
        retval[key.lower().strip()] = value.strip('\n\t ')

    if retval == {}:
        return None

    return retval
    def get_previous_file_name(self, uri, rev, file_name):
        self._check_uri(uri)

        cmd = ["git", "log", "--format=%H", "--name-status", "--find-copies", "-n1", rev]
        command = Command(cmd, uri, env={"PAGER": ""})
        try:
            output = command.run_sync()
        except:
            return None

        file_pattern = re.compile("^[ACDMRTUXB]{0,1}([MADT])[ \t]+(.*)$")
        file_move_pattern = re.compile("^[ACDMRTUXB]{0,1}([RC])[0-9]+[ \t]+(.*)[ \t]+(.*)$")

        for line in output.splitlines():
            old_file_name = new_file_name = None

            match_file = file_pattern.match(line)
            if match_file:
                old_file_name = new_file_name = match_file.group(2)

            match_file_move = file_move_pattern.match(line)
            if match_file_move:
                old_file_name = match_file_move.group(2)
                new_file_name = match_file_move.group(3)

            if new_file_name == file_name:
                return old_file_name

        return None
def get_config(path, option=None):
    if os.path.isfile(path):
        path = os.path.dirname(path)

    cmd = ["git", "config"]

    if option is not None:
        cmd.extend(["--get", option])
    else:
        cmd.extend(["-l"])

    command = Command(cmd, path, env={"PAGER": ""})
    out = command.run_sync()

    if option is not None:
        return out.strip("\n\t ")

    retval = {}
    for line in out.splitlines():
        if "=" not in line:
            continue
        key, value = line.split("=", 1)
        retval[key.lower().strip()] = value.strip("\n\t ")

    if retval == {}:
        return None

    return retval
Exemplo n.º 4
0
def get_repository_from_path(path):
    if os.path.isfile(path):
        path = os.path.dirname(path)

    pattern = re.compile("^[ \t]*(checkout of)?(parent)? branch:(.*)$")
    uri = None

    try:
        cmd = ['bzr', 'info']

        command = Command(cmd, path, env={'LC_ALL': 'C'})
        out = command.run_sync()

        for line in out.splitlines():
            match = pattern.match(line)
            if not match:
                continue

            uri = match.group(3).strip()
            break
    except CommandError:
        raise RepositoryInvalidWorkingCopy('"%s" does not appear to be a Bzr '
                                           'working copy' % path)

    if uri is None:
        raise RepositoryInvalidWorkingCopy(
            '"%s" does not appear to be a Bzr'
            ' working copy' % path
        )

    return 'bzr', uri
Exemplo n.º 5
0
def get_config (path, option = None):
    if os.path.isfile (path):
        path = os.path.dirname (path)

    cmd = ['git', 'config']

    if option is not None:
        cmd.extend (['--get', option])
    else:
        cmd.extend (['-l'])

    command = Command (cmd, path, env = {'PAGER' : ''})
    out = command.run_sync ()

    if option is not None:
        return out.strip ('\n\t ')

    retval = {}
    for line in out.splitlines ():
        if '=' not in line:
            continue
        key, value = line.split ('=', 1)
        retval[key.lower ().strip ()] = value.strip ('\n\t ')

    if retval == {}:
        return None

    return retval
Exemplo n.º 6
0
def get_repository_from_path(path):
    if os.path.isfile(path):
        path = os.path.dirname(path)

    pattern = re.compile("^[ \t]*(checkout of)?(parent)? branch:(.*)$")
    uri = None

    try:
        cmd = ['bzr', 'info']

        command = Command(cmd, path, env={'LC_ALL': 'C'})
        out = command.run_sync()

        for line in out.splitlines():
            match = pattern.match(line)
            if not match:
                continue

            uri = match.group(3).strip()
            break
    except CommandError:
        raise RepositoryInvalidWorkingCopy(
            '"%s" does not appear to be a Bzr working copy' % path)

    if uri is None:
        raise RepositoryInvalidWorkingCopy(
            '"%s" does not appear to be a Bzr working copy' % path)

    return 'bzr', uri
Exemplo n.º 7
0
 def get_previous_commit (self, uri, rev, file_name):
     self._check_uri (uri)
     
     cmd = ['git', 'log', '--follow', '--format=%H', rev, '--', file_name]
     command = Command (cmd, uri, env = {'PAGER' : ''})
     
     try:
         out = command.run_sync ()
         return out.splitlines()[1].strip ('\n\t ')
     except:
         return None
Exemplo n.º 8
0
    def _get_git_version (self):
        if self.git_version is not None:
            return self.git_version

        cmd = ['git', '--version']

        command = Command (cmd)
        out = command.run_sync ()

        version = out.replace ("git version ", "")
        self.git_version = tuple ([int (i) for i in version.split ('.')])

        return self.git_version
    def _get_git_version(self):
        if self.git_version is not None:
            return self.git_version

        cmd = ["git", "--version"]

        command = Command(cmd)
        out = command.run_sync()

        version = out.replace("git version ", "")
        self.git_version = tuple([i for i in version.split(".")[:4]])

        return self.git_version
Exemplo n.º 10
0
    def get_last_revision(self, uri):
        self._check_uri(uri)

        cmd = ['bzr', 'revno']

        command = Command(cmd, uri)
        try:
            out = command.run_sync()
        except:
            return None

        if out == "":
            return None

        return out.strip('\n\t ')
    def get_last_revision(self, uri):
        self._check_uri(uri)

        cmd = ["git", "rev-list", "HEAD^..HEAD"]

        command = Command(cmd, uri, env={"PAGER": ""})
        try:
            out = command.run_sync()
        except:
            return None

        if out == "":
            return None

        return out.strip("\n\t ")
Exemplo n.º 12
0
    def get_last_revision(self, uri):
        self._check_uri(uri)

        cmd = ['git', 'rev-list', 'HEAD^..HEAD']

        command = Command(cmd, uri, env={'PAGER': ''})
        try:
            out = command.run_sync()
        except:
            return None

        if out == "":
            return None

        return out.strip('\n\t ')
Exemplo n.º 13
0
    def get_last_revision (self, uri):
        self._check_uri (uri)

        cmd = ['git', 'rev-list', 'HEAD^..HEAD']

        command = Command (cmd, uri, env = {'PAGER' : ''})
        try:
            out = command.run_sync ()
        except:
            return None

        if out == "":
            return None

        return out.strip ('\n\t ')
Exemplo n.º 14
0
    def get_last_revision(self, uri):
        self._check_uri(uri)

        cmd = ['bzr', 'revno']

        command = Command(cmd, uri)
        try:
            out = command.run_sync()
        except:
            return None

        if out == "":
            return None

        return out.strip('\n\t ')
    def get_previous_commit_and_file_name(self, uri, rev, file_name):
        self._check_uri(uri)

        prev_file_name = self.get_previous_file_name(uri, rev, file_name)

        cmd = ["git", "log", "--format=%H", rev, "--", prev_file_name]
        command = Command(cmd, uri, env={"PAGER": ""})
        try:
            output = command.run_sync()
        except:
            return None

        revisions = output.splitlines()
        if len(revisions) > 1:
            return (revisions[1], prev_file_name)
        else:
            return None
Exemplo n.º 16
0
    def _get_git_version(self):
        if self.git_version is not None:
            return self.git_version

        cmd = ['git', '--version']

        command = Command(cmd)
        out = command.run_sync()
        # it could looks like:
        #  git version 1.7.10.4 // 1.8.4.rc3 // 1.7.12.4 (Apple Git-37)

        version = out.replace("git version ", "")
        try:
            self.git_version = tuple([int(i) for i in version.split('.')])
        except ValueError:
            self.git_version = tuple([int(i) for i in version.split('.')[0:3]])

        return self.git_version
Exemplo n.º 17
0
    def _get_git_version(self):
        if self.git_version is not None:
            return self.git_version

        cmd = ['git', '--version']

        command = Command(cmd)
        out = command.run_sync()
        # it could looks like:
        #  git version 1.7.10.4 // 1.8.4.rc3 // 1.7.12.4 (Apple Git-37)

        version = out.replace("git version ", "")
        try:
            self.git_version = tuple([int(i) for i in version.split('.')])
        except ValueError:
            self.git_version = tuple([int(i) for i in version.split('.')[0:3]])

        return self.git_version
Exemplo n.º 18
0
    def get_last_revision(self, uri):
        self._check_srcdir(uri)

        if not os.path.isfile(uri):
            return None

        filename = os.path.basename(uri)
        path = os.path.dirname(uri)

        cmd = ['cvs', 'status', filename]
        command = Command(cmd, path)
        out = command.run_sync()

        retval = None
        for line in out.splitlines():
            if "Working revision:" in line:
                retval = line.split(":", 1)[1].strip().split()[0]

        return retval
    def get_last_revision (self, uri):
        self._check_srcdir (uri)

        if not os.path.isfile (uri):
            return None

        filename = os.path.basename (uri)
        path = os.path.dirname (uri)
        
        cmd = ['cvs', 'status', filename]
        command = Command (cmd, path)
        out = command.run_sync ()

        retval = None
        for line in out.splitlines ():
            if "Working revision:" in line:
                retval = line.split (":", 1)[1].strip ().split ()[0]
            
        return retval
Exemplo n.º 20
0
    def _get_branches(self, path):
        cmd = ['git', 'branch']

        command = Command(cmd, path)
        out = command.run_sync()

        patt = re.compile("^\*(.*)$")

        i = 0
        current = 0
        retval = []
        for line in out.splitlines():
            if line.startswith(self.uri):
                continue

            match = patt.match(line)
            if match:
                current = i
                retval.append(match.group(1).strip(' '))
            else:
                retval.append(line.strip(' '))
            i += 1

        return current, retval
Exemplo n.º 21
0
    def _get_branches (self, path):
        cmd = ['git', 'branch']
        
        command = Command (cmd, path)
        out = command.run_sync ()

        patt = re.compile ("^\* (.*)$")
        
        i = 0
        current = 0
        retval = []
        for line in out.splitlines ():
            if line.startswith (self.uri):
                continue

            match = patt.match (line)
            if match:
                current = i
                retval.append (match.group (1).strip (' '))
            else:
                retval.append (line.strip (' '))
            i += 1

        return current, retval