You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
box-o-sand/flash_html_wrap.py

117 lines
2.8 KiB

#!/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("""
<!DOCTYPE html>
<html>
<head>
<title>${title}</title>
<style type="text/css" media="screen">
/*<![CDATA[*/
html, body { height:100%; }
body {
margin:0;
padding:0;
overflow:auto;
text-align:center;
background-color: ${bgcolor};
}
#flashContent {
display:none;
}
*/]]>*/
</style>
</head>
<body>
<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
width="${width}" height="${height}" id="${application}">
<param name="movie" value="${swf}.swf" />
<param name="quality" value="high" />
<param name="bgcolor" value="${bgcolor}" />
<param name="allowScriptAccess" value="sameDomain" />
<param name="allowFullScreen" value="true" />
<!--[if !IE]>-->
<object type="application/x-shockwave-flash" data="${swf}.swf"
width="${width}" height="${height}">
<param name="quality" value="high" />
<param name="bgcolor" value="${bgcolor}" />
<param name="allowScriptAccess" value="sameDomain" />
<param name="allowFullScreen" value="true" />
<!--<![endif]-->
<!--[if !IE]>-->
</object>
<!--<![endif]-->
</object>
</body>
</html>
""")
if __name__ == '__main__':
sys.exit(main())
# vim:filetype=python