当前位置: 首页>>代码示例>>Python>>正文


Python Path.find方法代码示例

本文整理汇总了Python中fbuild.path.Path.find方法的典型用法代码示例。如果您正苦于以下问题:Python Path.find方法的具体用法?Python Path.find怎么用?Python Path.find使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在fbuild.path.Path的用法示例。


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

示例1: copy_dir_to

# 需要导入模块: from fbuild.path import Path [as 别名]
# 或者: from fbuild.path.Path import find [as 别名]
def copy_dir_to(ctx, dstdir, srcdir, *, pattern=None) -> fbuild.db.DSTS:
    #print("Copy dir to: from srcdir = " + 
    #  str(srcdir) + ", pattern=" + str(pattern) +
    #  ", to " + str(dstdir))
    srcdir = Path(srcdir)

    srcs = []
    dsts = []

    for src in srcdir.find(pattern=pattern, include_dirs=False):
        dst = src.removeroot(srcdir+os.sep).addroot(dstdir)
        dst.parent.makedirs()

        srcs.append(src)
        dsts.append(dst)

        #ctx.logger.check(' * copy', '%s -> %s' % (src, dst), color='yellow')
        try:
            src.copy(dst)
        except shutil.SameFileError:
            pass

    ctx.db.add_external_dependencies_to_call(srcs=srcs)

    return dsts
开发者ID:DawidvC,项目名称:felix,代码行数:27,代码来源:__init__.py

示例2: copy_dir_to

# 需要导入模块: from fbuild.path import Path [as 别名]
# 或者: from fbuild.path.Path import find [as 别名]
def copy_dir_to(ctx, dstdir, srcdir, *, pattern=None) -> fbuild.db.DSTS:
    srcdir = Path(srcdir)

    srcs = []
    dsts = []

    for src in srcdir.find(pattern=pattern, include_dirs=False):
        dst = src.removeroot(srcdir.parent + os.sep).addroot(dstdir)
        dst.parent.makedirs()

        srcs.append(src)
        dsts.append(dst)

        ctx.logger.check(' * copy', '%s -> %s' % (src, dst), color='yellow')
        src.copy(dst)

    ctx.db.add_external_dependencies_to_call(srcs=srcs)

    return dsts
开发者ID:adnelson,项目名称:felix,代码行数:21,代码来源:__init__.py

示例3: copy_regex

# 需要导入模块: from fbuild.path import Path [as 别名]
# 或者: from fbuild.path.Path import find [as 别名]
def copy_regex(ctx, *, srcdir, dstdir, src_pattern, dst_pattern,
        exclude_pattern=None,
        include_dirs=True) -> fbuild.db.DSTS:
    """
    Recursively copies the files from the srcdir to the dstdir using the
    src_pattern and dst_pattern to choose and rename the files.

    >>> ctx = fbuild.context.make_default_context()
    >>> copy_regex(ctx, 'src', 'dst', r'(.*\.c)', r'foo-\1')
    """

    srcdir = Path(srcdir)
    dstdir = ctx.buildroot / Path(dstdir)

    srcs = []
    dsts = []
    for src in srcdir.find(include_dirs=include_dirs):
        # Filter out any files we're ignoring.
        if exclude_pattern is not None and re.search(exclude_pattern, src):
            continue

        dst, nsub = re.subn(
            src_pattern,
            dst_pattern,
            src[len(srcdir + os.sep):])

        if nsub > 0:
            dst = dstdir / Path(dst)
            ctx.logger.check(' * copy', '%s -> %s' % (src, dst), color='yellow')

            dst.parent.makedirs()
            src.copy(dst)

            srcs.append(src)
            dsts.append(dst)

    if srcs or dsts:
        ctx.db.add_external_dependencies_to_call(srcs=srcs, dsts=dsts)

    return dsts
开发者ID:mpashton,项目名称:fbuild,代码行数:42,代码来源:file.py

示例4: find_font

# 需要导入模块: from fbuild.path import Path [as 别名]
# 或者: from fbuild.path.Path import find [as 别名]
def find_font(ctx) -> fbuild.db.DST:
    ctx.logger.check('locating arial font')
    font = None

    if sys.platform == 'win32':
        font = Path(os.environ['SYSTEMROOT']) / 'Fonts' / 'Arial.ttf'
        if not font.exists():
            font = None
    elif sys.platform.startswith('linux'):
        # Check /etc/fonts/fonts.conf.
        font_dirs = []
        fonts = Path('/etc/fonts/fonts.conf')
        if not fonts.exists():
            ctx.logger.failed()
            raise fbuild.ConfigFailed('cannot locate fonts.conf')

        tree = etree.parse(str(fonts))
        for element in tree.findall('dir'):
            path = Path(element.text)
            if element.attrib.get('prefix') == 'xdg' and \
                'XDG_DATA_HOME' in os.environ:
                path = path.addroot(os.environ['XDG_DATA_HOME'])

            try:
                font = Path(next(path.find('Arial.ttf', include_dirs=False)))
            except StopIteration:
                pass
            else:
                break

    if font is None:
        ctx.logger.failed()
        raise fbuild.ConfigFailed('cannot locate arial font')
    else:
        ctx.logger.passed('ok %s' % font)
        return font
开发者ID:midifi,项目名称:midifi,代码行数:38,代码来源:fbuildroot.py


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