本文整理汇总了Python中mercurial.util.parsedate函数的典型用法代码示例。如果您正苦于以下问题:Python parsedate函数的具体用法?Python parsedate怎么用?Python parsedate使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了parsedate函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: fakewrite
def fakewrite(ui, func):
# fake "now" of 'pack_dirstate' only if it is invoked while 'func'
fakenow = ui.config('fakedirstatewritetime', 'fakenow')
if not fakenow:
# Execute original one, if fakenow isn't configured. This is
# useful to prevent subrepos from executing replaced one,
# because replacing 'parsers.pack_dirstate' is also effective
# in subrepos.
return func()
# parsing 'fakenow' in YYYYmmddHHMM format makes comparison between
# 'fakenow' value and 'touch -t YYYYmmddHHMM' argument easy
fakenow = util.parsedate(fakenow, ['%Y%m%d%H%M'])[0]
orig_pack_dirstate = parsers.pack_dirstate
orig_dirstate_getfsnow = dirstate._getfsnow
wrapper = lambda *args: pack_dirstate(fakenow, orig_pack_dirstate, *args)
parsers.pack_dirstate = wrapper
dirstate._getfsnow = lambda *args: fakenow
try:
return func()
finally:
parsers.pack_dirstate = orig_pack_dirstate
dirstate._getfsnow = orig_dirstate_getfsnow
示例2: makepatch
def makepatch(ui, repo, name=None, pats=[], opts={}):
"""sets up the call for attic.createpatch and makes the call"""
s = repo.attic
force = opts.get('force')
if name and s.exists(name) and name != s.applied and not force:
raise util.Abort(_('attempting to overwrite existing patch'))
if name and s.applied and name != s.applied and not force:
raise util.Abort(_('a different patch is active'))
if not name:
name = s.applied
if not name:
raise util.Abort(_('you need to supply a patch name'))
date, user, message = None, None, ''
if s.applied:
data = patch.extract(ui, open(s.join(s.applied), 'r'))
tmpname, message, user, date, branch, nodeid, p1, p2 = data
os.unlink(tmpname)
msg = cmdutil.logmessage(opts)
if not msg:
msg = message
if opts.get('edit'):
msg = ui.edit(msg, ui.username())
setupheaderopts(ui, opts)
if opts.get('user'):
user=opts['user']
if not user:
user = ui.username()
if opts.get('date'):
date=opts['date']
if not date:
date = util.makedate()
date = util.parsedate(date)
s.createpatch(repo, name, msg, user, date, pats, opts)
示例3: chash
def chash(manifest, files, desc, p1, p2, user, date, extra):
"""Compute changeset hash from the changeset pieces."""
user = user.strip()
if "\n" in user:
raise error.RevlogError(_("username %s contains a newline")
% repr(user))
# strip trailing whitespace and leading and trailing empty lines
desc = '\n'.join([l.rstrip() for l in desc.splitlines()]).strip('\n')
user, desc = encoding.fromlocal(user), encoding.fromlocal(desc)
if date:
parseddate = "%d %d" % util.parsedate(date)
else:
parseddate = "%d %d" % util.makedate()
extra = extra.copy()
if 'signature' in extra:
del extra['signature']
if extra.get("branch") in ("default", ""):
del extra["branch"]
if extra:
extra = changelog.encodeextra(extra)
parseddate = "%s %s" % (parseddate, extra)
l = [hex(manifest), user, parseddate] + sorted(files) + ["", desc]
text = "\n".join(l)
return revlog.hash(text, p1, p2)
示例4: __init__
def __init__(self, patchpath, repo, pf=None, rev=None):
""" Read patch context from file
:param pf: currently ignored
The provided handle is used to read the patch and
the patchpath contains the name of the patch.
The handle is NOT closed.
"""
self._path = patchpath
if rev:
assert isinstance(rev, str)
self._patchname = rev
else:
self._patchname = os.path.basename(patchpath)
self._repo = repo
self._rev = rev or 'patch'
self._status = [[], [], []]
self._fileorder = []
self._user = ''
self._desc = ''
self._branch = ''
self._node = node.nullid
self._mtime = None
self._fsize = 0
self._parseerror = None
self._phase = 'draft'
try:
self._mtime = os.path.getmtime(patchpath)
self._fsize = os.path.getsize(patchpath)
ph = mq.patchheader(self._path)
self._ph = ph
except EnvironmentError:
self._date = util.makedate()
return
try:
self._branch = ph.branch or ''
self._node = binascii.unhexlify(ph.nodeid)
if self._repo.ui.configbool('mq', 'secret'):
self._phase = 'secret'
except TypeError:
pass
except AttributeError:
# hacks to try to deal with older versions of mq.py
self._branch = ''
ph.diffstartline = len(ph.comments)
if ph.message:
ph.diffstartline += 1
except error.ConfigError:
pass
self._user = ph.user or ''
self._desc = ph.message and '\n'.join(ph.message).strip() or ''
try:
self._date = ph.date and util.parsedate(ph.date) or util.makedate()
except error.Abort:
self._date = util.makedate()
示例5: _getmetadata
def _getmetadata(**opts):
metadata = {}
date = opts.get('date')
user = opts.get('user')
if date:
metadata['date'] = '%i %i' % util.parsedate(date)
if user:
metadata['user'] = user
return metadata
示例6: printFile
def printFile(ui, repo, file, disableLastCommit, transport):
date = '0 0'
description = 'n/a'
if not disableLastCommit:
linkrev = repo[file.linkrev()]
date = '%d %d' % util.parsedate(linkrev.date())
description = linkrev.description()
format = '%s %i %s %s\n'
if transport:
format = 'f%s\n%i %s %s\0'
ui.write( format % (file.path(), file.size(), date, description) )
示例7: validatePage
def validatePage(self):
if self.cmd.core.running():
return False
if len(self.repo.parents()) == 1:
# commit succeeded, repositoryChanged() called wizard().next()
if self.skiplast.isChecked():
self.wizard().close()
return True
user = qtlib.getCurrentUsername(self, self.repo, self.opts)
if not user:
return False
self.setTitle(_('Committing...'))
self.setSubTitle(_('Please wait while committing merged files.'))
message = hglib.fromunicode(self.msgEntry.text())
cmdline = ['commit', '--verbose', '--message', message,
'--repository', self.repo.root, '--user', user]
if self.opts.get('recurseinsubrepos'):
cmdline.append('--subrepos')
try:
date = self.opts.get('date')
if date:
util.parsedate(date)
dcmd = ['--date', date]
else:
dcmd = []
except error.Abort, e:
if e.hint:
err = _('%s (hint: %s)') % (hglib.tounicode(str(e)),
hglib.tounicode(e.hint))
else:
err = hglib.tounicode(str(e))
qtlib.WarningMsgBox(_('TortoiseHg Merge Commit'),
_('Error creating interpreting commit date (%s).\n'
'Using current date instead.'), err)
dcmd = []
示例8: internalpatch
def internalpatch(orig, ui, repo, patchobj, strip,
prefix='', files=None,
eolmode='strict', similarity=0):
if files is None:
files = set()
r = orig(ui, repo, patchobj, strip,
prefix=prefix, files=files,
eolmode=eolmode, similarity=similarity)
fakenow = ui.config('fakepatchtime', 'fakenow')
if fakenow:
# parsing 'fakenow' in YYYYmmddHHMM format makes comparison between
# 'fakenow' value and 'touch -t YYYYmmddHHMM' argument easy
fakenow = util.parsedate(fakenow, ['%Y%m%d%H%M'])[0]
for f in files:
repo.wvfs.utime(f, (fakenow, fakenow))
return r
示例9: getdate
def getdate(n):
if n not in dates:
dates[n] = util.parsedate(self.commitcache[n].date)
return dates[n]
示例10: svnutcdate
def svnutcdate(text):
''':svnutcdate: Date. Returns a UTC-date in this format: "2009-08-18
11:00:13Z".
'''
return util.datestr((util.parsedate(text)[0], 0), '%Y-%m-%d %H:%M:%SZ')
示例11: utcdate
def utcdate(text):
''':utcdate: Date. Returns a UTC-date in this format: "2009/08/18 11:00:13".
'''
return util.datestr((util.parsedate(text)[0], 0), '%Y/%m/%d %H:%M:%S')
示例12: createlog
#.........这里部分代码省略.........
assert not re_32.match(line), _('must have at least '
'some revisions')
elif state == 5:
# expecting revision number and possibly (ignored) lock indication
# we create the logentry here from values stored in states 0 to 4,
# as this state is re-entered for subsequent revisions of a file.
match = re_50.match(line)
assert match, _('expected revision number')
e = logentry(rcs=scache(rcs),
file=scache(filename),
revision=tuple([int(x) for x in
match.group(1).split('.')]),
branches=[],
parent=None,
commitid=None,
mergepoint=None,
branchpoints=set())
state = 6
elif state == 6:
# expecting date, author, state, lines changed
match = re_60.match(line)
assert match, _('revision must be followed by date line')
d = match.group(1)
if d[2] == '/':
# Y2K
d = '19' + d
if len(d.split()) != 3:
# cvs log dates always in GMT
d = d + ' UTC'
e.date = util.parsedate(d, ['%y/%m/%d %H:%M:%S',
'%Y/%m/%d %H:%M:%S',
'%Y-%m-%d %H:%M:%S'])
e.author = scache(match.group(2))
e.dead = match.group(3).lower() == 'dead'
if match.group(5):
if match.group(6):
e.lines = (int(match.group(5)), int(match.group(6)))
else:
e.lines = (int(match.group(5)), 0)
elif match.group(6):
e.lines = (0, int(match.group(6)))
else:
e.lines = None
if match.group(7): # cvs 1.12 commitid
e.commitid = match.group(8)
if match.group(9): # cvsnt mergepoint
myrev = match.group(10).split('.')
if len(myrev) == 2: # head
e.mergepoint = 'HEAD'
else:
myrev = '.'.join(myrev[:-2] + ['0', myrev[-2]])
branches = [b for b in branchmap if branchmap[b] == myrev]
assert len(branches) == 1, ('unknown branch: %s'
% e.mergepoint)
e.mergepoint = branches[0]
e.comment = []
state = 7
示例13: fetch
def fetch(ui, repo, source="default", **opts):
"""pull changes from a remote repository, merge new changes if needed.
This finds all changes from the repository at the specified path
or URL and adds them to the local repository.
If the pulled changes add a new branch head, the head is
automatically merged, and the result of the merge is committed.
Otherwise, the working directory is updated to include the new
changes.
When a merge is needed, the working directory is first updated to
the newly pulled changes. Local changes are then merged into the
pulled changes. To switch the merge order, use --switch-parent.
See :hg:`help dates` for a list of formats valid for -d/--date.
Returns 0 on success.
"""
date = opts.get("date")
if date:
opts["date"] = util.parsedate(date)
parent, p2 = repo.dirstate.parents()
branch = repo.dirstate.branch()
try:
branchnode = repo.branchtip(branch)
except error.RepoLookupError:
branchnode = None
if parent != branchnode:
raise util.Abort(_("working dir not at branch tip " '(use "hg update" to check out branch tip)'))
if p2 != nullid:
raise util.Abort(_("outstanding uncommitted merge"))
wlock = lock = None
try:
wlock = repo.wlock()
lock = repo.lock()
mod, add, rem, del_ = repo.status()[:4]
if mod or add or rem:
raise util.Abort(_("outstanding uncommitted changes"))
if del_:
raise util.Abort(_("working directory is missing some files"))
bheads = repo.branchheads(branch)
bheads = [head for head in bheads if len(repo[head].children()) == 0]
if len(bheads) > 1:
raise util.Abort(_("multiple heads in this branch " '(use "hg heads ." and "hg merge" to merge)'))
other = hg.peer(repo, opts, ui.expandpath(source))
ui.status(_("pulling from %s\n") % util.hidepassword(ui.expandpath(source)))
revs = None
if opts["rev"]:
try:
revs = [other.lookup(rev) for rev in opts["rev"]]
except error.CapabilityError:
err = _("other repository doesn't support revision lookup, " "so a rev cannot be specified.")
raise util.Abort(err)
# Are there any changes at all?
modheads = repo.pull(other, heads=revs)
if modheads == 0:
return 0
# Is this a simple fast-forward along the current branch?
newheads = repo.branchheads(branch)
newchildren = repo.changelog.nodesbetween([parent], newheads)[2]
if len(newheads) == 1 and len(newchildren):
if newchildren[0] != parent:
return hg.update(repo, newchildren[0])
else:
return 0
# Are there more than one additional branch heads?
newchildren = [n for n in newchildren if n != parent]
newparent = parent
if newchildren:
newparent = newchildren[0]
hg.clean(repo, newparent)
newheads = [n for n in newheads if n != newparent]
if len(newheads) > 1:
ui.status(
_("not merging with %d other new branch heads " '(use "hg heads ." and "hg merge" to merge them)\n')
% (len(newheads) - 1)
)
return 1
if not newheads:
return 0
# Otherwise, let's merge.
err = False
if newheads:
# By default, we consider the repository we're pulling
# *from* as authoritative, so we merge our changes into
# theirs.
if opts["switch_parent"]:
firstparent, secondparent = newparent, newheads[0]
#.........这里部分代码省略.........
示例14: _parse
def _parse(self):
if self.changeset is not None:
return
self.changeset = {}
maxrev = 0
cmd = self.cmd
if self.rev:
# TODO: handle tags
try:
# patchset number?
maxrev = int(self.rev)
except ValueError:
try:
# date
util.parsedate(self.rev, ['%Y/%m/%d %H:%M:%S'])
cmd = '%s -d "1970/01/01 00:00:01" -d "%s"' % (cmd, self.rev)
except util.Abort:
raise util.Abort(_('revision %s is not a patchset number or date') % self.rev)
d = os.getcwd()
try:
os.chdir(self.path)
id = None
state = 0
filerevids = {}
if self.builtin:
# builtin cvsps code
self.ui.status(_('using builtin cvsps\n'))
cache = 'update'
if not self.ui.configbool('convert', 'cvsps.cache', True):
cache = None
db = cvsps.createlog(self.ui, cache=cache)
db = cvsps.createchangeset(self.ui, db,
fuzz=int(self.ui.config('convert', 'cvsps.fuzz', 60)),
mergeto=self.ui.config('convert', 'cvsps.mergeto', None),
mergefrom=self.ui.config('convert', 'cvsps.mergefrom', None))
for cs in db:
if maxrev and cs.id>maxrev:
break
id = str(cs.id)
cs.author = self.recode(cs.author)
self.lastbranch[cs.branch] = id
cs.comment = self.recode(cs.comment)
date = util.datestr(cs.date)
self.tags.update(dict.fromkeys(cs.tags, id))
files = {}
for f in cs.entries:
files[f.file] = "%s%s" % ('.'.join([str(x) for x in f.revision]),
['', '(DEAD)'][f.dead])
# add current commit to set
c = commit(author=cs.author, date=date,
parents=[str(p.id) for p in cs.parents],
desc=cs.comment, branch=cs.branch or '')
self.changeset[id] = c
self.files[id] = files
else:
# external cvsps
for l in util.popen(cmd):
if state == 0: # header
if l.startswith("PatchSet"):
id = l[9:-2]
if maxrev and int(id) > maxrev:
# ignore everything
state = 3
elif l.startswith("Date:"):
date = util.parsedate(l[6:-1], ["%Y/%m/%d %H:%M:%S"])
date = util.datestr(date)
elif l.startswith("Branch:"):
branch = l[8:-1]
self.parent[id] = self.lastbranch.get(branch, 'bad')
self.lastbranch[branch] = id
elif l.startswith("Ancestor branch:"):
ancestor = l[17:-1]
# figure out the parent later
self.parent[id] = self.lastbranch[ancestor]
elif l.startswith("Author:"):
author = self.recode(l[8:-1])
elif l.startswith("Tag:") or l.startswith("Tags:"):
t = l[l.index(':')+1:]
t = [ut.strip() for ut in t.split(',')]
if (len(t) > 1) or (t[0] and (t[0] != "(none)")):
self.tags.update(dict.fromkeys(t, id))
elif l.startswith("Log:"):
# switch to gathering log
state = 1
log = ""
elif state == 1: # log
if l == "Members: \n":
# switch to gathering members
files = {}
oldrevs = []
log = self.recode(log[:-1])
state = 2
else:
#.........这里部分代码省略.........
示例15: new
def new(self, repo, patchfn, *pats, **opts):
"""options:
msg: a string or a no-argument function returning a string
"""
msg = opts.get('msg')
user = opts.get('user')
date = opts.get('date')
if date:
date = util.parsedate(date)
diffopts = self.diffopts({'git': opts.get('git')})
if opts.get('checkname', True):
self.checkpatchname(patchfn)
inclsubs = self.checksubstate(repo)
if inclsubs:
inclsubs.append('.hgsubstate')
substatestate = repo.dirstate['.hgsubstate']
if opts.get('include') or opts.get('exclude') or pats:
if inclsubs:
pats = list(pats or []) + inclsubs
match = scmutil.match(repo[None], pats, opts)
# detect missing files in pats
def badfn(f, msg):
if f != '.hgsubstate': # .hgsubstate is auto-created
raise util.Abort('%s: %s' % (f, msg))
match.bad = badfn
changes = repo.status(match=match)
m, a, r, d = changes[:4]
else:
changes = self.checklocalchanges(repo, force=True)
m, a, r, d = changes
match = scmutil.matchfiles(repo, m + a + r + inclsubs)
if len(repo[None].parents()) > 1:
raise util.Abort(_('cannot manage merge changesets'))
commitfiles = m + a + r
self.checktoppatch(repo)
insert = self.fullseriesend()
wlock = repo.wlock()
try:
try:
# if patch file write fails, abort early
p = self.opener(patchfn, "w")
except IOError, e:
raise util.Abort(_('cannot write patch "%s": %s')
% (patchfn, e.strerror))
try:
if self.plainmode:
if user:
p.write("From: " + user + "\n")
if not date:
p.write("\n")
if date:
p.write("Date: %d %d\n\n" % date)
else:
p.write("# HG changeset patch\n")
p.write("# Parent "
+ hex(repo[None].p1().node()) + "\n")
if user:
p.write("# User " + user + "\n")
if date:
p.write("# Date %s %s\n\n" % date)
if util.safehasattr(msg, '__call__'):
msg = msg()
commitmsg = msg and msg or ("[mq]: %s" % patchfn)
n = newcommit(repo, None, commitmsg, user, date, match=match,
force=True)
if n is None:
raise util.Abort(_("repo commit failed"))
try:
self.fullseries[insert:insert] = [patchfn]
self.applied.append(statusentry(n, patchfn))
self.parseseries()
self.seriesdirty = True
self.applieddirty = True
if msg:
msg = msg + "\n\n"
p.write(msg)
if commitfiles:
parent = self.qparents(repo, n)
if inclsubs:
self.putsubstate2changes(substatestate, changes)
chunks = patchmod.diff(repo, node1=parent, node2=n,
changes=changes, opts=diffopts)
for chunk in chunks:
p.write(chunk)
p.close()
r = self.qrepo()
if r:
r[None].add([patchfn])
except: # re-raises
repo.rollback()
raise
except Exception:
patchpath = self.join(patchfn)
try:
os.unlink(patchpath)
except OSError:
self.ui.warn(_('error unlinking %s\n') % patchpath)
raise
self.removeundo(repo)