Example #1
0
    def _handleConflict(self, changeset, conflicts, conflict):
        """
        Handle the conflict raised by the application of the upstream changeset.

        Override parent behaviour: with darcs, we need to execute a revert
        on the conflicted files, **trashing** local changes, but there should
        be none of them in tailor context.
        """

        from os import walk, unlink
        from os.path import join
        from re import compile

        self.log.info("Reverting changes to %s, to solve the conflict",
                      ' '.join(conflict))
        cmd = self.repository.command("revert", "--all")
        revert = ExternalCommand(cwd=self.repository.basedir, command=cmd)
        revert.execute(conflict, input="\n")

        # Remove also the backups made by darcs
        bckre = compile('-darcs-backup[0-9]+$')
        for root, dirs, files in walk(self.repository.basedir):
            backups = [f for f in files if bckre.search(f)]
            for bck in backups:
                self.log.debug("Removing backup file %r in %r", bck, root)
                unlink(join(root, bck))
Example #2
0
    def _tag(self, tagname, date, author):
        """
        Apply a tag.
        """

        # Sanitize tagnames for CVS: start with [a-zA-z], only include letters,
        # numbers, '-' and '_'.
        # str.isalpha et al are locale-dependent
        def iscvsalpha(chr):
            return (chr >= 'a' and chr <= 'z') or (chr >= 'A' and chr <= 'Z')
        def iscvsdigit(chr):
            return chr >= '0' and chr <= '9'
        def iscvschar(chr):
            return iscvsalpha(chr) or iscvsdigit(chr) or chr == '-' or chr == '_'
        def cvstagify(chr):
            if iscvschar(chr):
                return chr
            else:
                return '_'

        tagname = ''.join([cvstagify(chr) for chr in tagname])
        if not iscvsalpha(tagname[0]):
            tagname = 'tag-' + tagname

        cmd = self.repository.command("-f", "tag")
        c = ExternalCommand(cwd=self.repository.basedir, command=cmd)
        c.execute(tagname)
        if c.exit_status:
            raise ChangesetApplicationFailure("%s returned status %d" %
                                              (str(c), c.exit_status))
Example #3
0
    def _commit(self, date, author, patchname, changelog=None, entries=None,
                tags = [], isinitialcommit = False):
        """
        Commit the changeset.
        """

        from vcpx.shwrap import ReopenableNamedTemporaryFile

        encode = self.repository.encode

        logmessage = []
        if patchname:
            logmessage.append(patchname)
        if changelog:
            logmessage.append(changelog)
        logmessage.append('')
        logmessage.append('Original author: %s' % author)
        logmessage.append('Date: %s' % date)

        rontf = ReopenableNamedTemporaryFile('cvs', 'tailor')
        log = open(rontf.name, "w")
        log.write(encode('\n'.join(logmessage)))
        log.close()

        cmd = self.repository.command("-f", "-q", "ci", "-F", rontf.name)
        if not entries:
            entries = ['.']

        c = ExternalCommand(cwd=self.repository.basedir, command=cmd)
        c.execute(entries)

        if c.exit_status:
            raise ChangesetApplicationFailure("%s returned status %d" %
                                              (str(c), c.exit_status))
Example #4
0
    def __move_file(self, old_name, new_name):
        #
        # The aegis command to rename files does not have the -keep
        # option to preserve the content of the file, do it manually.
        #
        fp = open(os.path.join(self.repository.basedir, new_name), 'rb')
        content = fp.read()
        fp.close()
        cmd = self.repository.command("-move", "-not-logging", "-project",
                                      self.repository.module, "-change",
                                      self.change_number)
        move_file = ExternalCommand(cwd=self.repository.basedir, command=cmd)
        output = move_file.execute(old_name,
                                   new_name,
                                   stdout=PIPE,
                                   stderr=STDOUT)[0]
        if move_file.exit_status > 0:
            raise ChangesetApplicationFailure(
                "%s returned status %d, saying: %s" %
                (str(move_file), move_file.exit_status, output.read()))

        #
        # Restore the previously saved content of the renamed file.
        #
        fp = open(os.path.join(self.repository.basedir, new_name), 'wb')
        fp.write(content)
        fp.close()
Example #5
0
    def _getUpstreamChangesets(self, sincerev=None):
        if sincerev:
            sincerev = int(sincerev)
        else:
            sincerev = 0

        cmd = self.repository.command("log", "--verbose", "--xml", "--non-interactive",
                                      "--revision", "%d:HEAD" % (sincerev+1))
        svnlog = ExternalCommand(cwd=self.repository.basedir, command=cmd)
        log = svnlog.execute('.', stdout=PIPE, TZ='UTC0')[0]

        if svnlog.exit_status:
            return []

        if self.repository.filter_badchars:
            from string import maketrans
            from cStringIO import StringIO

            # Apparently some (SVN repo contains)/(SVN server dumps) some
            # characters that are illegal in an XML stream. This was the case
            # with Twisted Matrix master repository. To be safe, we replace
            # all of them with a question mark.

            if isinstance(self.repository.filter_badchars, basestring):
                allbadchars = self.repository.filter_badchars
            else:
                allbadchars = "\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09" \
                              "\x0B\x0C\x0E\x0F\x10\x11\x12\x13\x14\x15" \
                              "\x16\x17\x18\x19\x1A\x1B\x1C\x1D\x1E\x1F\x7f"

            tt = maketrans(allbadchars, "?"*len(allbadchars))
            log = StringIO(log.read().translate(tt))

        return changesets_from_svnlog(log, self.repository)
Example #6
0
    def __parse_revision_logs(self, fqrevlist, update=True):
        changesets = []
        logparser = Parser()
        c = ExternalCommand(cwd=self.repository.basedir,
                            command=self.repository.command("cat-archive-log"))
        for fqrev in fqrevlist:
            out, err = c.execute(fqrev, stdout=PIPE, stderr=PIPE)
            if c.exit_status:
                raise GetUpstreamChangesetsFailure(
                    "%s returned status %d saying\n%s" %
                    (str(c), c.exit_status, err.read()))
            err = None
            try:
                msg = logparser.parse(out)
            except Exception, err:
                pass
            if not err and msg.is_multipart():
                err = "unable to parse log description"
            if not err and update and msg.has_key('Continuation-of'):
                err = "in-version continuations not supported"
            if err:
                raise GetUpstreamChangesetsFailure(str(err))

            date = self.__parse_date(msg['Date'], msg['Standard-date'])
            author = msg['Creator']
            revision = fqrev
            logmsg = [msg['Summary']]
            s  = msg.get('Keywords', "").strip()
            if s:
                logmsg.append('Keywords: ' + s)
            s = msg.get_payload().strip()
            if s:
                logmsg.append(s)
            logmsg = '\n'.join(logmsg)
            changesets.append(Changeset(revision, date, author, logmsg))
Example #7
0
    def _tag(self, tagname, date, author):
        """
        Apply a tag.
        """

        # Sanitize tagnames for CVS: start with [a-zA-z], only include letters,
        # numbers, '-' and '_'.
        # str.isalpha et al are locale-dependent
        def iscvsalpha(chr):
            return (chr >= 'a' and chr <= 'z') or (chr >= 'A' and chr <= 'Z')

        def iscvsdigit(chr):
            return chr >= '0' and chr <= '9'

        def iscvschar(chr):
            return iscvsalpha(chr) or iscvsdigit(
                chr) or chr == '-' or chr == '_'

        def cvstagify(chr):
            if iscvschar(chr):
                return chr
            else:
                return '_'

        tagname = ''.join([cvstagify(chr) for chr in tagname])
        if not iscvsalpha(tagname[0]):
            tagname = 'tag-' + tagname

        cmd = self.repository.command("-f", "tag")
        c = ExternalCommand(cwd=self.repository.basedir, command=cmd)
        c.execute(tagname)
        if c.exit_status:
            raise ChangesetApplicationFailure("%s returned status %d" %
                                              (str(c), c.exit_status))
Example #8
0
 def _addPathnames(self, names):
     """
     Add some new filesystem objects, skipping directories.
     In monotone *explicit* directory addition is always recursive,
     so adding a directory here might interfere with renames.
     Adding files without directories doesn't cause problems,
     because adding a file implicitly adds the parent directory
     (non-recursively).
     """
     fnames = []
     for fn in names:
         if isdir(join(self.repository.basedir, fn)):
             self.log.debug(
                 "ignoring addition of directory %r "
                 "(dirs are implicitly added by files)", fn)
         else:
             fnames.append(fn)
     if len(fnames):
         # ok, we still have something to add
         cmd = self.repository.command("add", "--")
         add = ExternalCommand(cwd=self.repository.basedir, command=cmd)
         add.execute(fnames, stdout=PIPE, stderr=PIPE)
         if add.exit_status:
             raise ChangesetApplicationFailure("%s returned status %s" %
                                               (str(add), add.exit_status))
Example #9
0
    def _commit(self, date, author, patchname, changelog=None, entries=None,
                tags = [], isinitialcommit = False):
        """
        Commit the changeset.
        """

        encode = self.repository.encode

        logmessage = []
        if patchname:
            logmessage.append(patchname)
        if changelog:
            logmessage.append(changelog.replace('%', '%%'))

        cmd = self.repository.command("-u", encode(author), "commit",
                                      "-m", encode('\n'.join(logmessage)),
                                      "-D", date.astimezone(UTC).strftime('%Y/%m/%d %H:%M:%S UTC'))

        if not entries:
            entries = ['...']

        c = ExternalCommand(cwd=self.repository.basedir, command=cmd)
        c.execute(entries)

        if c.exit_status:
            raise ChangesetApplicationFailure("%s returned status %d" %
                                              (str(c), c.exit_status))
Example #10
0
    def _handleConflict(self, changeset, conflicts, conflict):
        """
        Handle the conflict raised by the application of the upstream changeset.

        Override parent behaviour: with darcs, we need to execute a revert
        on the conflicted files, **trashing** local changes, but there should
        be none of them in tailor context.
        """

        from os import walk, unlink
        from os.path import join
        from re import compile

        self.log.info("Reverting changes to %s, to solve the conflict",
                      ' '.join(conflict))
        cmd = self.repository.command("revert", "--all")
        revert = ExternalCommand(cwd=self.repository.basedir, command=cmd)
        revert.execute(conflict, input="\n")

        # Remove also the backups made by darcs
        bckre = compile('-darcs-backup[0-9]+$')
        for root, dirs, files in walk(self.repository.basedir):
            backups = [f for f in files if bckre.search(f)]
            for bck in backups:
                self.log.debug("Removing backup file %r in %r", bck, root)
                unlink(join(root, bck))
Example #11
0
    def __move_file(self, old_name, new_name):
        #
        # The aegis command to rename files does not have the -keep
        # option to preserve the content of the file, do it manually.
        #
        fp = open(os.path.join(self.repository.basedir, new_name), 'rb')
        content = fp.read()
        fp.close()
        cmd = self.repository.command("-move",
                                      "-not-logging",
                                      "-project", self.repository.module,
                                      "-change", self.change_number)
        move_file = ExternalCommand(cwd=self.repository.basedir,
                                    command=cmd)
        output = move_file.execute(old_name, new_name, stdout = PIPE, stderr = STDOUT)[0]
        if move_file.exit_status > 0:
            raise ChangesetApplicationFailure(
                "%s returned status %d, saying: %s" %
                (str(move_file), move_file.exit_status, output.read()))

        #
        # Restore the previously saved content of the renamed file.
        #
        fp = open(os.path.join(self.repository.basedir, new_name), 'wb')
        fp.write(content)
        fp.close()
Example #12
0
File: tla.py Project: yut148/tailor
    def __parse_revision_logs(self, fqrevlist, update=True):
        changesets = []
        logparser = Parser()
        c = ExternalCommand(cwd=self.repository.basedir,
                            command=self.repository.command("cat-archive-log"))
        for fqrev in fqrevlist:
            out, err = c.execute(fqrev, stdout=PIPE, stderr=PIPE)
            if c.exit_status:
                raise GetUpstreamChangesetsFailure(
                    "%s returned status %d saying\n%s" %
                    (str(c), c.exit_status, err.read()))
            err = None
            try:
                msg = logparser.parse(out)
            except Exception, err:
                pass
            if not err and msg.is_multipart():
                err = "unable to parse log description"
            if not err and update and msg.has_key('Continuation-of'):
                err = "in-version continuations not supported"
            if err:
                raise GetUpstreamChangesetsFailure(str(err))

            date = self.__parse_date(msg['Date'], msg['Standard-date'])
            author = msg['Creator']
            revision = fqrev
            logmsg = [msg['Summary']]
            s = msg.get('Keywords', "").strip()
            if s:
                logmsg.append('Keywords: ' + s)
            s = msg.get_payload().strip()
            if s:
                logmsg.append(s)
            logmsg = '\n'.join(logmsg)
            changesets.append(Changeset(revision, date, author, logmsg))
Example #13
0
    def _getUpstreamChangesets(self, sincerev=None):
        if sincerev:
            sincerev = int(sincerev)
        else:
            sincerev = 0

        cmd = self.repository.command("log", "--verbose", "--xml",
                                      "--non-interactive", "--revision",
                                      "%d:HEAD" % (sincerev + 1))
        svnlog = ExternalCommand(cwd=self.repository.basedir, command=cmd)
        log = svnlog.execute('.', stdout=PIPE, TZ='UTC0')[0]

        if svnlog.exit_status:
            return []

        if self.repository.filter_badchars:
            from string import maketrans
            from cStringIO import StringIO

            # Apparently some (SVN repo contains)/(SVN server dumps) some
            # characters that are illegal in an XML stream. This was the case
            # with Twisted Matrix master repository. To be safe, we replace
            # all of them with a question mark.

            if isinstance(self.repository.filter_badchars, basestring):
                allbadchars = self.repository.filter_badchars
            else:
                allbadchars = "\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09" \
                              "\x0B\x0C\x0E\x0F\x10\x11\x12\x13\x14\x15" \
                              "\x16\x17\x18\x19\x1A\x1B\x1C\x1D\x1E\x1F\x7f"

            tt = maketrans(allbadchars, "?" * len(allbadchars))
            log = StringIO(log.read().translate(tt))

        return changesets_from_svnlog(log, self.repository)
Example #14
0
    def _commit(self,
                date,
                author,
                patchname,
                changelog=None,
                entries=None,
                tags=[],
                isinitialcommit=False):
        """
        Commit the changeset.
        """

        encode = self.repository.encode

        logmessage = []
        if patchname:
            logmessage.append(patchname)
        if changelog:
            logmessage.append(changelog)

        # If we cannot use propset, fall back to old behaviour of
        # appending these info to the changelog

        if not self.repository.use_propset:
            logmessage.append('')
            logmessage.append('Original author: %s' % encode(author))
            logmessage.append('Date: %s' % date)
        elif not self.repository.propset_date:
            logmessage.append('')
            logmessage.append('Date: %s' % date)

        rontf = ReopenableNamedTemporaryFile('svn', 'tailor')
        log = open(rontf.name, "w")
        log.write(encode('\n'.join(logmessage)))
        log.close()

        cmd = self.repository.command("commit", "--file", rontf.name)
        commit = ExternalCommand(cwd=self.repository.basedir, command=cmd)

        if not entries or self.repository.commit_all_files:
            entries = ['.']

        out, err = commit.execute(entries, stdout=PIPE, stderr=PIPE)

        if commit.exit_status:
            raise ChangesetApplicationFailure(
                "%s returned status %d saying\n%s" %
                (str(commit), commit.exit_status, err.read()))

        revision = self._propsetRevision(out, commit, date, author)
        if not revision:
            # svn did not find anything to commit
            return

        cmd = self.repository.command("update", "--quiet")
        if self.repository.ignore_externals:
            cmd.append("--ignore-externals")
        cmd.extend(["--revision", revision])

        ExternalCommand(cwd=self.repository.basedir, command=cmd).execute()
Example #15
0
    def _commit(self,
                date,
                author,
                patchname,
                changelog=None,
                entries=None,
                tags=[],
                isinitialcommit=False):
        """
        Commit the changeset.
        """

        encode = self.repository.encode

        logmessage = []
        if patchname:
            logmessage.append(patchname)
        if changelog:
            logmessage.append(changelog.replace('%', '%%'))

        cmd = self.repository.command("commit", "-s",
                                      encode('\n'.join(logmessage)),
                                      "--author", encode(author), "--date",
                                      date.isoformat())
        c = ExternalCommand(cwd=self.repository.basedir, command=cmd)
        c.execute()

        if c.exit_status:
            raise ChangesetApplicationFailure("%s returned status %d" %
                                              (str(c), c.exit_status))
Example #16
0
    def _getUpstreamChangesets(self, sincerev=None):
        from os.path import join, exists

        branch = "HEAD"
        fname = join(self.repository.basedir, 'CVS', 'Tag')
        if exists(fname):
            tag = open(fname).read()
            if tag.startswith('T'):
                branch = tag[1:-1]
        else:
            if sincerev is not None and isinstance(sincerev, basestring) \
                   and not sincerev[0] in '0123456789':
                branch = sincerev
                sincerev = None

        if sincerev:
            sincerev = int(sincerev)

        cmd = self.repository.command("--norc",
                                      "--cvs-direct",
                                      "-u",
                                      "-b",
                                      branch,
                                      "--root",
                                      self.repository.repository,
                                      cvsps=True)
        cvsps = ExternalCommand(command=cmd)
        log = cvsps.execute(self.repository.module, stdout=PIPE, TZ='UTC0')[0]

        for cs in changesets_from_cvsps(log, sincerev):
            yield cs
Example #17
0
    def _commit(self, date, author, patchname, changelog=None, entries=None,
                tags = [], isinitialcommit = False):
        """
        Commit the changeset.
        """

        logmessage = []

        logmessage.append(date.astimezone(UTC).strftime('%Y/%m/%d %H:%M:%S UTC'))
        logmessage.append(author)
        if patchname:
            logmessage.append(patchname)
        if changelog:
            logmessage.append(changelog)
        if not patchname and not changelog:
            logmessage.append('Unnamed patch')

        cmd = self.repository.command("record", "--all", "--pipe")
        if not entries:
            entries = ['.']

        record = ExternalCommand(cwd=self.repository.basedir, command=cmd)
        record.execute(input=self.repository.encode('\n'.join(logmessage)))

        if record.exit_status:
            raise ChangesetApplicationFailure(
                "%s returned status %d" % (str(record), record.exit_status))
Example #18
0
    def _commit(self, date, author, patchname, changelog=None, entries=None,
                tags = [], isinitialcommit = False):
        """
        Commit the changeset.
        """

        from os import environ

        encode = self.repository.encode

        logmessage = []
        if patchname:
            logmessage.append(patchname)
        if changelog:
            logmessage.append(changelog)

        env = {}
        env.update(environ)

        (name, email) = self.__parse_author(author)
        if name:
            env['GIT_AUTHOR_NAME'] = encode(name)
        if email:
            env['GIT_AUTHOR_EMAIL']=email
        if date:
            env['GIT_AUTHOR_DATE']=date.strftime('%Y-%m-%d %H:%M:%S %z')
        # '-f' flag means we can get empty commits, which
        # shouldn't be a problem.
        cmd = self.repository.command("commit", "-f")
        c = ExternalCommand(cwd=self.repository.basedir, command=cmd)

        c.execute(env=env, input=encode('\n'.join(logmessage)))
        if c.exit_status:
            raise ChangesetApplicationFailure("%s returned status %d" %
                                              (str(c), c.exit_status))
Example #19
0
    def _getUpstreamChangesets(self, sincerev=None):
        from os.path import join, exists

        branch="HEAD"
        fname = join(self.repository.basedir, 'CVS', 'Tag')
        if exists(fname):
            tag = open(fname).read()
            if tag.startswith('T'):
                branch=tag[1:-1]
        else:
            if sincerev is not None and isinstance(sincerev, basestring) \
                   and not sincerev[0] in '0123456789':
                branch = sincerev
                sincerev = None

        if sincerev:
            sincerev = int(sincerev)

        cmd = self.repository.command("--norc", "--cvs-direct", "-u", "-b", branch,
                                      "--root", self.repository.repository,
                                      cvsps=True)
        cvsps = ExternalCommand(command=cmd)
        log = cvsps.execute(self.repository.module, stdout=PIPE, TZ='UTC0')[0]

        for cs in changesets_from_cvsps(log, sincerev):
            yield cs
Example #20
0
 def darcs_version(self):
     if self._darcs_version is None:
         cmd = self.command('--version')
         version = ExternalCommand(command=cmd)
         self._darcs_version = version.execute(stdout=PIPE)[0].read().strip()
         self.log.debug('Using %s, version %s', self.EXECUTABLE, self._darcs_version)
     return self._darcs_version
Example #21
0
    def _commit(self,
                date,
                author,
                patchname,
                changelog=None,
                entries=None,
                tags=[],
                isinitialcommit=False):
        """
        Commit the changeset.
        """

        logmessage = []

        logmessage.append(
            date.astimezone(UTC).strftime('%Y/%m/%d %H:%M:%S UTC'))
        logmessage.append(author)
        if patchname:
            logmessage.append(patchname)
        if changelog:
            logmessage.append(changelog)
        if not patchname and not changelog:
            logmessage.append('Unnamed patch')

        cmd = self.repository.command("record", "--all", "--pipe")
        if not entries:
            entries = ['.']

        record = ExternalCommand(cwd=self.repository.basedir, command=cmd)
        record.execute(input=self.repository.encode('\n'.join(logmessage)))

        if record.exit_status:
            raise ChangesetApplicationFailure(
                "%s returned status %d" % (str(record), record.exit_status))
Example #22
0
    def _prepareWorkingDirectory(self, source_repo):
        """
        Possibly checkout a working copy of the target VC, that will host the
        upstream source tree, when overriden by subclasses.
        """

        from re import escape

        if not self.repository.repository or exists(join(self.repository.basedir, '_MTN')):
            return

        if not self.repository.module:
            raise TargetInitializationFailure("Monotone needs a module "
                                              "defined (to be used as "
                                              "commit branch)")


        cmd = self.repository.command("setup",
                                      "--db", self.repository.repository,
                                      "--branch", self.repository.module)

        if self.repository.keygenid:
           self.repository.keyid = self.repository.keygenid
        if self.repository.keyid:
            cmd.extend( ("--key", self.repository.keyid) )

        setup = ExternalCommand(command=cmd)
        setup.execute(self.repository.basedir, stdout=PIPE, stderr=PIPE)

        if self.repository.passphrase or self.repository.custom_lua:
            monotonerc = open(join(self.repository.basedir, '_MTN', 'monotonerc'), 'w')
            if self.repository.passphrase:
                monotonerc.write(MONOTONERC % self.repository.passphrase)
            else:
                raise TargetInitializationFailure("The passphrase must be specified")
            if self.repository.custom_lua:
                self.log.info("Adding custom lua script")
                monotonerc.write(self.repository.custom_lua)
            monotonerc.close()

        # Add the tailor log file and state file to _MTN's list of
        # ignored files
        ignored = []
        logfile = self.repository.projectref().logfile
        if logfile.startswith(self.repository.basedir):
            ignored.append('^%s$' %
                           escape(logfile[len(self.repository.basedir)+1:]))

        sfname = self.repository.projectref().state_file.filename
        if sfname.startswith(self.repository.basedir):
            sfrelname = sfname[len(self.repository.basedir)+1:]
            ignored.append('^%s$' % escape(sfrelname))
            ignored.append('^%s$' % escape(sfrelname + '.old'))
            ignored.append('^%s$' % escape(sfrelname + '.journal'))

        if len(ignored) > 0:
            mt_ignored = open(join(self.repository.basedir, '.mtn-ignore'), 'a')
            mt_ignored.write('\n'.join(ignored))
            mt_ignored.close()
Example #23
0
    def _renamePathname(self, oldname, newname):
        """
        Rename a filesystem object.
        """

        cmd = self.repository.command("copy")
        rename = ExternalCommand(cwd=self.repository.basedir, command=cmd)
        rename.execute(oldname, newname)
Example #24
0
    def _removePathnames(self, names):
        """
        Remove some filesystem objects.
        """

        cmd = self.repository.command("remove", "--quiet", "--force")
        remove = ExternalCommand(cwd=self.repository.basedir, command=cmd)
        remove.execute(names)
Example #25
0
    def _removePathnames(self, names):
        """
        Remove some filesystem objects.
        """

        cmd = self.repository.command("remove", "--quiet", "--force")
        remove = ExternalCommand(cwd=self.repository.basedir, command=cmd)
        remove.execute(names)
Example #26
0
    def _renamePathname(self, oldname, newname):
        """
        Rename a filesystem object.
        """

        cmd = self.repository.command("copy")
        rename = ExternalCommand(cwd=self.repository.basedir, command=cmd)
        rename.execute(oldname, newname)
Example #27
0
    def _convert_head_initial(self, dbrepo, module, revision, working_dir):
        """
        This method handles HEAD and INITIAL pseudo-revisions, converting
        them to monotone revids
        """
        effective_rev = revision
        if revision == 'HEAD' or revision=='INITIAL':
            # in both cases we need the head(s) of the requested branch
            cmd = self.repository.command("automate","heads",
                                          "--db", dbrepo, module)
            mtl = ExternalCommand(cwd=working_dir, command=cmd)
            outstr = mtl.execute(stdout=PIPE, stderr=PIPE)
            if mtl.exit_status:
                raise InvocationError("The branch '%s' is empty" % module)

            revision = outstr[0].getvalue().split()
            if revision == 'HEAD':
                if len(revision)>1:
                    raise InvocationError("Branch '%s' has multiple heads. "
                                          "Please choose only one." % module)
                effective_rev=revision[0]
            else:
                # INITIAL requested. We must get the ancestors of
                # current head(s), topologically sort them and pick
                # the first (i.e. the "older" revision). Unfortunately
                # if the branch has multiple heads then we could end
                # up with only part of the ancestry graph.
                if len(revision)>1:
                    self.log.info('Branch "%s" has multiple heads. There '
                                  'is no guarantee to reconstruct the '
                                  'full history.', module)
                cmd = [ self.repository.command("automate","ancestors",
                                                "--db",dbrepo),
                        self.repository.command("automate","toposort",
                                                "--db",dbrepo, "-@-")
                        ]
                cmd[0].extend(revision)
                cld = ExternalCommandChain(cwd=working_dir, command=cmd)
                outstr = cld.execute()
                if cld.exit_status:
                    raise InvocationError("Ancestor reading returned "
                                          "status %d" % cld.exit_status)
                revlist = outstr[0].getvalue().split()
                if len(revlist)>1:
                    mtr = MonotoneRevToCset(repository=self.repository,
                                            working_dir=working_dir,
                                            branch=module)
                    first_cset = mtr.getCset(revlist, True)
                    if len(first_cset)==0:
                        raise InvocationError("Can't find an INITIAL revision on branch '%s'."
                                              % module)
                    effective_rev=first_cset[0].revision
                elif len(revlist)==0:
                    # Special case: only one revision in branch - is the head self
                    effective_rev=revision[0]
                else:
                    effective_rev=revlist[0]
        return effective_rev
Example #28
0
 def __delta_name (self, delta):
     cmd = self.repository.command ("-delta_name",
                                    "-project", self.repository.module)
     delta_name = ExternalCommand (cwd="/tmp", command=cmd)
     output = delta_name.execute (delta, stdout = PIPE, stderr = STDOUT)[0]
     if delta_name.exit_status > 0:
         raise ChangesetApplicationFailure(
             "%s returned status %d, saying: %s" %
             (str(delta_name), delta_name.exit_status, output.read()))
Example #29
0
 def _postCommitCheck(self):
     # If we are using --look-for-adds on commit this is useless
     if not self.repository.use_look_for_adds:
         cmd = self.repository.command("whatsnew", "--summary", "--look-for-add")
         whatsnew = ExternalCommand(cwd=self.repository.basedir, command=cmd, ok_status=(1,))
         output = whatsnew.execute(stdout=PIPE, stderr=STDOUT)[0]
         if not whatsnew.exit_status:
             raise PostCommitCheckFailure(
                 "Changes left in working dir after commit:\n%s" % output.read())
Example #30
0
File: tla.py Project: yut148/tailor
 def __apply_changeset(self, changeset):
     c = ExternalCommand(cwd=self.repository.basedir,
                         command=self.repository.command("update"))
     out, err = c.execute(changeset.revision, stdout=PIPE, stderr=PIPE)
     if not c.exit_status in [0, 1]:
         raise ChangesetApplicationFailure(
             "%s returned status %d saying\n%s" %
             (str(c), c.exit_status, err.read()))
     return self.__parse_apply_changeset_output(changeset, out)
Example #31
0
 def __delta_name(self, delta):
     cmd = self.repository.command("-delta_name", "-project",
                                   self.repository.module)
     delta_name = ExternalCommand(cwd="/tmp", command=cmd)
     output = delta_name.execute(delta, stdout=PIPE, stderr=STDOUT)[0]
     if delta_name.exit_status > 0:
         raise ChangesetApplicationFailure(
             "%s returned status %d, saying: %s" %
             (str(delta_name), delta_name.exit_status, output.read()))
Example #32
0
 def __apply_changeset(self, changeset):
     c = ExternalCommand(cwd=self.repository.basedir,
                         command=self.repository.command("update"))
     out, err = c.execute(changeset.revision, stdout=PIPE, stderr=PIPE)
     if not c.exit_status in [0, 1]:
         raise ChangesetApplicationFailure(
             "%s returned status %d saying\n%s" %
             (str(c), c.exit_status, err.read()))
     return self.__parse_apply_changeset_output(changeset, out)
Example #33
0
 def darcs_version(self):
     if self._darcs_version is None:
         cmd = self.command('--version')
         version = ExternalCommand(command=cmd)
         self._darcs_version = version.execute(
             stdout=PIPE)[0].read().strip()
         self.log.debug('Using %s, version %s', self.EXECUTABLE,
                        self._darcs_version)
     return self._darcs_version
Example #34
0
 def _renamePathname(self, oldname, newname):
     """
     Rename a filesystem object.
     """
     cmd = self.repository.command("rename", "--")
     rename = ExternalCommand(cwd=self.repository.basedir, command=cmd)
     rename.execute(oldname, newname, stdout=PIPE, stderr=PIPE)
     if rename.exit_status:
         raise ChangesetApplicationFailure(
                  "%s returned status %s" % (str(rename),rename.exit_status))
Example #35
0
File: tla.py Project: yut148/tailor
 def __checkout_initial_revision(self, fqrev, root, destdir):
     if not os.path.exists(root):
         os.makedirs(root)
     cmd = self.repository.command("get", "--no-pristine", fqrev, destdir)
     c = ExternalCommand(cwd=root, command=cmd)
     out, err = c.execute(stdout=PIPE, stderr=PIPE)
     if c.exit_status:
         raise TargetInitializationFailure(
             "%s returned status %d saying\n%s" %
             (str(c), c.exit_status, err.read()))
Example #36
0
 def _addSubtree(self, subdir):
     """
     Add a whole subtree (recursively)
     """
     cmd = self.repository.command("add", "--recursive", "--")
     add = ExternalCommand(cwd=self.repository.basedir, command=cmd)
     add.execute(subdir, stdout=PIPE, stderr=PIPE)
     if add.exit_status:
         raise ChangesetApplicationFailure("%s returned status %s" %
                                           (str(add), add.exit_status))
Example #37
0
 def __change_attribute(self, file):
     cmd = self.repository.command ("-change_attr",
                                    "-project", self.repository.module,
                                    "-change", self.change_number)
     change_attr = ExternalCommand (cwd="/tmp", command=cmd)
     output = change_attr.execute ("-file", file, stdout = PIPE, stderr = STDOUT)[0]
     if change_attr.exit_status > 0:
         raise ChangesetApplicationFailure(
             "%s returned status %d, saying: %s" %
             (str(change_attr), change_attr.exit_status, output.read()))
Example #38
0
 def __finish(self):
     cmd = self.repository.command("-finish",
                                   "-project", self.repository.module,
                                   "-change", self.change_number)
     finish = ExternalCommand(cwd="/tmp", command=cmd)
     output = finish.execute(stdout = PIPE, stderr = STDOUT)[0]
     if finish.exit_status > 0:
         raise ChangesetApplicationFailure(
             "%s returned status %d, saying: %s" %
             (str(finish), finish.exit_status, output.read()))
Example #39
0
 def _addSubtree(self, subdir):
     """
     Add a whole subtree (recursively)
     """
     cmd = self.repository.command("add", "--recursive", "--")
     add = ExternalCommand(cwd=self.repository.basedir, command=cmd)
     add.execute(subdir, stdout=PIPE, stderr=PIPE)
     if add.exit_status:
         raise ChangesetApplicationFailure("%s returned status %s" %
                                           (str(add),add.exit_status))
Example #40
0
 def __remove_file(self, file_name):
     cmd = self.repository.command("-remove", "-not-logging", "-project",
                                   self.repository.module, "-change",
                                   self.change_number)
     remove_file = ExternalCommand(cwd=self.repository.basedir, command=cmd)
     output = remove_file.execute(file_name, stdout=PIPE, stderr=STDOUT)[0]
     if remove_file.exit_status > 0:
         raise ChangesetApplicationFailure(
             "%s returned status %d, saying: %s" %
             (str(remove_file), remove_file.exit_status, output.read()))
Example #41
0
 def __finish(self):
     cmd = self.repository.command("-finish", "-project",
                                   self.repository.module, "-change",
                                   self.change_number)
     finish = ExternalCommand(cwd="/tmp", command=cmd)
     output = finish.execute(stdout=PIPE, stderr=STDOUT)[0]
     if finish.exit_status > 0:
         raise ChangesetApplicationFailure(
             "%s returned status %d, saying: %s" %
             (str(finish), finish.exit_status, output.read()))
Example #42
0
 def _renamePathname(self, oldname, newname):
     """
     Rename a filesystem object.
     """
     cmd = self.repository.command("rename", "--")
     rename = ExternalCommand(cwd=self.repository.basedir, command=cmd)
     rename.execute(oldname, newname, stdout=PIPE, stderr=PIPE)
     if rename.exit_status:
         raise ChangesetApplicationFailure(
             "%s returned status %s" % (str(rename), rename.exit_status))
Example #43
0
 def __init__(self):
     self.changesets = []
     self.current = None
     self.current_field = []
     if unidiff and repodir:
         cmd = ["darcs", "diff", "--unified", "--repodir", repodir,
                "--patch", "%(patchname)s"]
         self.darcsdiff = ExternalCommand(command=cmd)
     else:
         self.darcsdiff = None
Example #44
0
    def testExitStatusForTrue(self):
        """Verify ExternalCommand exit_status of ``true``.
        """

        if platform != 'win32':
            c = ExternalCommand(['true'])
        else:
            c = ExternalCommand(['cmd','/c exit 0'])
        c.execute()
        self.assertEqual(c.exit_status, 0)
Example #45
0
    def testExitStatusForFalse(self):
        """Verify ExternalCommand exit_status of ``false``.
        """

        if platform != 'win32':
            c = ExternalCommand(['false'])
        else:
            c = ExternalCommand(['cmd','/c exit 1'])
        c.execute()
        self.assertNotEqual(c.exit_status, 0)
Example #46
0
 def __checkout_initial_revision(self, fqrev, root, destdir):
     if not os.path.exists(root):
         os.makedirs(root)
     cmd = self.repository.command("get", "--no-pristine", fqrev, destdir)
     c = ExternalCommand(cwd=root, command=cmd)
     out, err = c.execute(stdout=PIPE, stderr=PIPE)
     if c.exit_status:
         raise TargetInitializationFailure(
             "%s returned status %d saying\n%s" %
             (str(c), c.exit_status, err.read()))
Example #47
0
    def _commit(self, date, author, patchname, changelog=None, entries=None,
                tags = [], isinitialcommit = False):
        """
        Commit the changeset.
        """

        encode = self.repository.encode

        logmessage = []
        if patchname:
            logmessage.append(patchname)
        if changelog:
            logmessage.append(changelog)

        # If we cannot use propset, fall back to old behaviour of
        # appending these info to the changelog

        if not self.repository.use_propset:
            logmessage.append('')
            logmessage.append('Original author: %s' % encode(author))
            logmessage.append('Date: %s' % date)
        elif not self.repository.propset_date:
            logmessage.append('')
            logmessage.append('Date: %s' % date)

        rontf = ReopenableNamedTemporaryFile('svn', 'tailor')
        log = open(rontf.name, "w")
        log.write(encode('\n'.join(logmessage)))
        log.close()

        cmd = self.repository.command("commit", "--file", rontf.name)
        commit = ExternalCommand(cwd=self.repository.basedir, command=cmd)

        if not entries or self.repository.commit_all_files:
            entries = ['.']

        out, err = commit.execute(entries, stdout=PIPE, stderr=PIPE)

        if commit.exit_status:
            raise ChangesetApplicationFailure("%s returned status %d saying\n%s"
                                              % (str(commit),
                                                 commit.exit_status,
                                                 err.read()))

        revision = self._propsetRevision(out, commit, date, author)
        if not revision:
            # svn did not find anything to commit
            return

        cmd = self.repository.command("update", "--quiet")
        if self.repository.ignore_externals:
            cmd.append("--ignore-externals")
        cmd.extend(["--revision", revision])

        ExternalCommand(cwd=self.repository.basedir, command=cmd).execute()
Example #48
0
 def __integrate_begin(self):
     cmd = self.repository.command("-integrate_begin", "-project",
                                   self.repository.module, "-change",
                                   self.change_number)
     integrate_begin = ExternalCommand(cwd="/tmp", command=cmd)
     output = integrate_begin.execute(stdout=PIPE, stderr=STDOUT)[0]
     if integrate_begin.exit_status > 0:
         raise ChangesetApplicationFailure(
             "%s returned status %d, saying: %s" %
             (str(integrate_begin), integrate_begin.exit_status,
              output.read()))
Example #49
0
    def testStringification(self):
        """Verify the conversion from sequence of args to string"""

        c = ExternalCommand(['some spaces here'])
        self.assertEqual(str(c), '$ "some spaces here"')

        c = ExternalCommand(['a "double quoted" arg'])
        self.assertEqual(str(c), r'$ "a \"double quoted\" arg"')

        c = ExternalCommand([r'a \" backslashed quote mark\\'])
        self.assertEqual(str(c), r'$ "a \\\" backslashed quote mark\\\\"')
Example #50
0
 def __change_attribute(self, file):
     cmd = self.repository.command("-change_attr", "-project",
                                   self.repository.module, "-change",
                                   self.change_number)
     change_attr = ExternalCommand(cwd="/tmp", command=cmd)
     output = change_attr.execute("-file", file, stdout=PIPE,
                                  stderr=STDOUT)[0]
     if change_attr.exit_status > 0:
         raise ChangesetApplicationFailure(
             "%s returned status %d, saying: %s" %
             (str(change_attr), change_attr.exit_status, output.read()))
Example #51
0
 def __integrate_begin(self):
     cmd = self.repository.command("-integrate_begin",
                                   "-project", self.repository.module,
                                   "-change", self.change_number)
     integrate_begin = ExternalCommand(cwd="/tmp", command=cmd)
     output = integrate_begin.execute(stdout = PIPE, stderr = STDOUT)[0]
     if integrate_begin.exit_status > 0:
         raise ChangesetApplicationFailure(
             "%s returned status %d, saying: %s" %
             (str(integrate_begin), integrate_begin.exit_status,
              output.read()))
Example #52
0
 def __develop_begin(self):
     cmd = self.repository.command("-develop_begin", "-project",
                                   self.repository.module, "-change",
                                   self.change_number, "-directory",
                                   self.repository.basedir)
     develop_begin = ExternalCommand(cwd="/tmp", command=cmd)
     output = develop_begin.execute(stdout=PIPE, stderr=STDOUT)[0]
     if develop_begin.exit_status > 0:
         raise ChangesetApplicationFailure(
             "%s returned status %d, saying: %s" %
             (str(develop_begin), develop_begin.exit_status, output.read()))
     self.log.info(output.read())
Example #53
0
    def testCvsReappearedDirectoryToSubversion(self):
        """Test that we can handle resurrected cvs directory to svn."""

        from vcpx.tests import DEBUG

        t = Tailorizer("svnresurdirtest", self.config)
        t()

        svnls = ExternalCommand(nolog=not DEBUG, command=['svn', 'ls'])
        manifest = svnls.execute('file://%s/cvsresurdirtest.svnrepo/test/bar' % self.TESTDIR,
                                 stdout=PIPE)[0]
        self.assertEqual(manifest.read(), "again\n")
Example #54
0
    def testWorkingDir(self):
        """Verify that the given command is executed in the specified
        working directory.
        """

        tempdir = gettempdir()
        if platform != 'win32':
            c = ExternalCommand(['pwd'], tempdir)
        else:
            c = ExternalCommand(['cmd', '/c', 'cd'], tempdir)
        out = c.execute(stdout=PIPE)[0]
        self.assertEqual(out.read(), tempdir + "\n")
Example #55
0
    def testWorkingDir(self):
        """Verify that the given command is executed in the specified
        working directory.
        """

        tempdir = gettempdir()
        if platform != 'win32':
            c = ExternalCommand(['pwd'], tempdir)
        else:
            c = ExternalCommand(['cmd','/c','cd'], tempdir)
        out = c.execute(stdout=PIPE)[0]
        self.assertEqual(out.read(), tempdir+"\n")
Example #56
0
    def _postCommitCheck(self):
        """
        Assert that all the entries in the working dir are versioned.
        """

        cmd = self.repository.command("status")
        whatsnew = ExternalCommand(cwd=self.repository.basedir, command=cmd)
        output = whatsnew.execute(stdout=PIPE, stderr=STDOUT)[0]
        unknown = [l for l in output.readlines() if l.startswith('?')]
        if unknown:
            raise PostCommitCheckFailure(
                "Changes left in working dir after commit:\n%s" % ''.join(unknown))
Example #57
0
 def _postCommitCheck(self):
     # If we are using --look-for-adds on commit this is useless
     if not self.repository.use_look_for_adds:
         cmd = self.repository.command("whatsnew", "--summary",
                                       "--look-for-add")
         whatsnew = ExternalCommand(cwd=self.repository.basedir,
                                    command=cmd,
                                    ok_status=(1, ))
         output = whatsnew.execute(stdout=PIPE, stderr=STDOUT)[0]
         if not whatsnew.exit_status:
             raise PostCommitCheckFailure(
                 "Changes left in working dir after commit:\n%s" %
                 output.read())
Example #58
0
    def _removePathnames(self, names):
        """
        Remove some filesystem object.
        """

        cmd = self.repository.command("drop", "--recursive", "--")
        drop = ExternalCommand(cwd=self.repository.basedir, command=cmd)
        dum, error = drop.execute(names, stdout=PIPE, stderr=PIPE)
        if drop.exit_status:
            errtext = error.read()
            self.log.error("Monotone drop said: %s", errtext)
            raise ChangesetApplicationFailure("%s returned status %s" %
                                              (str(drop), drop.exit_status))
Example #59
0
 def execute(self):
     outstr = None
     for cmd in self.commandchain:
         input = outstr
         exc = ExternalCommand(cwd=self.cwd, command=cmd)
         out, err = exc.execute(input=input, stdout=PIPE, stderr=PIPE)
         self.exit_status = exc.exit_status
         if self.exit_status:
             break
         outstr = out.getvalue()
         if len(outstr) <= 0:
             break
     return out, err