From 365cb8f87f11bc60067a61ba928ead2ac3277552 Mon Sep 17 00:00:00 2001 From: Dan Buch Date: Mon, 19 Apr 2010 19:04:46 -0400 Subject: [PATCH] first pass at html wrapper generator script --- Makefile | 1 + bin/flashhtml.py | 969 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 970 insertions(+) create mode 100755 bin/flashhtml.py diff --git a/Makefile b/Makefile index 5cc86b9..df319c3 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,5 @@ FLIXEL := $(PWD)/flixel +WRAP := $(PWD)/bin/flashhtml.py TOP := $(PWD) MXMLC := mxmlc diff --git a/bin/flashhtml.py b/bin/flashhtml.py new file mode 100755 index 0000000..03e06d4 --- /dev/null +++ b/bin/flashhtml.py @@ -0,0 +1,969 @@ +#!/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', ''), + ('useBrowserHistory', ''), + ('version_major', 0), + ('version_minor', 0), + ('version_revision', 0), + ('expressInstallSwf', ''), + ('application', ''), + ('swf', ''), + ('width', ''), + ('height', ''), +) +TEMPLATE = Template(""" + + + + + ${title} + + + + + + + + + + + +
+

+ To view this page ensure that Adobe Flash Player version + ${version_major}.${version_minor}.${version_revision} or greater is installed. +

+ +
+ + + + +""") + +if __name__ == '__main__': + sys.exit(main()) + +# vim:filetype=python