• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python encoding.fromlocal函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中mercurial.encoding.fromlocal函数的典型用法代码示例。如果您正苦于以下问题:Python fromlocal函数的具体用法?Python fromlocal怎么用?Python fromlocal使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了fromlocal函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: 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)
开发者ID:tpoeppke,项目名称:reds,代码行数:27,代码来源:commitsigs.py


示例2: _update_issue

def _update_issue(ui, repo, node, **kwargs):
    """Update a Roundup issue for corresponding changesets.

    Return True if updating the Roundup issue fails, else False.
    """
    repourl = ui.config('hgroundup', 'repourl')
    if not repourl:
        repourl = posixpath.join(ui.config('web', 'baseurl'), 'rev/')
    fromaddr = ui.config('hgroundup', 'fromaddr')
    toaddr = ui.config('hgroundup', 'toaddr')
    for var in ('repourl', 'fromaddr', 'toaddr'):
        if not locals()[var]:
            raise RuntimeError(
                'roundup hook not configured properly,\nplease '
                'set the "%s" property in the [hgroundup] section'
                % var)
    start = repo[node].rev()

    issues = {}

    for rev in xrange(start, len(repo)):
        ctx = repo[rev]
        description = fromlocal(ctx.description().strip())
        matches = ISSUE_PATTERN.finditer(description)
        ids = set()
        for match in matches:
            data = match.groupdict()
            ui.debug('match in commit msg: %s\n' % data)
            # check for duplicated issue numbers in the same commit msg
            if data['issue_id'] in ids:
                continue
            ids.add(data['issue_id'])
            comment = Template(COMMENT_TEMPLATE).substitute({
                'author': fromlocal(person(ctx.user())),
                'branch': ctx.branch(),
                'changeset_id': str(ctx),
                'changeset_url': posixpath.join(repourl, str(ctx)),
                'commit_msg': description.splitlines()[0],
            })
            add_comment(issues, data, comment)
    if issues:
        smtp_host = ui.config('smtp', 'host', default='localhost')
        smtp_port = int(ui.config('smtp', 'port', 25))
        s = smtplib.SMTP(smtp_host, smtp_port)
        username = ui.config('smtp', 'username', '')
        if username:
          password = ui.config('smtp', 'password', '')
          s.login(username, password)
        try:
            send_comments(s, fromaddr, toaddr, issues)
            ui.status("sent email to roundup at " + toaddr + '\n')
        except Exception, err:
            # make sure an issue updating roundup does not prevent an
            # otherwise successful push.
            ui.warn("sending email to roundup at %s failed: %s\n" %
                    (toaddr, err))
开发者ID:non-github,项目名称:python-hooks,代码行数:56,代码来源:hgroundup.py


示例3: write

def write(repo):
    '''Write bookmarks

    Write the given bookmark => hash dictionary to the .hg/bookmarks file
    in a format equal to those of localtags.

    We also store a backup of the previous state in undo.bookmarks that
    can be copied back on rollback.
    '''
    refs = repo._bookmarks

    if repo._bookmarkcurrent not in refs:
        setcurrent(repo, None)
    for mark in refs.keys():
        if not valid(mark):
            raise util.Abort(_("bookmark '%s' contains illegal "
                "character" % mark))

    wlock = repo.wlock()
    try:

        file = repo.opener('bookmarks', 'w', atomictemp=True)
        for refspec, node in refs.iteritems():
            file.write("%s %s\n" % (hex(node), encoding.fromlocal(refspec)))
        file.close()

        # touch 00changelog.i so hgweb reloads bookmarks (no lock needed)
        try:
            os.utime(repo.sjoin('00changelog.i'), None)
        except OSError:
            pass

    finally:
        wlock.release()
开发者ID:agbiotec,项目名称:galaxy-tools-vcr,代码行数:34,代码来源:bookmarks.py


示例4: sendchanges

def sendchanges(ui, master, changes):
    # send change information to one master
    from buildbot.clients import sendchange

    s = sendchange.Sender(master)
    d = defer.Deferred()
    reactor.callLater(0, d.callback, None)

    def send(res, c):
        return s.send(**c)
    for change in changes:
        for k, v in change.items():
            # Yikes!
            if isinstance(v, localstr):
                change[k] = fromlocal(v).decode('utf8', 'replace')
            elif isinstance(v, str):
                change[k] = v.decode('utf8', 'replace')
        d.addCallback(send, change)

    def printSuccess(res):
        print "change(s) sent successfully"

    def printFailure(why):
        print "change(s) NOT sent, something went wrong:"
        print why

    d.addCallbacks(printSuccess, printFailure)
    d.addBoth(lambda _: reactor.stop())
开发者ID:non-github,项目名称:python-hooks,代码行数:28,代码来源:hgbuildbot.py


示例5: write

    def write(self):
        '''Write bookmarks

        Write the given bookmark => hash dictionary to the .hg/bookmarks file
        in a format equal to those of localtags.

        We also store a backup of the previous state in undo.bookmarks that
        can be copied back on rollback.
        '''
        repo = self._repo
        if repo._bookmarkcurrent not in self:
            setcurrent(repo, None)

        wlock = repo.wlock()
        try:

            file = repo.vfs('bookmarks', 'w', atomictemp=True)
            for name, node in self.iteritems():
                file.write("%s %s\n" % (hex(node), encoding.fromlocal(name)))
            file.close()

            # touch 00changelog.i so hgweb reloads bookmarks (no lock needed)
            try:
                repo.svfs.utime('00changelog.i', None)
            except OSError:
                pass

        finally:
            wlock.release()
开发者ID:spraints,项目名称:for-example,代码行数:29,代码来源:bookmarks.py


示例6: expandpath

 def expandpath(path, default=None):
     ep = oldexpandpath(path, default)
     if ep != path:
         return ep
     bent = store.encodefilename(encoding.fromlocal(path))
     if os.path.isdir(os.path.join('.hg', 'branches', bent)):
         return 'lbranch://%s' % path
     return ep
开发者ID:jmurty,项目名称:dotfiles,代码行数:8,代码来源:localbranch.py


示例7: loadlocalbranch

 def loadlocalbranch(self, branch):
     spath = self.localbranchpath(encoding.fromlocal(branch))
     if spath != repo.spath:
         if not os.path.isdir(spath):
             raise util.Abort(_('local branch %s not found') % branch)
         self.store = store.store(self.getrequirements(), spath, util.opener)
         self.spath = self.store.path
         self.sopener = self.store.opener
         self.sopener.options = {}
开发者ID:jmurty,项目名称:dotfiles,代码行数:9,代码来源:localbranch.py


示例8: _set_bookmark

def _set_bookmark(repo, mark):
    """Set the name of the remote branch that the repo is tracking."""
    # Based on bookmarks.setcurrent
    wlock = repo.wlock()
    try:
        file = repo.opener('bookrepos.bookmark', 'w', atomictemp=True)
        file.write(encoding.fromlocal(mark))
        file.close()
    finally:
        wlock.release()
开发者ID:spicyj,项目名称:hg-bookrepos,代码行数:10,代码来源:bookrepos.py


示例9: localbranch

        def localbranch(self, name):
            # switch to local branch, creating if necessary
            def checkdir(d):
                if not os.path.isdir(d):
                    if os.path.exists(d):
                        raise util.Abort(_('%s is not a directory') % d)
                    return False
                return True

            if self.dirstate.parents()[1] != nullid:
                raise util.Abort(_('merge in progress'))

            obranch = self.getlocalbranch()
            lname = encoding.fromlocal(name)

            if obranch == name:
                return

            omf = self.changectx('').manifest()
            del self.changelog
            del self.manifest

            if not name:
                lbpath = self.join('localbranch')
                if os.path.exists(lbpath):
                    os.unlink(lbpath)
            else:
                bdir = self.join('branches')
                if not checkdir(bdir):
                    os.mkdir(bdir)
                dest = os.path.join(bdir, store.encodefilename(lname))
                if not checkdir(dest):
                    # check for non-store layout
                    if self.spath == self.path:
                        os.mkdir(dest)
                        datadir = os.path.join(dest, 'data')
                        util.copyfiles(self.join('data'), datadir)
                        for f in ('00changelog.i', '00changelog.d',
                                  '00manifest.i', '00manifest.d'):
                            src = self.join(f)
                            if os.path.exists(src):
                                util.copyfiles(src, os.path.join(dest, f))
                    else:
                        os.mkdir(dest)
                        spath = os.path.join(dest, 'store')
                        util.copyfiles(self.spath, spath)
                self.opener('localbranch', 'w').write(lname + '\n')

            self.loadlocalbranch(name)
            ctx = repo.changectx('tip')
            wlock = self.wlock()
            try:
                self.refreshdirstate(ctx, omf)
            finally:
                wlock.release()
开发者ID:jmurty,项目名称:dotfiles,代码行数:55,代码来源:localbranch.py


示例10: makememctx

    def makememctx(repo, ctx, revmap, copyfilectxfn):
        parents = newparents(repo, ctx, revmap)
        # Need to make a copy otherwise modification is made on original,
        # which is just plain wrong.
        msg = encoding.fromlocal(ctx.description())
        new_msg, changed = addcommitid(msg, repo=repo)

        memctx = context.memctx(repo, parents,
                                encoding.tolocal(new_msg), ctx.files(),
                                copyfilectxfn, user=ctx.user(),
                                date=ctx.date(), extra=dict(ctx.extra()))

        return memctx
开发者ID:pkdevboxy,项目名称:version-control-tools,代码行数:13,代码来源:client.py


示例11: write_tag

    def write_tag(self, ref):
        node = self.parsed_refs[ref]
        tag = git_to_hg_spaces(ref[len('refs/tags/'):])
        branch = self.repo[node].branch()
        # Calling self.repo.tag() doesn't append the tag to the correct
        # commit. So I copied some of localrepo._tag into here.
        # But that method, like much of mercurial's code, is ugly.
        # So I then rewrote it.

        tags_revision = revsingle(self.repo, hghex(branch_tip(self.repo, branch)))
        if '.hgtags' in tags_revision:
            old_tags = tags_revision['.hgtags'].data()
        else:
            old_tags = ''
        newtags = [old_tags]
        if old_tags and old_tags[-1] != '\n':
            newtags.append('\n')

        encoded_tag = encoding.fromlocal(tag)
        tag_line = '%s %s' % (hghex(node), encoded_tag)
        if tag_line in old_tags:
            return  # Don't commit a tag that was previously committed
        newtags.append(tag_line)

        def get_filectx(repo, memctx, file):
            return memfilectx(file, ''.join(newtags))

        if tag in self.parsed_tags:
            author, message = self.parsed_tags[tag]
            user, date, tz = author
            date_tz = (date, tz)
        else:
            message = "Added tag %s for changeset %s" % (tag, hgshort(node))
            user = None
            date_tz = None
        ctx = memctx(self.repo,
            (branch_tip(self.repo, branch), self.NULL_PARENT), message,
            ['.hgtags'], get_filectx, user, date_tz, {'branch': branch})

        tmp = encoding.encoding
        encoding.encoding = 'utf-8'
        node = self.repo.commitctx(ctx)
        encoding.encoding = tmp
开发者ID:xentac,项目名称:gitifyhg,代码行数:43,代码来源:gitexporter.py


示例12: alignString

    def alignString(self, inStr, window):
        """
        Add whitespace to the end of a string in order to make it fill
        the screen in the x direction.  The current cursor position is
        taken into account when making this calculation.  The string can span
        multiple lines.

        """
        y,xStart = window.getyx()
        width = self.xScreenSize
        # turn tabs into spaces
        inStr = inStr.expandtabs(4)
        try:
            strLen = len(unicode(encoding.fromlocal(inStr), code))
        except:
            # if text is not utf8, then assume an 8-bit single-byte encoding.
            strLen = len(inStr)

        numSpaces = (width - ((strLen + xStart) % width) - 1)
        return inStr + " " * numSpaces + "\n"
开发者ID:billxu09,项目名称:dotfiles,代码行数:20,代码来源:chunk_selector.py


示例13: activate

def activate(repo, mark):
    """
    Set the given bookmark to be 'active', meaning that this bookmark will
    follow new commits that are made.
    The name is recorded in .hg/bookmarks.current
    """
    if mark not in repo._bookmarks:
        raise AssertionError('bookmark %s does not exist!' % mark)

    active = repo._activebookmark
    if active == mark:
        return

    wlock = repo.wlock()
    try:
        file = repo.vfs('bookmarks.current', 'w', atomictemp=True)
        file.write(encoding.fromlocal(mark))
        file.close()
    finally:
        wlock.release()
    repo._activebookmark = mark
开发者ID:pierfort123,项目名称:mercurial,代码行数:21,代码来源:bookmarks.py


示例14: setcurrent

def setcurrent(repo, mark):
    '''Set the name of the bookmark that we are currently on

    Set the name of the bookmark that we are on (hg update <bookmark>).
    The name is recorded in .hg/bookmarks.current
    '''
    if mark not in repo._bookmarks:
        raise AssertionError('bookmark %s does not exist!' % mark)

    current = repo._bookmarkcurrent
    if current == mark:
        return

    wlock = repo.wlock()
    try:
        file = repo.vfs('bookmarks.current', 'w', atomictemp=True)
        file.write(encoding.fromlocal(mark))
        file.close()
    finally:
        wlock.release()
    repo._bookmarkcurrent = mark
开发者ID:RayFerr000,项目名称:PLTL,代码行数:21,代码来源:bookmarks.py


示例15: setcurrent

def setcurrent(repo, mark):
    '''Set the name of the bookmark that we are currently on

    Set the name of the bookmark that we are on (hg update <bookmark>).
    The name is recorded in .hg/bookmarks.current
    '''
    current = repo._bookmarkcurrent
    if current == mark:
        return

    if mark not in repo._bookmarks:
        mark = ''

    wlock = repo.wlock()
    try:
        file = repo.opener('bookmarks.current', 'w', atomictemp=True)
        file.write(encoding.fromlocal(mark))
        file.close()
    finally:
        wlock.release()
    repo._bookmarkcurrent = mark
开发者ID:spraints,项目名称:for-example,代码行数:21,代码来源:bookmarks.py


示例16: setcurrent

def setcurrent(repo, mark):
    '''Set the name of the bookmark that we are currently on

    Set the name of the bookmark that we are on (hg update <bookmark>).
    The name is recorded in .hg/bookmarks.current
    '''
    current = repo._bookmarkcurrent
    if current == mark:
        return

    if mark not in repo._bookmarks:
        mark = ''
    if not valid(mark):
        raise util.Abort(_("bookmark '%s' contains illegal "
            "character" % mark))

    wlock = repo.wlock()
    try:
        file = repo.opener('bookmarks.current', 'w', atomictemp=True)
        file.write(encoding.fromlocal(mark))
        file.close()
    finally:
        wlock.release()
    repo._bookmarkcurrent = mark
开发者ID:agbiotec,项目名称:galaxy-tools-vcr,代码行数:24,代码来源:bookmarks.py


示例17: hook

def hook(ui, repo, hooktype, node=None, source=None, **kwargs):
    # read config parameters
    baseurl = ui.config('hgbuildbot', 'baseurl',
                        ui.config('web', 'baseurl', ''))
    masters = ui.configlist('hgbuildbot', 'master')
    if masters:
        branchtype = ui.config('hgbuildbot', 'branchtype', 'inrepo')
        branch = ui.config('hgbuildbot', 'branch')
        fork = ui.configbool('hgbuildbot', 'fork', False)
        # notify also has this setting
        stripcount = int(ui.config('notify', 'strip') or ui.config('hgbuildbot', 'strip', 3))
        category = ui.config('hgbuildbot', 'category', None)
        project = ui.config('hgbuildbot', 'project', '')
        auth = ui.config('hgbuildbot', 'auth', None)
    else:
        ui.write("* You must add a [hgbuildbot] section to .hg/hgrc in "
                 "order to use buildbot hook\n")
        return

    if hooktype != "changegroup":
        ui.status("hgbuildbot: hooktype %s not supported.\n" % hooktype)
        return

    if fork:
        child_pid = os.fork()
        if child_pid == 0:
            # child
            pass
        else:
            # parent
            ui.status("Notifying buildbot...\n")
            return

    # only import inside the fork if forked
    from buildbot.clients import sendchange
    from twisted.internet import defer, reactor

    if branch is None:
        if branchtype == 'dirname':
            branch = os.path.basename(repo.root)

    if not auth:
        auth = 'change:changepw'
    auth = auth.split(':', 1)

    # process changesets
    def _send(res, s, c):
        if not fork:
            ui.status("rev %s sent\n" % c['revision'])
        return s.send(c['branch'], c['revision'], c['comments'],
                      c['files'], c['username'], category=category,
                      repository=repository, project=project, vc='hg',
                      properties=c['properties'])

    try:    # first try Mercurial 1.1+ api
        start = repo[node].rev()
        end = len(repo)
    except TypeError:   # else fall back to old api
        start = repo.changelog.rev(bin(node))
        end = repo.changelog.count()

    repository = strip(repo.root, stripcount)
    repository = baseurl + repository

    for master in masters:
        s = sendchange.Sender(master, auth=auth)
        d = defer.Deferred()
        reactor.callLater(0, d.callback, None)

        for rev in xrange(start, end):
            # send changeset
            node = repo.changelog.node(rev)
            manifest, user, (time, timezone), files, desc, extra = repo.changelog.read(node)
            parents = filter(lambda p: not p == nullid, repo.changelog.parents(node))
            if branchtype == 'inrepo':
                branch = extra['branch']
            is_merge = len(parents) > 1
            # merges don't always contain files, but at least one file is required by buildbot
            if is_merge and not files:
                files = ["merge"]
            properties = {'is_merge': is_merge}
            if branch:
                branch = fromlocal(branch)
            change = {
                'master': master,
                'username': fromlocal(user),
                'revision': hex(node),
                'comments': fromlocal(desc),
                'files': files,
                'branch': branch,
                'properties': properties
            }
            d.addCallback(_send, s, change)

    def _printSuccess(res):
        ui.status(s.getSuccessString(res) + '\n')

    def _printFailure(why):
        ui.warn(s.getFailureString(why) + '\n')

#.........这里部分代码省略.........
开发者ID:AsylumCorp,项目名称:buildbot,代码行数:101,代码来源:hgbuildbot.py


示例18: _write

 def _write(self, fp):
     for name, node in self.iteritems():
         fp.write("%s %s\n" % (hex(node), encoding.fromlocal(name)))
开发者ID:pierfort123,项目名称:mercurial,代码行数:3,代码来源:bookmarks.py


示例19: wrappedpushdiscovery


#.........这里部分代码省略.........

    # Given a base and tip node, find all changesets to review.
    #
    # A solution that works most of the time is to find all non-public
    # ancestors of that node. This is our default.
    #
    # If basenode is specified, we stop the traversal when we encounter it.
    #
    # Note that we will still refuse to review a public changeset even with
    # basenode. This decision is somewhat arbitrary and can be revisited later
    # if there is an actual need to review public changesets.
    nodes = [tipnode]
    # Special case where basenode is the tip node.
    if basenode and tipnode == basenode:
        pass
    else:
        for node in repo[tipnode].ancestors():
            ctx = repo[node]

            if ctx.phase() == phases.public:
                break
            if basenode and ctx.node() == basenode:
                nodes.insert(0, ctx.node())
                break

            nodes.insert(0, ctx.node())

    # Filter out public nodes.
    publicnodes = []
    for node in nodes:
        ctx = repo[node]
        if ctx.phase() == phases.public:
            publicnodes.append(node)
            ui.status(_('(ignoring public changeset %s in review request)\n') %
                        ctx.hex()[0:12])

    nodes = [n for n in nodes if n not in publicnodes]
    if not nodes:
        raise util.Abort(
            _('no non-public changesets left to review'),
            hint=_('add or change the -r argument to include draft changesets'))

    # We stop completely empty changesets prior to review.
    for node in nodes:
        ctx = repo[node]
        if not ctx.files():
            raise util.Abort(
                    _('cannot review empty changeset %s') % ctx.hex()[:12],
                    hint=_('add files to or remove changeset'))

    # Ensure all reviewed changesets have commit IDs.
    replacenodes = []
    for node in nodes:
        ctx = repo[node]
        if not parse_commit_id(encoding.fromlocal(ctx.description())):
            replacenodes.append(node)

    def makememctx(repo, ctx, revmap, copyfilectxfn):
        parents = newparents(repo, ctx, revmap)
        # Need to make a copy otherwise modification is made on original,
        # which is just plain wrong.
        msg = encoding.fromlocal(ctx.description())
        new_msg, changed = addcommitid(msg, repo=repo)

        memctx = context.memctx(repo, parents,
                                encoding.tolocal(new_msg), ctx.files(),
                                copyfilectxfn, user=ctx.user(),
                                date=ctx.date(), extra=dict(ctx.extra()))

        return memctx

    if replacenodes:
        ui.status(_('(adding commit id to %d changesets)\n') %
                  (len(replacenodes)))
        nodemap = replacechangesets(repo, replacenodes, makememctx,
                                    backuptopic='addcommitid')

        # Since we're in the middle of an operation, update references
        # to rewritten nodes.
        nodes = [nodemap.get(node, node) for node in nodes]
        pushop.revs = [nodemap.get(node, node) for node in pushop.revs]

    pushop.reviewnodes = nodes

    # Since we may rewrite changesets to contain review metadata after
    # push, abort immediately if the working directory state is not
    # compatible with rewriting. This prevents us from successfully
    # pushing and failing to update commit metadata after the push. i.e.
    # it prevents potential loss of metadata.
    #
    # There may be some scenarios where we don't rewrite after push.
    # But coding that here would be complicated. And future server changes
    # may change things like review request mapping, which may invalidate
    # client assumptions. So always assume a rewrite is needed.
    impactedrevs = list(repo.revs('%ln::', nodes))
    if repo['.'].rev() in impactedrevs:
        cmdutil.checkunfinished(repo)
        cmdutil.bailifchanged(repo)

    return orig(pushop)
开发者ID:pkdevboxy,项目名称:version-control-tools,代码行数:101,代码来源:client.py


示例20: hg2u

def hg2u(s):
    """Returns a unicode object representing the mercurial string."""
    return encoding.fromlocal(s).decode("utf-8")
开发者ID:liuyxpp,项目名称:blohg,代码行数:3,代码来源:filectx.py



注:本文中的mercurial.encoding.fromlocal函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python encoding.tolocal函数代码示例发布时间:2022-05-27
下一篇:
Python demandimport.enable函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap