本文整理汇总了Python中mercurial.util.safehasattr函数的典型用法代码示例。如果您正苦于以下问题:Python safehasattr函数的具体用法?Python safehasattr怎么用?Python safehasattr使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了safehasattr函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: log
def log(self, event, *msg, **opts):
global lastblackbox
super(blackboxui, self).log(event, *msg, **opts)
if not '*' in self.track and not event in self.track:
return
if util.safehasattr(self, '_blackbox'):
blackbox = self._blackbox
elif util.safehasattr(self, '_bbopener'):
try:
self._blackbox = self._openlogfile()
except (IOError, OSError) as err:
self.debug('warning: cannot write to blackbox.log: %s\n' %
err.strerror)
del self._bbopener
self._blackbox = None
blackbox = self._blackbox
else:
# certain ui instances exist outside the context of
# a repo, so just default to the last blackbox that
# was seen.
blackbox = lastblackbox
if blackbox:
date = util.datestr(None, '%Y/%m/%d %H:%M:%S')
user = util.getuser()
formattedmsg = msg[0] % msg[1:]
try:
blackbox.write('%s %s> %s' % (date, user, formattedmsg))
except IOError as err:
self.debug('warning: cannot write to blackbox.log: %s\n' %
err.strerror)
lastblackbox = blackbox
示例2: populateresponseforphab
def populateresponseforphab(repo, diffnum):
""":populateresponse: Runs the memoization function
for use of phabstatus and sync status
"""
if not hgutil.safehasattr(repo, '_phabstatusrevs'):
return
if (hgutil.safehasattr(repo, '_phabstatuscache') and
(repo, diffnum) in repo._phabstatuscache):
# We already have cached data for this diff
return
next_revs = repo._phabstatusrevs.peekahead()
if repo._phabstatusrevs.done:
# repo._phabstatusrevs doesn't have anything else to process.
# Remove it so we will bail out earlier next time.
del repo._phabstatusrevs
alldiffnumbers = [getdiffnum(repo, repo[rev])
for rev in next_revs]
okdiffnumbers = set(d for d in alldiffnumbers if d is not None)
# Make sure we always include the requested diff number
okdiffnumbers.add(diffnum)
# To populate the cache, the result will be used by the templater
getdiffstatus(repo, *okdiffnumbers)
示例3: clearcaches
def clearcaches(cl):
# behave somewhat consistently across internal API changes
if util.safehasattr(cl, 'clearcaches'):
cl.clearcaches()
elif util.safehasattr(cl, '_nodecache'):
from mercurial.node import nullid, nullrev
cl._nodecache = {nullid: nullrev}
cl._nodepos = None
示例4: extsetup
def extsetup(ui):
"""insert command wrappers for a bunch of commands"""
docvals = {"extension": "hgsubversion"}
for cmd, (generic, target, fixdoc, ppopts, opts) in wrapcmds.iteritems():
if fixdoc and wrappers.generic.__doc__:
docvals["command"] = cmd
docvals["Command"] = cmd.capitalize()
docvals["target"] = target
doc = wrappers.generic.__doc__.strip() % docvals
fn = getattr(commands, cmd)
fn.__doc__ = fn.__doc__.rstrip() + "\n\n " + doc
wrapped = generic and wrappers.generic or getattr(wrappers, cmd)
entry = extensions.wrapcommand(commands.table, cmd, wrapped)
if ppopts:
entry[1].extend(svnopts)
if opts:
entry[1].extend(opts)
try:
rebase = extensions.find("rebase")
if not rebase:
return
entry = extensions.wrapcommand(rebase.cmdtable, "rebase", wrappers.rebase)
entry[1].append(("", "svn", None, "automatic svn rebase"))
except:
pass
if not hgutil.safehasattr(localrepo.localrepository, "push"):
# Mercurial >= 3.2
extensions.wrapfunction(exchange, "push", wrappers.exchangepush)
if not hgutil.safehasattr(localrepo.localrepository, "pull"):
# Mercurial >= 3.2
extensions.wrapfunction(exchange, "pull", wrappers.exchangepull)
helpdir = os.path.join(os.path.dirname(__file__), "help")
entries = (
(
["subversion"],
"Working with Subversion Repositories",
lambda: open(os.path.join(helpdir, "subversion.rst")).read(),
),
)
help.helptable.extend(entries)
templatekw.keywords.update(util.templatekeywords)
revset.symbols.update(util.revsets)
subrepo.types["hgsubversion"] = svnexternals.svnsubrepo
示例5: extsetup
def extsetup(ui):
"""insert command wrappers for a bunch of commands"""
docvals = {'extension': 'hgsubversion'}
for cmd, (generic, target, fixdoc, ppopts, opts) in wrapcmds.iteritems():
if fixdoc and wrappers.generic.__doc__:
docvals['command'] = cmd
docvals['Command'] = cmd.capitalize()
docvals['target'] = target
doc = wrappers.generic.__doc__.strip() % docvals
fn = getattr(commands, cmd)
fn.__doc__ = fn.__doc__.rstrip() + '\n\n ' + doc
wrapped = generic and wrappers.generic or getattr(wrappers, cmd)
entry = extensions.wrapcommand(commands.table, cmd, wrapped)
if ppopts:
entry[1].extend(svnopts)
if opts:
entry[1].extend(opts)
try:
rebase = extensions.find('rebase')
if not rebase:
return
entry = extensions.wrapcommand(rebase.cmdtable, 'rebase', wrappers.rebase)
entry[1].append(('', 'svn', None, 'automatic svn rebase'))
except:
pass
if not hgutil.safehasattr(localrepo.localrepository, 'push'):
# Mercurial >= 3.2
extensions.wrapfunction(exchange, 'push', wrappers.exchangepush)
if not hgutil.safehasattr(localrepo.localrepository, 'pull'):
# Mercurial >= 3.2
extensions.wrapfunction(exchange, 'pull', wrappers.exchangepull)
helpdir = os.path.join(os.path.dirname(__file__), 'help')
entries = (
(['subversion'],
"Working with Subversion Repositories",
# Mercurial >= 3.6: doc(ui)
lambda *args: open(os.path.join(helpdir, 'subversion.rst')).read()),
)
help.helptable.extend(entries)
templatekw.keywords.update(util.templatekeywords)
revset.symbols.update(util.revsets)
subrepo.types['hgsubversion'] = svnexternals.svnsubrepo
示例6: relink
def relink(ui, repo, origin=None, **opts):
"""recreate hardlinks between two repositories
When repositories are cloned locally, their data files will be
hardlinked so that they only use the space of a single repository.
Unfortunately, subsequent pulls into either repository will break
hardlinks for any files touched by the new changesets, even if
both repositories end up pulling the same changes.
Similarly, passing --rev to "hg clone" will fail to use any
hardlinks, falling back to a complete copy of the source
repository.
This command lets you recreate those hardlinks and reclaim that
wasted space.
This repository will be relinked to share space with ORIGIN, which
must be on the same local disk. If ORIGIN is omitted, looks for
"default-relink", then "default", in [paths].
Do not attempt any read operations on this repository while the
command is running. (Both repositories will be locked against
writes.)
"""
if (not util.safehasattr(util, 'samefile') or
not util.safehasattr(util, 'samedevice')):
raise error.Abort(_('hardlinks are not supported on this system'))
src = hg.repository(repo.baseui, ui.expandpath(origin or 'default-relink',
origin or 'default'))
ui.status(_('relinking %s to %s\n') % (src.store.path, repo.store.path))
if repo.root == src.root:
ui.status(_('there is nothing to relink\n'))
return
if not util.samedevice(src.store.path, repo.store.path):
# No point in continuing
raise error.Abort(_('source and destination are on different devices'))
locallock = repo.lock()
try:
remotelock = src.lock()
try:
candidates = sorted(collect(src, ui))
targets = prune(candidates, src.store.path, repo.store.path, ui)
do_relink(src.store.path, repo.store.path, targets, ui)
finally:
remotelock.release()
finally:
locallock.release()
示例7: _hashmatcher
def _hashmatcher(matcher):
if util.safehasattr(matcher, 'hash'):
return matcher.hash()
sha1 = hashlib.sha1()
sha1.update(repr(matcher))
return sha1.hexdigest()
示例8: __init__
def __init__(self, ctx, path, state):
state = (state[0].split(':', 1)[1], state[1])
super(svnsubrepo, self).__init__(ctx, path, state)
# Mercurial 3.3+ set 'ui' rather than '_ui' -- set that and use 'ui'
# everywhere to maintain compatibility across versions
if not hgutil.safehasattr(self, 'ui'):
self.ui = ctx._repo.ui
示例9: pagecmd
def pagecmd(orig, ui, options, cmd, cmdfunc):
p = ui.config("pager", "pager", os.environ.get("PAGER"))
usepager = False
always = util.parsebool(options['pager'])
auto = options['pager'] == 'auto'
if not p:
pass
elif always:
usepager = True
elif not auto:
usepager = False
else:
attend = ui.configlist('pager', 'attend', attended)
ignore = ui.configlist('pager', 'ignore')
cmds, _ = cmdutil.findcmd(cmd, commands.table)
for cmd in cmds:
var = 'attend-%s' % cmd
if ui.config('pager', var):
usepager = ui.configbool('pager', var)
break
if (cmd in attend or
(cmd not in ignore and not attend)):
usepager = True
break
if usepager:
ui.setconfig('ui', 'formatted', ui.formatted(), 'pager')
ui.setconfig('ui', 'interactive', False, 'pager')
if util.safehasattr(signal, "SIGPIPE"):
signal.signal(signal.SIGPIPE, signal.SIG_DFL)
_runpager(ui, p)
return orig(ui, options, cmd, cmdfunc)
示例10: getpager
def getpager(self):
"""Read cmdargs and write pager command to r-channel if enabled
If pager isn't enabled, this writes '\0' because channeledoutput
does not allow to write empty data.
"""
args = self._readlist()
try:
cmd, _func, args, options, _cmdoptions = dispatch._parse(self.ui,
args)
except (error.Abort, error.AmbiguousCommand, error.CommandError,
error.UnknownCommand):
cmd = None
options = {}
if not cmd or 'pager' not in options:
self.cresult.write('\0')
return
pagercmd = _setuppagercmd(self.ui, options, cmd)
if pagercmd:
# Python's SIGPIPE is SIG_IGN by default. change to SIG_DFL so
# we can exit if the pipe to the pager is closed
if util.safehasattr(signal, 'SIGPIPE') and \
signal.getsignal(signal.SIGPIPE) == signal.SIG_IGN:
signal.signal(signal.SIGPIPE, signal.SIG_DFL)
self.cresult.write(pagercmd)
else:
self.cresult.write('\0')
示例11: system
def system(self, cmd, environ=None, cwd=None, onerr=None,
errprefix=None):
# fallback to the original system method if the output needs to be
# captured (to self._buffers), or the output stream is not stdout
# (e.g. stderr, cStringIO), because the chg client is not aware of
# these situations and will behave differently (write to stdout).
if (any(s[1] for s in self._bufferstates)
or not util.safehasattr(self.fout, 'fileno')
or self.fout.fileno() != sys.stdout.fileno()):
return super(chgui, self).system(cmd, environ, cwd, onerr,
errprefix)
# copied from mercurial/util.py:system()
self.flush()
def py2shell(val):
if val is None or val is False:
return '0'
if val is True:
return '1'
return str(val)
env = os.environ.copy()
if environ:
env.update((k, py2shell(v)) for k, v in environ.iteritems())
env['HG'] = util.hgexecutable()
rc = self._csystem(cmd, env, cwd)
if rc and onerr:
errmsg = '%s %s' % (os.path.basename(cmd.split(None, 1)[0]),
util.explainexit(rc)[0])
if errprefix:
errmsg = '%s: %s' % (errprefix, errmsg)
raise onerr(errmsg)
return rc
示例12: wrapdirstate
def wrapdirstate(orig, repo):
"""Make journal storage available to the dirstate object"""
dirstate = orig(repo)
if util.safehasattr(repo, 'journal'):
dirstate.journalstorage = repo.journal
dirstate.addparentchangecallback('journal', recorddirstateparents)
return dirstate
示例13: wrapdirstate
def wrapdirstate(orig, self):
ds = orig(self)
# only override the dirstate when Watchman is available for the repo
if util.safehasattr(self, "_fsmonitorstate"):
ds.__class__ = makedirstate(ds.__class__)
ds._fsmonitorinit(self._fsmonitorstate, self._watchmanclient)
return ds
示例14: strip
def strip(ui, repo, revs, update=True, backup=True, force=None, bookmarks=None):
wlock = lock = None
try:
wlock = repo.wlock()
lock = repo.lock()
if update:
checklocalchanges(repo, force=force)
urev, p2 = repo.changelog.parents(revs[0])
if (util.safehasattr(repo, 'mq') and
p2 != nullid
and p2 in [x.node for x in repo.mq.applied]):
urev = p2
hg.clean(repo, urev)
repo.dirstate.write(repo.currenttransaction())
repair.strip(ui, repo, revs, backup)
repomarks = repo._bookmarks
if bookmarks:
with repo.transaction('strip') as tr:
if repo._activebookmark in bookmarks:
bookmarksmod.deactivate(repo)
for bookmark in bookmarks:
del repomarks[bookmark]
repomarks.recordchange(tr)
for bookmark in sorted(bookmarks):
ui.write(_("bookmark '%s' deleted\n") % bookmark)
finally:
release(lock, wlock)
示例15: checkhghelps
def checkhghelps():
errorcnt = 0
for names, sec, doc in helptable:
if util.safehasattr(doc, '__call__'):
doc = doc()
errorcnt += checkseclevel(doc,
'%s help topic' % names[0],
initlevel_topic)
errorcnt += checkcmdtable(table, '%s command', initlevel_cmd)
for name in sorted(extensions.enabled().keys() +
extensions.disabled().keys()):
mod = extensions.load(None, name, None)
if not mod.__doc__:
verbose('skip checking %s extension: no help document' % name)
continue
errorcnt += checkseclevel(mod.__doc__,
'%s extension' % name,
initlevel_ext)
cmdtable = getattr(mod, 'cmdtable', None)
if cmdtable:
errorcnt += checkcmdtable(cmdtable,
'%s command of ' + name + ' extension',
initlevel_ext_cmd)
return errorcnt