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

Python util.pconvert函数代码示例

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

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



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

示例1: unidiff

def unidiff(a, ad, b, bd, fn1, fn2, opts=defaultopts):
    def datetag(date, fn=None):
        if not opts.git and not opts.nodates:
            return '\t%s\n' % date
        if fn and ' ' in fn:
            return '\t\n'
        return '\n'

    if not a and not b:
        return ""

    if opts.noprefix:
        aprefix = bprefix = ''
    else:
        aprefix = 'a/'
        bprefix = 'b/'

    epoch = util.datestr((0, 0))

    fn1 = util.pconvert(fn1)
    fn2 = util.pconvert(fn2)

    if not opts.text and (util.binary(a) or util.binary(b)):
        if a and b and len(a) == len(b) and a == b:
            return ""
        l = ['Binary file %s has changed\n' % fn1]
    elif not a:
        b = splitnewlines(b)
        if a is None:
            l1 = '--- /dev/null%s' % datetag(epoch)
        else:
            l1 = "--- %s%s%s" % (aprefix, fn1, datetag(ad, fn1))
        l2 = "+++ %s%s" % (bprefix + fn2, datetag(bd, fn2))
        l3 = "@@ -0,0 +1,%d @@\n" % len(b)
        l = [l1, l2, l3] + ["+" + e for e in b]
    elif not b:
        a = splitnewlines(a)
        l1 = "--- %s%s%s" % (aprefix, fn1, datetag(ad, fn1))
        if b is None:
            l2 = '+++ /dev/null%s' % datetag(epoch)
        else:
            l2 = "+++ %s%s%s" % (bprefix, fn2, datetag(bd, fn2))
        l3 = "@@ -1,%d +0,0 @@\n" % len(a)
        l = [l1, l2, l3] + ["-" + e for e in a]
    else:
        al = splitnewlines(a)
        bl = splitnewlines(b)
        l = list(_unidiff(a, b, al, bl, opts=opts))
        if not l:
            return ""

        l.insert(0, "--- %s%s%s" % (aprefix, fn1, datetag(ad, fn1)))
        l.insert(1, "+++ %s%s%s" % (bprefix, fn2, datetag(bd, fn2)))

    for ln in xrange(len(l)):
        if l[ln][-1] != '\n':
            l[ln] += "\n\ No newline at end of file\n"

    return "".join(l)
开发者ID:RayFerr000,项目名称:PLTL,代码行数:59,代码来源:mdiff.py


示例2: canonpath

def canonpath(root, cwd, myname, auditor=None):
    '''return the canonical path of myname, given cwd and root'''
    if util.endswithsep(root):
        rootsep = root
    else:
        rootsep = root + os.sep
    name = myname
    if not os.path.isabs(name):
        name = os.path.join(root, cwd, name)
    name = os.path.normpath(name)
    if auditor is None:
        auditor = pathauditor(root)
    if name != rootsep and name.startswith(rootsep):
        name = name[len(rootsep):]
        auditor(name)
        return util.pconvert(name)
    elif name == root:
        return ''
    else:
        # Determine whether `name' is in the hierarchy at or beneath `root',
        # by iterating name=dirname(name) until that causes no change (can't
        # check name == '/', because that doesn't work on windows). The list
        # `rel' holds the reversed list of components making up the relative
        # file name we want.
        rel = []
        while True:
            try:
                s = util.samefile(name, root)
            except OSError:
                s = False
            if s:
                if not rel:
                    # name was actually the same as root (maybe a symlink)
                    return ''
                rel.reverse()
                name = os.path.join(*rel)
                auditor(name)
                return util.pconvert(name)
            dirname, basename = util.split(name)
            rel.append(basename)
            if dirname == name:
                break
            name = dirname

        # A common mistake is to use -R, but specify a file relative to the repo
        # instead of cwd.  Detect that case, and provide a hint to the user.
        hint = None
        try:
            if cwd != root:
                canonpath(root, root, myname, auditor)
                hint = (_("consider using '--cwd %s'")
                        % os.path.relpath(root, cwd))
        except util.Abort:
            pass

        raise util.Abort(_("%s not under root '%s'") % (myname, root),
                         hint=hint)
开发者ID:pierfort123,项目名称:mercurial,代码行数:57,代码来源:pathutil.py


示例3: pathto

 def pathto(self, f, cwd=None):
     if cwd is None:
         cwd = self.getcwd()
     path = util.pathto(self._root, cwd, f)
     if self._slash:
         return util.pconvert(path)
     return path
开发者ID:CS76,项目名称:ipo-galaxy,代码行数:7,代码来源:dirstate.py


示例4: tidyprefix

def tidyprefix(dest, kind, prefix):
    '''choose prefix to use for names in archive.  make sure prefix is
    safe for consumers.'''

    if prefix:
        prefix = util.normpath(prefix)
    else:
        if not isinstance(dest, str):
            raise ValueError('dest must be string if no prefix')
        prefix = os.path.basename(dest)
        lower = prefix.lower()
        for sfx in exts.get(kind, []):
            if lower.endswith(sfx):
                prefix = prefix[:-len(sfx)]
                break
    lpfx = os.path.normpath(util.localpath(prefix))
    prefix = util.pconvert(lpfx)
    if not prefix.endswith('/'):
        prefix += '/'
    # Drop the leading '.' path component if present, so Windows can read the
    # zip files (issue4634)
    if prefix.startswith('./'):
        prefix = prefix[2:]
    if prefix.startswith('../') or os.path.isabs(lpfx) or '/../' in prefix:
        raise util.Abort(_('archive prefix contains illegal components'))
    return prefix
开发者ID:pierfort123,项目名称:mercurial,代码行数:26,代码来源:archival.py


示例5: stream_out

def stream_out(repo, fileobj, untrusted=False):
    '''stream out all metadata files in repository.
    writes to file-like object, must support write() and optional flush().'''

    if not repo.ui.configbool('server', 'uncompressed', untrusted=untrusted):
        fileobj.write('1\n')
        return

    # get consistent snapshot of repo. lock during scan so lock not
    # needed while we stream, and commits can happen.
    repolock = None
    try:
        try:
            repolock = repo.lock()
        except (lock.LockHeld, lock.LockUnavailable), inst:
            repo.ui.warn('locking the repository failed: %s\n' % (inst,))
            fileobj.write('2\n')
            return

        fileobj.write('0\n')
        repo.ui.debug('scanning\n')
        entries = []
        total_bytes = 0
        for name, size in walkrepo(repo.spath):
            name = repo.decodefn(util.pconvert(name))
            entries.append((name, size))
            total_bytes += size
开发者ID:c0ns0le,项目名称:cygwin,代码行数:27,代码来源:streamclone.py


示例6: canonpath

def canonpath(root, cwd, myname, auditor=None):
    '''return the canonical path of myname, given cwd and root'''
    if util.endswithsep(root):
        rootsep = root
    else:
        rootsep = root + os.sep
    name = myname
    if not os.path.isabs(name):
        name = os.path.join(root, cwd, name)
    name = os.path.normpath(name)
    if auditor is None:
        auditor = pathauditor(root)
    if name != rootsep and name.startswith(rootsep):
        name = name[len(rootsep):]
        auditor(name)
        return util.pconvert(name)
    elif name == root:
        return ''
    else:
        # Determine whether `name' is in the hierarchy at or beneath `root',
        # by iterating name=dirname(name) until that causes no change (can't
        # check name == '/', because that doesn't work on windows).  For each
        # `name', compare dev/inode numbers.  If they match, the list `rel'
        # holds the reversed list of components making up the relative file
        # name we want.
        root_st = os.stat(root)
        rel = []
        while True:
            try:
                name_st = os.stat(name)
            except OSError:
                name_st = None
            if name_st and util.samestat(name_st, root_st):
                if not rel:
                    # name was actually the same as root (maybe a symlink)
                    return ''
                rel.reverse()
                name = os.path.join(*rel)
                auditor(name)
                return util.pconvert(name)
            dirname, basename = os.path.split(name)
            rel.append(basename)
            if dirname == name:
                break
            name = dirname

        raise util.Abort('%s not under root' % myname)
开发者ID:sandeepprasanna,项目名称:ODOO,代码行数:47,代码来源:scmutil.py


示例7: canonpath

def canonpath(root, cwd, myname, auditor=None):
    """return the canonical path of myname, given cwd and root"""
    if util.endswithsep(root):
        rootsep = root
    else:
        rootsep = root + os.sep
    name = myname
    if not os.path.isabs(name):
        name = os.path.join(root, cwd, name)
    name = os.path.normpath(name)
    if auditor is None:
        auditor = pathauditor(root)
    if name != rootsep and name.startswith(rootsep):
        name = name[len(rootsep) :]
        auditor(name)
        return util.pconvert(name)
    elif name == root:
        return ""
    else:
        # Determine whether `name' is in the hierarchy at or beneath `root',
        # by iterating name=dirname(name) until that causes no change (can't
        # check name == '/', because that doesn't work on windows). The list
        # `rel' holds the reversed list of components making up the relative
        # file name we want.
        rel = []
        while True:
            try:
                s = util.samefile(name, root)
            except OSError:
                s = False
            if s:
                if not rel:
                    # name was actually the same as root (maybe a symlink)
                    return ""
                rel.reverse()
                name = os.path.join(*rel)
                auditor(name)
                return util.pconvert(name)
            dirname, basename = util.split(name)
            rel.append(basename)
            if dirname == name:
                break
            name = dirname

        raise util.Abort(_("%s not under root '%s'") % (myname, root))
开发者ID:jordigh,项目名称:mercurial-crew,代码行数:45,代码来源:scmutil.py


示例8: _walk

 def _walk(self, relpath, recurse):
     '''yields (unencoded, encoded, size)'''
     path = self.pathjoiner(self.path, relpath)
     striplen = len(self.path) + len(os.sep)
     l = []
     if os.path.isdir(path):
         visit = [path]
         while visit:
             p = visit.pop()
             for f, kind, st in osutil.listdir(p, stat=True):
                 fp = self.pathjoiner(p, f)
                 if kind == stat.S_IFREG and f[-2:] in ('.d', '.i'):
                     n = util.pconvert(fp[striplen:])
                     l.append((decodedir(n), n, st.st_size))
                 elif kind == stat.S_IFDIR and recurse:
                     visit.append(fp)
     return sorted(l)
开发者ID:ThissDJ,项目名称:designhub,代码行数:17,代码来源:store.py


示例9: _walk

 def _walk(self, relpath, recurse):
     """yields (unencoded, encoded, size)"""
     path = self.path
     if relpath:
         path += "/" + relpath
     striplen = len(self.path) + 1
     l = []
     if os.path.isdir(path):
         visit = [path]
         while visit:
             p = visit.pop()
             for f, kind, st in osutil.listdir(p, stat=True):
                 fp = p + "/" + f
                 if kind == stat.S_IFREG and f[-2:] in (".d", ".i"):
                     n = util.pconvert(fp[striplen:])
                     l.append((decodedir(n), n, st.st_size))
                 elif kind == stat.S_IFDIR and recurse:
                     visit.append(fp)
     return sorted(l)
开发者ID:yonas,项目名称:HgWeb-Syntax-Highlighter,代码行数:19,代码来源:store.py


示例10: _walk

 def _walk(self, relpath, recurse):
     '''yields (unencoded, encoded, size)'''
     path = self.path
     if relpath:
         path += '/' + relpath
     striplen = len(self.path) + 1
     l = []
     if self.rawvfs.isdir(path):
         visit = [path]
         readdir = self.rawvfs.readdir
         while visit:
             p = visit.pop()
             for f, kind, st in readdir(p, stat=True):
                 fp = p + '/' + f
                 if kind == stat.S_IFREG and f[-2:] in ('.d', '.i'):
                     n = util.pconvert(fp[striplen:])
                     l.append((decodedir(n), n, st.st_size))
                 elif kind == stat.S_IFDIR and recurse:
                     visit.append(fp)
     l.sort()
     return l
开发者ID:pierfort123,项目名称:mercurial,代码行数:21,代码来源:store.py


示例11: tidyprefix

def tidyprefix(dest, prefix, suffixes):
    '''choose prefix to use for names in archive.  make sure prefix is
    safe for consumers.'''

    if prefix:
        prefix = util.normpath(prefix)
    else:
        if not isinstance(dest, str):
            raise ValueError('dest must be string if no prefix')
        prefix = os.path.basename(dest)
        lower = prefix.lower()
        for sfx in suffixes:
            if lower.endswith(sfx):
                prefix = prefix[:-len(sfx)]
                break
    lpfx = os.path.normpath(util.localpath(prefix))
    prefix = util.pconvert(lpfx)
    if not prefix.endswith('/'):
        prefix += '/'
    if prefix.startswith('../') or os.path.isabs(lpfx) or '/../' in prefix:
        raise util.Abort(_('archive prefix contains illegal components'))
    return prefix
开发者ID:c0ns0le,项目名称:cygwin,代码行数:22,代码来源:archival.py


示例12: tidyprefix

def tidyprefix(dest, kind, prefix):
    """choose prefix to use for names in archive.  make sure prefix is
    safe for consumers."""

    if prefix:
        prefix = util.normpath(prefix)
    else:
        if not isinstance(dest, str):
            raise ValueError("dest must be string if no prefix")
        prefix = os.path.basename(dest)
        lower = prefix.lower()
        for sfx in exts.get(kind, []):
            if lower.endswith(sfx):
                prefix = prefix[: -len(sfx)]
                break
    lpfx = os.path.normpath(util.localpath(prefix))
    prefix = util.pconvert(lpfx)
    if not prefix.endswith("/"):
        prefix += "/"
    if prefix.startswith("../") or os.path.isabs(lpfx) or "/../" in prefix:
        raise util.Abort(_("archive prefix contains illegal components"))
    return prefix
开发者ID:Pelonza,项目名称:Learn2Mine-Main,代码行数:22,代码来源:archival.py


示例13: _expandsubinclude

def _expandsubinclude(kindpats, root):
    '''Returns the list of subinclude matchers and the kindpats without the
    subincludes in it.'''
    relmatchers = []
    other = []

    for kind, pat, source in kindpats:
        if kind == 'subinclude':
            sourceroot = pathutil.dirname(util.normpath(source))
            pat = util.pconvert(pat)
            path = pathutil.join(sourceroot, pat)

            newroot = pathutil.dirname(path)
            relmatcher = match(newroot, '', [], ['include:%s' % path])

            prefix = pathutil.canonpath(root, root, newroot)
            if prefix:
                prefix += '/'
            relmatchers.append((prefix, relmatcher))
        else:
            other.append((kind, pat, source))

    return relmatchers, other
开发者ID:pierfort123,项目名称:mercurial,代码行数:23,代码来源:match.py


示例14: _abssource

def _abssource(repo, push=False, abort=True):
    """return pull/push path of repo - either based on parent repo .hgsub info
    or on the top repo config. Abort or return None if no source found."""
    if util.safehasattr(repo, '_subparent'):
        source = util.url(repo._subsource)
        if source.isabs():
            return str(source)
        source.path = posixpath.normpath(source.path)
        parent = _abssource(repo._subparent, push, abort=False)
        if parent:
            parent = util.url(util.pconvert(parent))
            parent.path = posixpath.join(parent.path or '', source.path)
            parent.path = posixpath.normpath(parent.path)
            return str(parent)
    else: # recursion reached top repo
        if util.safehasattr(repo, '_subtoppath'):
            return repo._subtoppath
        if push and repo.ui.config('paths', 'default-push'):
            return repo.ui.config('paths', 'default-push')
        if repo.ui.config('paths', 'default'):
            return repo.ui.config('paths', 'default')
    if abort:
        raise util.Abort(_("default path for subrepository %s not found") %
            reporelpath(repo))
开发者ID:agbiotec,项目名称:galaxy-tools-vcr,代码行数:24,代码来源:subrepo.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Python util.peek函数代码示例发布时间:2022-05-26
下一篇:
Python util.pathexists函数代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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