Exemplo n.º 1
0
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
Exemplo n.º 2
0
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
Exemplo n.º 3
0
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 = Path(dstdir).addroot(ctx.buildroot)

    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
Exemplo n.º 4
0
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
Exemplo n.º 5
0
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
Exemplo n.º 6
0
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