def run(self, pipedata): if not pipedata.get('ttfautohint', '') or not ttfautohint_installed(): return False from bakery_cli.utils import ProcessedFile filepath = ProcessedFile() self.bakery.logging_raw( '### Autohint TTFs (ttfautohint) {}\n'.format(filepath)) params = pipedata['ttfautohint'] filepath = op.join(self.project_root, self.builddir, filepath) cmd = ("ttfautohint {params} {name}" " '{name}.fix'").format(params=params.strip(), name=filepath) try: run(cmd, cwd=self.builddir) except: return False if 'autohinting_sizes' not in pipedata: pipedata['autohinting_sizes'] = [] origsize = op.getsize(filepath) autohintsize = op.getsize(filepath + '.fix') pipedata['autohinting_sizes'].append({ 'fontname': op.basename(filepath), 'origin': origsize, 'processed': autohintsize }) # compare filesizes TODO print analysis of this :) comment = "# look at the size savings of that subset process" run("ls -la {0} {0}.fix | awk '{{ print $5 \"\t\" $9 }}'".format( filepath)) comment = "# copy back optimized ttf to original filename" self.bakery.logging_cmd(comment) shutil.move(filepath + '.fix', filepath) return 1
def run(self, pipedata): if not pipedata.get('ttfautohint', '') or not ttfautohint_installed(): return False from bakery_cli.utils import ProcessedFile filepath = ProcessedFile() self.bakery.logging_raw('### Autohint TTFs (ttfautohint) {}\n'.format(filepath)) params = pipedata['ttfautohint'] filepath = op.join(self.project_root, self.builddir, filepath) cmd = ("ttfautohint {params} {name}" " '{name}.fix'").format(params=params.strip(), name=filepath) try: run(cmd, cwd=self.builddir) except: return False if 'autohinting_sizes' not in pipedata: pipedata['autohinting_sizes'] = [] origsize = op.getsize(filepath) autohintsize = op.getsize(filepath + '.fix') pipedata['autohinting_sizes'].append({ 'fontname': op.basename(filepath), 'origin': origsize, 'processed': autohintsize }) # compare filesizes TODO print analysis of this :) comment = "# look at the size savings of that subset process" run("ls -la {0} {0}.fix | awk '{{ print $5 \"\t\" $9 }}'".format(filepath)) comment = "# copy back optimized ttf to original filename" self.bakery.logging_cmd(comment) shutil.move(filepath + '.fix', filepath) return 1
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)
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)