コード例 #1
0
ファイル: fontbakery.py プロジェクト: lowks/fontbakery-cli
def run_bakery(sourcedir, config=None):

    try:
        if config:
            config = yaml.safe_load(open(config, 'r'))
        else:
            config = yaml.safe_load(open(BAKERY_CONFIGURATION_DEFAULTS))

        if 'process_files' not in config:
            directory = UpstreamDirectory(sourcedir)
            config['process_files'] = directory.get_fonts()

        bakeryyaml = os.path.abspath(os.path.join(sourcedir, '.bakery.yaml'))
        l = open(bakeryyaml, 'w')
        l.write(yaml.safe_dump(config))
        l.close()

        b = Bakery('', sourcedir, 'builds', sourcedir)

        b.init_logging('%s.process.log' % sourcedir.replace('/', '-'))

        b.pipes = [
            pipe.Copy, pipe.Build, pipe.Rename, pipe.Metadata, pipe.PyFtSubset,
            pipe.FontLint, pipe.Optimize, pipe.AutoFix, pipe.CopyLicense,
            pipe.CopyFontLog, pipe.CopyDescription, pipe.CopyMetadata,
            pipe.CopyTxtFiles, pipe.TTFAutoHint, pipe.PyFontaine
        ]

        config = os.path.join(sourcedir, '.bakery.yaml')
        b.load_config(config)

        b.run()
    except Exception, ex:
        print >> sys.stderr, 'FAILED: %s' % sourcedir
        print >> sys.stderr, ex
コード例 #2
0
def run_bakery(bakery_yml_file, verbose=False):
    try:
        config = yaml.safe_load(open(op.join(bakery_yml_file), 'r'))
    except IOError:
        config = yaml.safe_load(open(BAKERY_CONFIGURATION_DEFAULTS))

    sourcedir = op.dirname(bakery_yml_file)
    try:
        builddir = 'build'
        if GITPYTHON_INSTALLED:
            try:
                repo = Repo(sourcedir)
                builddir = repo.git.rev_parse('HEAD', short=True)
            except git.exc.InvalidGitRepositoryError:
                pass
        builddir = os.environ.get('TRAVIS_COMMIT', builddir)

        if 'process_files' not in config:
            directory = UpstreamDirectory(sourcedir)
            # normalize process_files path
            config['process_files'] = directory.get_fonts()

        create_bakery_config(bakery_yml_file, config)

        b = Bakery('', sourcedir, 'builds', builddir)
        b.load_config(bakery_yml_file)
        b.run()
    except:
        if verbose or config.get('verbose'):
            raise
        sys.exit(1)
コード例 #3
0
def run_bakery(path, verbose=False):
    # fontbakery-build supports passing arguments of directory or
    # concrete bakery.y[a]ml files. In case of passing directory
    # it looks at existing bakery.yml or bakery.yaml and runs on
    # first matched filepath

    # There can also be cases when directory does not contain any
    # bakery.y[a]ml or passed bakery.yml file does not exist. Then
    # fontbakery-build loads default configuration.
    bakery_yml_file = None
    sourcedir = path

    if os.path.isdir(path):
        for filename in ['bakery.yml', 'bakery.yaml']:
            if os.path.exists(os.path.join(path, filename)):
                bakery_yml_file = os.path.join(path, filename)
                break
    else:
        bakery_yml_file = path
        sourcedir = os.path.dirname(path)

    try:
        if bakery_yml_file:
            config = yaml.safe_load(open(bakery_yml_file, 'r'))
        else:
            raise IOError
    except IOError:
        bakery_yml_file = os.path.join(sourcedir, 'bakery.yml')
        config = yaml.safe_load(open(BAKERY_CONFIGURATION_DEFAULTS))

    try:
        builddir = 'build'
        if GITPYTHON_INSTALLED:
            try:
                repo = Repo(sourcedir)
                builddir = repo.git.rev_parse('HEAD', short=True)
            except git.exc.InvalidGitRepositoryError:
                pass
        builddir = os.environ.get('TRAVIS_COMMIT', builddir)

        if 'process_files' not in config:
            directory = UpstreamDirectory(sourcedir)
            # normalize process_files path
            config['process_files'] = directory.get_fonts()

        create_bakery_config(bakery_yml_file, config)

        Bakery.verbose = verbose or config.get('verbose')

        b = Bakery('', sourcedir, 'builds', builddir)
        b.addLoggingToFile()
        b.load_config(bakery_yml_file)
        b.run()
    except:
        if verbose or config.get('verbose'):
            raise
        sys.exit(1)
コード例 #4
0
ファイル: fontbakery.py プロジェクト: lowks/fontbakery-cli
def run_bakery(sourcedir, config=None):

    try:
        if config:
            config = yaml.safe_load(open(config, 'r'))
        else:
            config = yaml.safe_load(open(BAKERY_CONFIGURATION_DEFAULTS))

        if 'process_files' not in config:
            directory = UpstreamDirectory(sourcedir)
            config['process_files'] = directory.get_fonts()

        bakeryyaml = os.path.abspath(os.path.join(sourcedir, '.bakery.yaml'))
        l = open(bakeryyaml, 'w')
        l.write(yaml.safe_dump(config))
        l.close()

        b = Bakery('', sourcedir, 'builds', sourcedir)

        b.init_logging('%s.process.log' % sourcedir.replace('/', '-'))

        b.pipes = [
            pipe.Copy,
            pipe.Build,
            pipe.Rename,
            pipe.Metadata,
            pipe.PyFtSubset,
            pipe.FontLint,
            pipe.Optimize,
            pipe.AutoFix,
            pipe.CopyLicense,
            pipe.CopyFontLog,
            pipe.CopyDescription,
            pipe.CopyMetadata,
            pipe.CopyTxtFiles,
            pipe.TTFAutoHint,
            pipe.PyFontaine
        ]

        config = os.path.join(sourcedir, '.bakery.yaml')
        b.load_config(config)

        b.run()
    except Exception, ex:
        print >> sys.stderr, 'FAILED: %s' % sourcedir
        print >> sys.stderr, ex
コード例 #5
0
def run_bakery(path, verbose=False):
    # fontbakery-build supports passing arguments of directory or
    # concrete bakery.y[a]ml files. In case of passing directory
    # it looks at existing bakery.yml or bakery.yaml and runs on
    # first matched filepath

    # There can also be cases when directory does not contain any
    # bakery.y[a]ml or passed bakery.yml file does not exist. Then
    # fontbakery-build loads default configuration.
    bakery_yml_file = None
    sourcedir = path

    if os.path.isdir(path):
        for filename in ["bakery.yml", "bakery.yaml"]:
            if os.path.exists(os.path.join(path, filename)):
                bakery_yml_file = os.path.join(path, filename)
                break
    else:
        bakery_yml_file = path
        sourcedir = os.path.dirname(path)

    try:
        if bakery_yml_file:
            config = yaml.safe_load(open(bakery_yml_file, "r"))
        else:
            raise IOError
    except IOError:
        bakery_yml_file = os.path.join(sourcedir, "bakery.yml")
        config = yaml.safe_load(open(BAKERY_CONFIGURATION_DEFAULTS))

    try:
        builddir = "build"
        if GITPYTHON_INSTALLED:
            try:
                repo = Repo(sourcedir)
                builddir = repo.git.rev_parse("HEAD", short=True)
            except git.exc.InvalidGitRepositoryError:
                pass
        builddir = os.environ.get("TRAVIS_COMMIT", builddir)

        if "process_files" not in config:
            directory = UpstreamDirectory(sourcedir)
            # normalize process_files path
            config["process_files"] = directory.get_fonts()

        create_bakery_config(bakery_yml_file, config)

        b = Bakery("", sourcedir, "builds", builddir)
        b.addLoggingToFile()
        b.load_config(bakery_yml_file)
        b.run()

        if not ttfautohint_installed():
            msg = (
                "Command line tool `ttfautohint` is required. Install it with"
                " `apt-get install ttfautohint` or `brew install ttfautohint`"
            )
            logger.error(msg)
    except:
        if verbose or config.get("verbose"):
            raise
        sys.exit(1)
コード例 #6
0
def run_bakery(path, verbose=False):
    # fontbakery-build supports passing arguments of directory or
    # concrete bakery.y[a]ml files. In case of passing directory
    # it looks at existing bakery.yml or bakery.yaml and runs on
    # first matched filepath

    # There can also be cases when directory does not contain any
    # bakery.y[a]ml or passed bakery.yml file does not exist. Then
    # fontbakery-build loads default configuration.
    bakery_yml_file = None
    sourcedir = path

    if os.path.isdir(path):
        for filename in ['bakery.yml', 'bakery.yaml']:
            if os.path.exists(os.path.join(path, filename)):
                bakery_yml_file = os.path.join(path, filename)
                break
    else:
        bakery_yml_file = path
        sourcedir = os.path.dirname(path)

    try:
        if bakery_yml_file:
            config = yaml.safe_load(open(bakery_yml_file, 'r'))
        else:
            raise IOError
    except IOError:
        bakery_yml_file = os.path.join(sourcedir, 'bakery.yml')
        config = yaml.safe_load(open(BAKERY_CONFIGURATION_DEFAULTS))

    try:
        builddir = 'build'
        if GITPYTHON_INSTALLED:
            try:
                repo = Repo(sourcedir)
                builddir = repo.git.rev_parse('HEAD', short=True)
            except git.exc.InvalidGitRepositoryError:
                pass
        builddir = os.environ.get('TRAVIS_COMMIT', builddir)

        if 'process_files' not in config:
            directory = UpstreamDirectory(sourcedir)
            # normalize process_files path
            config['process_files'] = directory.get_fonts()

        create_bakery_config(bakery_yml_file, config)

        b = Bakery('', sourcedir, 'builds', builddir)
        b.addLoggingToFile()
        b.load_config(bakery_yml_file)
        b.run()

        if not ttfautohint_installed():
            msg = ('Command line tool `ttfautohint` is required. Install it with'
                   ' `apt-get install ttfautohint` or `brew install ttfautohint`')
            logger.error(msg)
    except:
        logger.error('BUILD FAILED')
        if verbose or config.get('verbose'):
            raise
        logger.error('Run with --verbose to get stacktrace info.')
        sys.exit(1)