# HG changeset patch # User paulb # Date 1128216827 0 # Node ID b3d790a895e323119398ee1940b7566a2c1c86d2 # Parent b8d6f347575f2c6f099108c74d612294c04316e5 [project @ 2005-10-02 01:33:47 by paulb] Changed some parameter names in Prepare, adding an ensure_input_stylesheet function. Added a prepare_initialiser method to the WebStack resource, along with an init_resources standard attribute. diff -r b8d6f347575f -r b3d790a895e3 XSLForms/Prepare.py --- a/XSLForms/Prepare.py Sun Oct 02 01:20:06 2005 +0000 +++ b/XSLForms/Prepare.py Sun Oct 02 01:33:47 2005 +0000 @@ -77,17 +77,30 @@ make_stylesheet_fragment(template_name, output_name, element_id) -def make_input_stylesheet(template_name, output_name, stylesheet_names=["PrepareMacro.xsl", "Schema.xsl", "Input.xsl"], encoding=None): +def make_input_stylesheet(template_name, input_name, stylesheet_names=["PrepareMacro.xsl", "Schema.xsl", "Input.xsl"], encoding=None): """ Make an input stylesheet using the file with the given 'template_name', - producing a file with the given 'output_name'. Such stylesheets are used to + producing a file with the given 'input_name'. Such stylesheets are used to ensure the general structure of an input document. """ stylesheets = [os.path.join(resource_dir, stylesheet_name) for stylesheet_name in stylesheet_names] proc = XSLOutput.Processor(stylesheets) template = libxml2dom.parse(template_name) - proc.send_output(open(output_name, "wb"), encoding, template) + proc.send_output(open(input_name, "wb"), encoding, template) + +def ensure_input_stylesheet(template_name, input_name): + + """ + Ensure the presence of an input stylesheet, preparing it if necessary + using the file with the given 'template_name', producing a file with the + given 'input_name'. + """ + + if not os.path.exists(input_name) or \ + os.path.getmtime(input_name) < os.path.getmtime(template_name): + + make_input_stylesheet(template_name, input_name) # vim: tabstop=4 expandtab shiftwidth=4 diff -r b8d6f347575f -r b3d790a895e3 XSLForms/Resources.py --- a/XSLForms/Resources.py Sun Oct 02 01:20:06 2005 +0000 +++ b/XSLForms/Resources.py Sun Oct 02 01:33:47 2005 +0000 @@ -47,6 +47,12 @@ mark a region of those documents as the fragment to be updated upon "in-page" requests + * init_resources - a dictionary mapping initialiser/input + identifiers to (template_filename, + input_filename) tuples, indicating the template + and initialiser/input stylesheet filenames to be + employed + * transform_resources - a dictionary mapping transform identifiers to lists of stylesheet filenames for use with the transformation methods @@ -162,6 +168,22 @@ proc = XSLOutput.Processor(stylesheet_filenames, parameters=stylesheet_parameters, references=references) return proc.get_result(document) + def prepare_initialiser(self, input_identifier): + + """ + Prepare an initialiser/input transformation using the given + 'input_identifier'. + + Return the full path to the input stylesheet for use with 'send_output' + or 'get_result'. + """ + + template_filename, input_filename = self.init_resources[input_identifier] + input_path = os.path.abspath(os.path.join(self.resource_dir, input_filename)) + template_path = os.path.abspath(os.path.join(self.resource_dir, template_filename)) + XSLForms.Prepare.ensure_input_stylesheet(template_path, input_path) + return input_path + def prepare_transform(self, transform_identifier): """