本文整理汇总了Python中vcpx.shwrap.ExternalCommand类的典型用法代码示例。如果您正苦于以下问题:Python ExternalCommand类的具体用法?Python ExternalCommand怎么用?Python ExternalCommand使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ExternalCommand类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _commit
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))
示例2: _commit
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))
示例3: _commit
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))
示例4: _getUpstreamChangesets
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
示例5: _tag
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))
示例6: __move_file
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()
示例7: _getUpstreamChangesets
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)
示例8: __parse_revision_logs
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))
示例9: _commit
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))
示例10: darcs_version
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
示例11: _handleConflict
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))
示例12: _prepareWorkingDirectory
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()
示例13: _renamePathname
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)
示例14: _removePathnames
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)
示例15: _convert_head_initial
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, "[email protected]")
]
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