1.1 --- a/XSLForms/Prepare.py Sun Oct 02 01:20:06 2005 +0000
1.2 +++ b/XSLForms/Prepare.py Sun Oct 02 01:33:47 2005 +0000
1.3 @@ -77,17 +77,30 @@
1.4
1.5 make_stylesheet_fragment(template_name, output_name, element_id)
1.6
1.7 -def make_input_stylesheet(template_name, output_name, stylesheet_names=["PrepareMacro.xsl", "Schema.xsl", "Input.xsl"], encoding=None):
1.8 +def make_input_stylesheet(template_name, input_name, stylesheet_names=["PrepareMacro.xsl", "Schema.xsl", "Input.xsl"], encoding=None):
1.9
1.10 """
1.11 Make an input stylesheet using the file with the given 'template_name',
1.12 - producing a file with the given 'output_name'. Such stylesheets are used to
1.13 + producing a file with the given 'input_name'. Such stylesheets are used to
1.14 ensure the general structure of an input document.
1.15 """
1.16
1.17 stylesheets = [os.path.join(resource_dir, stylesheet_name) for stylesheet_name in stylesheet_names]
1.18 proc = XSLOutput.Processor(stylesheets)
1.19 template = libxml2dom.parse(template_name)
1.20 - proc.send_output(open(output_name, "wb"), encoding, template)
1.21 + proc.send_output(open(input_name, "wb"), encoding, template)
1.22 +
1.23 +def ensure_input_stylesheet(template_name, input_name):
1.24 +
1.25 + """
1.26 + Ensure the presence of an input stylesheet, preparing it if necessary
1.27 + using the file with the given 'template_name', producing a file with the
1.28 + given 'input_name'.
1.29 + """
1.30 +
1.31 + if not os.path.exists(input_name) or \
1.32 + os.path.getmtime(input_name) < os.path.getmtime(template_name):
1.33 +
1.34 + make_input_stylesheet(template_name, input_name)
1.35
1.36 # vim: tabstop=4 expandtab shiftwidth=4