Ejemplo n.º 1
0
    def __normalize_revision(self, revision):
        if revision == HEAD:
            r = Revision(opt_revision_kind.head)
        elif revision == PRE_CREATION:
            raise FileNotFoundError('', revision)
        else:
            r = Revision(opt_revision_kind.number, str(revision))

        return r
Ejemplo n.º 2
0
def getrev(client, url, rev):
    try:
        print "getting rev %s" % rev
        catout = client.cat(url, revision=Revision(opt_revision_kind.number, rev))
        diff = None
        try:
            diff = client.diff('/tmp/', url,
                revision1=Revision(opt_revision_kind.number, rev-1),
                revision2=Revision(opt_revision_kind.number, rev))
        except ClientError, e:
            print "Couldn't diff versions %s and %s of %s" % (rev, rev-1, url)
        return (catout, diff)
Ejemplo n.º 3
0
def checkout_v8():
    if svn_name:
        print("INFO: we will try to update v8 to %s at <%s>" %
              (svn_name, V8_SVN_URL))
    else:
        print(
            "INFO: we will try to checkout and build a private v8 build from <%s>."
            % V8_SVN_URL)

    print("=" * 20)
    print("INFO: Checking out or Updating Google V8 code from SVN...\n")

    update_code = os.path.isdir(V8_HOME) and os.path.exists(
        os.path.join(V8_HOME, 'include', 'v8.h'))

    try:
        from pysvn import Client, Revision, opt_revision_kind

        svnClient = Client()
        rev = Revision(opt_revision_kind.number,
                       V8_SVN_REVISION) if V8_SVN_REVISION else Revision(
                           opt_revision_kind.head)

        if update_code:
            r = svnClient.update(V8_HOME, revision=rev)
        else:
            r = svnClient.checkout(V8_SVN_URL, V8_HOME, revision=rev)

        if r: return

        print("ERROR: Failed to export from V8 svn repository")
    except ImportError:
        #print "WARN: could not import pysvn. Ensure you have the pysvn package installed."
        #print "      on debian/ubuntu, this is called 'python-svn'; on Fedora/RHEL, this is called 'pysvn'."

        print(
            "INFO: we will try to use the system 'svn' command to checkout/update V8 code"
        )

    if update_code:
        args = ["svn", "up", V8_HOME]
    else:
        os.makedirs(V8_HOME)

        args = ["svn", "co", V8_SVN_URL, V8_HOME]

    if V8_SVN_REVISION:
        args += ['-r', str(V8_SVN_REVISION)]

    cmdline = ' '.join(args)

    exec_cmd(cmdline, "checkout or update Google V8 code from SVN")
Ejemplo n.º 4
0
        def lastLog(self, num=1, files=False):
            
            if num == 1:
                end = Revision(opt_revision_kind.head)
            else:
                end = Revision(opt_revision_kind.number, int(self.lastRev()) - (num - 1))

            try:
                log = self.client.log(self.repo, revision_end=end, discover_changed_paths=files)
            except ClientError, message:
                msg = 'Error connecting to SVN repo: %s' % (message, )
                print msg
                return 'Error connecting to SVN repo'
Ejemplo n.º 5
0
    def get_commits(self, start):
        """Returns a list of commits."""
        commits = self.client.log(self.repopath,
                                  revision_start=Revision(
                                      opt_revision_kind.number, int(start)),
                                  limit=31)

        results = []

        # We fetch one more commit than we care about, because the entries in
        # the svn log doesn't include the parent revision.
        for i in range(len(commits) - 1):
            commit = commits[i]
            parent = commits[i + 1]

            date = datetime.utcfromtimestamp(commit['date'])
            results.append(
                Commit(commit.get('author', ''),
                       six.text_type(commit['revision'].number),
                       date.isoformat(), commit['message'],
                       six.text_type(parent['revision'].number)))

        # If there were fewer than 31 commits fetched, also include the last
        # one in the list so we don't leave off the initial revision.
        if len(commits) < 31:
            commit = commits[-1]
            date = datetime.utcfromtimestamp(commit['date'])
            results.append(
                Commit(commit['author'],
                       six.text_type(commit['revision'].number),
                       date.isoformat(), commit['message']))

        return results
Ejemplo n.º 6
0
    def get_change(self, revision, cache_key):
        """Get an individual change.

        This returns a tuple with the commit message and the diff contents.
        """
        revision = int(revision)
        head_revision = Revision(opt_revision_kind.number, revision)

        commit = cache.get(cache_key)
        if commit:
            message = commit.message
            author_name = commit.author_name
            date = commit.date
            base_revision = Revision(opt_revision_kind.number, commit.parent)
        else:
            commits = self.client.log(
                self.repopath,
                revision_start=head_revision,
                limit=2)
            commit = commits[0]
            message = commit['message'].decode('utf-8', 'replace')
            author_name = commit['author'].decode('utf-8', 'replace')
            date = datetime.utcfromtimestamp(commit['date']).\
                isoformat()

            try:
                commit = commits[1]
                base_revision = commit['revision']
            except IndexError:
                base_revision = Revision(opt_revision_kind.number, 0)

        tmpdir = mkdtemp(prefix='reviewboard-svn.')

        diff = self.client.diff(
            tmpdir,
            self.repopath,
            revision1=base_revision,
            revision2=head_revision,
            header_encoding='utf-8',
            diff_options=['-u']).decode('utf-8')

        rmtree(tmpdir)

        commit = Commit(author_name, six.text_type(head_revision.number), date,
                        message, six.text_type(base_revision.number))
        commit.diff = diff
        return commit
Ejemplo n.º 7
0
 def showOld(self, path):
     try:
         return self._getClient().cat(os.path.join(self.working_copy, path),
                                      Revision(opt_revision_kind.base))
     except ClientError, e:
         if e.args[1][-1][1] in (errno.ENOENT, svn_err.entry_not_found):
             raise NotVersionedError(path)
         raise
Ejemplo n.º 8
0
    def checkout_v8(self):
        update_code = os.path.isdir(V8_HOME) and os.path.exists(
            os.path.join(V8_HOME, 'include', 'v8.h'))

        try:
            from pysvn import Client, Revision, opt_revision_kind

            svnClient = Client()
            rev = Revision(opt_revision_kind.number,
                           V8_SVN_REVISION) if V8_SVN_REVISION else Revision(
                               opt_revision_kind.head)

            if update_code:
                r = svnClient.update(V8_HOME, revision=rev)
            else:
                r = svnClient.checkout(V8_SVN_URL, V8_HOME, revision=rev)

            if r: return

            print "ERROR: Failed to export from V8 svn repository"
        except ImportError:
            #print "WARN: could not import pysvn. Ensure you have the pysvn package installed."
            #print "      on debian/ubuntu, this is called 'python-svn'; on Fedora/RHEL, this is called 'pysvn'."

            print "INFO: we will try to use the system 'svn' command to checkout/update V8 code"

        if update_code:
            args = ["svn", "up", V8_HOME]
        else:
            os.makedirs(V8_HOME)

            args = ["svn", "co", V8_SVN_URL, V8_HOME]

        if V8_SVN_REVISION:
            args += ['-r', str(V8_SVN_REVISION)]

        try:
            proc = subprocess.Popen(args, stdout=sys.stdout, stderr=sys.stderr)

            proc.communicate()

            if proc.returncode != 0:
                print "WARN: fail to checkout or update Google v8 code from SVN, error code: ", proc.returncode
        except Exception, e:
            print "ERROR: fail to invoke 'svn' command, please install it first: %s" % e
            sys.exit(-1)
Ejemplo n.º 9
0
 def discover_changes(self):
     """
     Find out the changes occured since the last time this method is ran
     """
     logging.debug("Discover Changes in %s" % self.name)
     self.parser.read(self.config_file)
     if self.parser.has_option(self.name, "last_revision"):
         last_revision = self.parser.get(self.name, "last_revision")
     else:
         last_revision = 0
     log = self.client.log(self.svn_root,
                           discover_changed_paths=True,
                           revision_end=Revision(opt_revision_kind.number,
                                                 last_revision))
     log = log[:-1]  # Ignore last revision
     if len(log) > 0:
         logging.info("%s new commits in repository %s" %
                      (len(log), self.name))
         # update last revision in config file
         last_revision = log[0].revision.number
         self.parser.set(self.name, "last_revision", last_revision)
         self.parser.write(open(self.config_file, 'w'))
         log.reverse()
         if len(log) > 5:  # Show only most recent commits
             pynotify.Notification(
                 "Even more commits in repository %s" % self.name,
                 "There are %s more new commits in the repository" %
                 (len(log) - 5), "view-refresh").show()
             log = log[-5:]
         for entry in log:
             author = entry.get('author')
             rev = entry.revision.number
             message = entry.message
             date = datetime.datetime.fromtimestamp(entry.date)
             paths = []
             for change in entry.changed_paths:
                 paths.append(change.path)
             self._notify(author, date, rev, message, paths)
     else:
         logging.debug("No new commits in repository %s" % self.name)
Ejemplo n.º 10
0
def checkout_v8():
    if svn_name:
        print("INFO: we will try to update v8 to %s at <%s>" %
              (svn_name, V8_SVN_URL))
    else:
        print(
            "INFO: we will try to checkout and build a private v8 build from <%s>."
            % V8_SVN_URL)

    print("=" * 20)
    print("INFO: Checking out or Updating Google V8 code from SVN...\n")

    update_code = os.path.isdir(V8_HOME) and os.path.exists(
        os.path.join(V8_HOME, 'include', 'v8.h'))

    try:
        from pysvn import Client, Revision, opt_revision_kind

        svnClient = Client()
        rev = Revision(opt_revision_kind.number,
                       V8_SVN_REVISION) if V8_SVN_REVISION else Revision(
                           opt_revision_kind.head)

        if update_code:
            r = svnClient.update(V8_HOME, revision=rev)
        else:
            r = svnClient.checkout(V8_SVN_URL, V8_HOME, revision=rev)

        if r:
            print("%s Google V8 code (r%d) from SVN to %s" %
                  ("Update" if update_code else "Checkout", r[-1].number,
                   V8_HOME))

            with open(v8_svn_rev_file, 'w') as f:
                f.write(str(r[-1].number))

            return

        print("ERROR: Failed to export from V8 svn repository")
    except ImportError:
        #print "WARN: could not import pysvn. Ensure you have the pysvn package installed."
        #print "      on debian/ubuntu, this is called 'python-svn'; on Fedora/RHEL, this is called 'pysvn'."

        print(
            "INFO: we will try to use the system 'svn' command to checkout/update V8 code"
        )

    if update_code:
        args = ["svn", "up", V8_HOME]
    else:
        os.makedirs(V8_HOME)

        args = ["svn", "co", V8_SVN_URL, V8_HOME]

    if V8_SVN_REVISION:
        args += ['-r', str(V8_SVN_REVISION)]

    if exec_cmd(' '.join(args), "checkout or update Google V8 code from SVN"):
        if not V8_SVN_REVISION:
            ok, out, err = exec_cmd(
                ' '.join(["svn", "info", V8_HOME]),
                "save the current V8 SVN revision to REVISION file",
                output=True)

            if ok:
                with open(v8_svn_rev_file, 'w') as f:
                    f.write(
                        re.search(r'Revision:\s(?P<rev>\d+)', out,
                                  re.MULTILINE).groupdict()['rev'])
            else:
                print("ERROR: fail to fetch SVN info, %s", err)
Ejemplo n.º 11
0
def main(options):
    """docstring for main"""
    client = Client()
    client.callback_ssl_server_trust_prompt = ssl_trust_prompt
    if (options.verbose > 1):
        client.callback_notify = notify
    retcode = 0
    # check out branch from subversion
    if (test_skip(options.branch_flags, update)):
        getSourceTree(options.workingDir + os.sep + "branch",
                      options.branchUrl, client, options)
    elif (options.verbose):
        print "Skipping branch update"

    # compile branch
    if (test_skip(options.branch_flags, build)):
        print "Compiling branch"
        retcode = doCompile(options.workingDir + os.sep + "branch" + os.sep +
                            "VS2005")
    elif (options.verbose):
        print "Skipping branch compile"

    # If compile successful, Run autotest
    if (retcode != 0):
        print "Failed to compile branch"
        return retcode

    if (test_skip(options.branch_flags, autotest)):
        print "Running branch autotest"
        retcode = doAutotest(options.workingDir + os.sep + "branch")
    elif (options.verbose):
        print "Skipping branch autotest"

    if (retcode != 0):
        print "Failed branch autotest"
        return retcode

    if (test_skip(options.trunk_flags, update)):
        getSourceTree(options.workingDir + os.sep + "trunk", options.trunkUrl,
                      client, options)
    elif (options.verbose):
        print "Skipping trunk update"

    # Determine the revision number of the head of the branch
    if (options.endrev == 'HEAD'):
        if (options.verbose):
            print "Getting last revision number of branch"
        messages = client.log(branchUrl,
                              revision_end=Revision(
                                  pysvn.opt_revision_kind.number, startrev))
        endrev = messages[0].revision.number
        options.endrev = str(endrev)

    if (options.verbose):
        print "Revisions to merge", options.startrev + ":" + options.endrev

    # Merge changes from branch to trunk
    if (not options.skip_merge):
        if (options.verbose):
            print "Merging branch changes to trunk working directory"
        (retcode, conflicts) = doMerge(options.workingDir + os.sep + "trunk",
                                       endrev, options)
    elif (options.verbose):
        print "Skipping merge"

    # How do we tell if there were merge errors?!?
    if (retcode != 0):
        print "Merge to working directory failed with conflicts."
        printList(conflicts)
        return retcode

    # Compile trunk
    if (test_skip(options.trunk_flags, build)):
        print "Compiling trunk"
        retcode = doCompile(options.workingDir + os.sep + "trunk" + os.sep +
                            "VS2005")
    elif (options.verbose):
        print "Skipping trunk compile"

    if (retcode != 0):
        print "Failed to compile merged trunk"
        return retcode

    # If compile successful, run autotest
    if (test_skip(options.trunk_flags, autotest)):
        print "Running trunk autotest"
        retcode = doAutotest(options.workingDir + os.sep + "trunk")
    elif (options.verbose):
        print "Skipping trunk autotest"

    if (retcode != 0):
        print "Failed in merged autotest"
        return retcode

    # TODO: If successful, commit.
    if (not options.skip_commit):
        pass

    # Write out new lastrev.py file
    fp = open("lastrev.py", 'w')
    fp.write("startrev = " + str(endrev) + "\n")
    fp.write("prevrev = " + str(startrev))
    fp.close()