Beispiel #1
0
    def __init__(self, source):
        self.git_executable = common.which('git')
        if self.git_executable is None:
            logger.error("Cannot find git executable in PATH")
            sys.exit(1)
        if 'rev' in source and 'revision' in source:
            raise ValueError("The source definition of '%s' contains "
                             "duplicate revision options." % source['name'])
        # 'rev' is canonical
        if 'revision' in source:
            source['rev'] = source['revision']
            del source['revision']

        if 'credentials' in source:
            cred = source['credentials']
            if not ':' in cred:
                raise ValueError(
                    "Credentials in the form USERNAME:PASSWORD needed")
            user, passwd = cred.split(':', 1)
        else:
            user = ''
        root = source['collection']
        # add credentials to auth cache, if they are not there already
        if user and not root in self._gittf_auth_cache:
            self._gittf_auth_cache[root] = dict(user=user,
                                                passwd=passwd)
        super(GitTFSWorkingCopy, self).__init__(source)
Beispiel #2
0
 def __init__(self, source):
     self.git_executable = common.which('git')
     if 'rev' in source and 'revision' in source:
         raise ValueError("The source definition of '%s' contains "
                          "duplicate revision options." % source['name'])
     # 'rev' is canonical
     if 'revision' in source:
         source['rev'] = source['revision']
         del source['revision']
     if 'branch' in source and 'rev' in source:
         logger.error("Cannot specify both branch (%s) and rev/revision "
                      "(%s) in source for %s",
                      source['branch'], source['rev'], source['name'])
         sys.exit(1)
     super(GitWorkingCopy, self).__init__(source)
Beispiel #3
0
 def __init__(self, source):
     self.git_executable = common.which('git')
     if self.git_executable is None:
         logger.error("Cannot find git executable in PATH")
         sys.exit(1)
     if 'rev' in source and 'revision' in source:
         raise ValueError("The source definition of '%s' contains "
                          "duplicate revision options." % source['name'])
     # 'rev' is canonical
     if 'revision' in source:
         source['rev'] = source['revision']
         del source['revision']
     if 'branch' not in source:
         source['branch'] = 'master'
     super(GitWorkingCopy, self).__init__(source)
Beispiel #4
0
def build_cvs_command(command, name, url, tag='', cvs_root='', tag_file=None):
    """
    Create CVS commands.

    Examples::

        >>> build_cvs_command('checkout', 'package.name', 'python/package.name')
        ['cvs', 'checkout', '-P', '-f', '-d', 'package.name', 'python/package.name']
        >>> build_cvs_command('update', 'package.name', 'python/package.name')
        ['cvs', 'update', '-P', '-f', '-d']
        >>> build_cvs_command('checkout', 'package.name', 'python/package.name', tag='package_name_0-1-0')
        ['cvs', 'checkout', '-P', '-r', 'package_name_0-1-0', '-d', 'package.name', 'python/package.name']
        >>> build_cvs_command('update', 'package.name', 'python/package.name', tag='package_name_0-1-0')
        ['cvs', 'update', '-P', '-r', 'package_name_0-1-0', '-d']
        >>> build_cvs_command('checkout', 'package.name', 'python/package.name', cvs_root=':pserver:[email protected]:/repos')
        ['cvs', '-d', ':pserver:[email protected]:/repos', 'checkout', '-P', '-f', '-d', 'package.name', 'python/package.name']
        >>> build_cvs_command('status', 'package.name', 'python/package.name')
        ['cvs', '-q', '-n', 'update']
        >>> build_cvs_command('tags', 'package.name', 'python/package.name', tag_file='setup.py')
        ['cvs', '-Q', 'log', 'setup.py']

    """
    if command == 'status':
        return ['cvs', '-q', '-n', 'update']

    cmd = [common.which('cvs', default='cvs')]
    if cvs_root:
        cmd.extend(['-d', cvs_root])

    if command == 'tags':
        cmd.extend(['-Q', 'log'])
        if not tag_file:
            tag_file = 'setup.py'
        cmd.append(tag_file)
    else:
        cmd.extend([command, '-P'])
        if tag:
            cmd.extend(['-r', tag])
        else:
            cmd.append('-f')
        cmd.append('-d')
        if command == 'checkout':
            cmd.extend([name, url])
    return cmd
Beispiel #5
0
    def vcsdiff(self, pofile, vcstype, vcsurl):
        """ Internal helper function.

            Diffs a file with it's counterpart in a VCS repository, of
            type $vcstype at $vcsurl.
        """
        pofile = os.path.abspath(pofile)
        basepath = self.get_package_root(os.getcwd())

        proto, string = urllib.splittype(vcsurl)
        host, path = urllib.splithost(string)

        relpath = os.path.relpath(pofile, basepath)
        pofileurl = os.path.join(vcsurl, relpath)
        tmp, tmppath = tempfile.mkstemp(text=True)
        if vcstype == 'svn':
            urllib.urlretrieve(pofileurl, tmppath)
        elif vcstype == 'git':
            cmd = which('git')
            branchmatch = re.search('branch=(\S*)', vcsurl)
            if branchmatch:
                branch = branchmatch.group(1)
            else:
                branch = 'master'
            cmdline = '%s show %s:%s' % (cmd, branch, relpath)
            err, errtmppath = tempfile.mkstemp(text=True)
            out = subprocess.Popen(cmdline.split(' '),
                                   stdout=subprocess.PIPE,
                                   stderr=err,
                                   cwd=basepath).stdout.read()
            err = open(errtmppath).read()
            if err:
                log.critical(err)
                return
            outfile = open(tmppath, 'w')
            outfile.write(out)
            outfile.close()
        else:
            log.critical('Sorry, %s is not supported yet.')
            return
        log.debug("Comparing %s and %s:%s" % (pofile, branch, relpath))
        self.diff(tmppath, pofile)
        os.remove(tmppath)
Beispiel #6
0
 def __init__(self, source):
     self.git_executable = common.which('git')
     if self.git_executable is None:
         logger.error("Cannot find git executable in PATH")
         sys.exit(1)
     if 'rev' in source and 'revision' in source:
         raise ValueError("The source definition of '%s' contains "
                          "duplicate revision options." % source['name'])
     # 'rev' is canonical
     if 'revision' in source:
         source['rev'] = source['revision']
         del source['revision']
     if 'branch' in source and 'rev' in source:
         logger.error(
             "Cannot specify both branch (%s) and rev/revision "
             "(%s) in source for %s", source['branch'], source['rev'],
             source['name'])
         sys.exit(1)
     super(GitWorkingCopy, self).__init__(source)
Beispiel #7
0
 def __init__(self, source):
     self.git_executable = common.which(*self._executable_names)
     if self.git_executable is None:
         logger.error("Cannot find git executable in PATH")
         sys.exit(1)
     if "rev" in source and "revision" in source:
         raise ValueError("The source definition of '%s' contains " "duplicate revision options." % source["name"])
     # 'rev' is canonical
     if "revision" in source:
         source["rev"] = source["revision"]
         del source["revision"]
     if "branch" in source and "rev" in source:
         logger.error(
             "Cannot specify both branch (%s) and rev/revision " "(%s) in source for %s",
             source["branch"],
             source["rev"],
             source["name"],
         )
         sys.exit(1)
     if "branch" not in source:
         source["branch"] = "master"
     super(GitWorkingCopy, self).__init__(source)
def podiff(vcsurl):
    """ Shows differences between the po files in the working copy of this
        package and their counterparts in the repository. Only cares
        about msgid and msgstr, not about position in the file, comments, etc.
    """
    import os, subprocess, tempfile, urllib, polib, re
    from mr.developer.common import which

    vcstype = vcsurl.split(' ')[0]
    vcsextra = ''
    if len(vcsurl.split(' ')) > 2:
        vcsextra = ' '.join(vcsurl.split(' ')[2:])
    vcsurl = vcsurl.split(' ')[1]
    pofiles = []
    def visit(pofiles, dirname, names):
        pofiles.extend(
            map(lambda n: os.path.join(dirname, n),
                filter(
                    lambda n: n.endswith('.po') or n.endswith('.pot'), names)))
    os.path.walk(__path__[0], visit, pofiles)
    basepath = __path__[0][:__path__[0].rfind(__name__)+len(__name__)]

    for pofile in pofiles:
        #out = subprocess.Popen(("/usr/bin/svn info %s" % pofile).split(" "), stdout=subprocess.PIPE).stdout.read()
        #out = out[out.find('URL: ')+5:]
        #pofileurl = out[:out.find('\n')]
        proto, string = urllib.splittype(vcsurl)
        host, path = urllib.splithost(string)
        relpath = os.path.relpath(pofile, basepath)
        pofileurl = os.path.join(vcsurl, relpath)

        tmp, tmppath = tempfile.mkstemp(text=True)
        if vcstype == 'svn':
            urllib.urlretrieve(pofileurl, tmppath)
        elif vcstype == 'git':
            cmd = which('git')
            branchmatch = re.search('branch=(\S*)', vcsextra)
            if branchmatch:
                branch = branchmatch.group(1)
            else:
                branch = 'master'
            cmdline = '%s show %s:%s' % (cmd, branch, relpath)
            err, errtmppath = tempfile.mkstemp(text=True)
            out = subprocess.Popen(cmdline.split(' '), 
                  stdout=subprocess.PIPE,
                  stderr=err,
                  cwd=basepath).stdout.read()
            err = open(errtmppath).read()
            if err:
                print(err)
                return
            outfile = open(tmppath, 'w')
            outfile.write(out)
            outfile.close()
        else:
            print('Sorry, %s is not supported yet.')
            return

        polocal = polib.pofile(pofile)
        povcs = polib.pofile(tmppath)

        diff = []

        for entryvcs in povcs:
            if entryvcs.obsolete:
                if entryvcs not in polocal.obsolete_entries():
                    diff += ['-#msgid "%s"' % entryvcs.msgid]
                    diff += ['-#msgstr "%s"' % entryvcs.msgstr]
                    diff += ['']
                else:
                    continue
            entrylocal = polocal.find(entryvcs.msgid)
            if not entrylocal:
                if entryvcs in polocal.obsolete_entries():
                    diff += ['+#msgid "%s"' % entryvcs.msgid]
                    diff += ['+#msgstr "%s"' % entryvcs.msgstr]
                    diff += ['']
                else:
                    diff += ['-msgid "%s"' % entryvcs.msgid]
                    diff += ['-msgstr "%s"' % entryvcs.msgstr]
                    diff += ['']
            else:
                if not entryvcs.msgstr == entrylocal.msgstr:
                    diff += [' msgid "%s"' % entryvcs.msgid]
                    diff += ['-msgstr "%s"' % entryvcs.msgstr]
                    diff += ['+msgstr "%s"' % entrylocal.msgstr]
                    diff += ['']
        for entrylocal in filter(lambda e: e not in povcs, polocal):
            if entrylocal in povcs.obsolete_entries():
                # XXX WTF? Iterating over a POFile yields obsolete entries, but
                # checking for an obsolete entry with 'in' returns False. This
                # means we have already iterated over the obsolete entries but
                # the above filter returns them again. We need to explicity skip
                # them.
                #
                # (Pdb) entry.obsolete
                # 1
                # (Pdb) [e for e in povcs if e == entry]
                # [<polib.POEntry object at 0x2f7d850>]
                # (Pdb) entry in povcs
                # False
                continue
            if entrylocal.obsolete:
                diff += ['+#msgid "%s"' % entrylocal.msgid]
                diff += ['+#msgstr "%s"' % entrylocal.msgstr]
                diff += ['']
            else:
                diff += ['+msgid "%s"' % entrylocal.msgid]
                diff += ['+msgstr "%s"' % entrylocal.msgstr]
                diff += ['']

        if diff:
            out = ['']
            out += ['Index: %s' % pofile]
            out += ['===================================================================']
            out += ['--- repository']
            out += ['+++ working copy']
            out += diff
            out += ['']
            print("\n".join(out))

        os.remove(tmppath)
Beispiel #9
0
 def __init__(self, source):
     super(BazaarWorkingCopy, self).__init__(source)
     self.bzr_executable = common.which('bzr')
Beispiel #10
0
 def __init__(self, *args, **kwargs):
     common.BaseWorkingCopy.__init__(self, *args, **kwargs)
     self.svn_executable = common.which("svn")
     self._svn_check_version()
Beispiel #11
0
 def __init__(self, source):
     self.hg_executable = common.which("hg")
     source.setdefault("branch", "default")
     source.setdefault("rev")
     super(MercurialWorkingCopy, self).__init__(source)
Beispiel #12
0
 def __init__(self, source):
     super(BazaarWorkingCopy, self).__init__(source)
     self.bzr_executable = common.which('bzr')
Beispiel #13
0
 def __init__(self, source):
     self.hg_executable = common.which('hg')
     source.setdefault('branch', 'default')
     source.setdefault('rev')
     super(MercurialWorkingCopy, self).__init__(source)
Beispiel #14
0
 def __init__(self, source):
     super(GitSVNWorkingCopy, self).__init__(source)
     self.gitify_executable = common.which('gitify')
Beispiel #15
0
 def __init__(self, source):
     super(DarcsWorkingCopy, self).__init__(source)
     self.darcs_executable = common.which('darcs')
Beispiel #16
0
 def __init__(self, *args, **kwargs):
     common.BaseWorkingCopy.__init__(self, *args, **kwargs)
     self.tf_executable = common.which(*self._executable_names)
     if self.tf_executable is None:
         self.tf_log(logger.error, "Cannot find tf executable in PATH")
         sys.exit(1)
Beispiel #17
0
 def __init__(self, source):
     super(GitSVNWorkingCopy, self).__init__(source)
     self.gitify_executable = common.which('gitify')
Beispiel #18
0
 def __init__(self, source):
     super(DarcsWorkingCopy, self).__init__(source)
     self.darcs_executable = common.which('darcs')