#!/usr/bin/env python from __future__ import print_function import sys from string import Template import argparse OPTIONS = ( (('-P', '--properties-file'), dict(help='specify a properties file for use as variables ' 'in html wrapper')), ) def main(sysargs=sys.argv[:]): parser = get_option_parser() opts = parser.parse_args(sysargs[1:]) tmpl_vars = dict(VARS) if opts.properties_file: _update_from_properties(tmpl_vars, opts.properties_file) print(TEMPLATE.substitute(**tmpl_vars)) return 0 def get_option_parser(): parser = argparse.ArgumentParser() for args, kwargs in OPTIONS: parser.add_argument(*args, **kwargs) return parser def _update_from_properties(tmpl_vars, properties_file): defines = _get_defines_from_properties_file(properties_file) tmpl_vars.update(defines) def _get_defines_from_properties_file(properties_file): ret = {} with open(properties_file) as opened: for line in opened: line = line.strip() if line.startswith('#'): continue if '=' in line: key, value = line.split('=', 1) ret[key] = value return ret VARS = ( ('title', ''), ('bgcolor', ''), ('application', ''), ('swf', ''), ('width', ''), ('height', ''), ) TEMPLATE = Template("""