# HG changeset patch # User paulb # Date 1130189649 0 # Node ID 89619b21b8b48a65cf0526832f0de2f34ffba189 # Parent 7b20e53fed9db980f3d2b4b3b3024703d6c83047 [project @ 2005-10-24 21:34:09 by paulb] Reorganised the existing functions and added some new functions to prepare Qt Designer form fragments, Web templates and output stylesheets. diff -r 7b20e53fed9d -r 89619b21b8b4 XSLForms/Prepare.py --- a/XSLForms/Prepare.py Mon Oct 24 18:17:02 2005 +0000 +++ b/XSLForms/Prepare.py Mon Oct 24 21:34:09 2005 +0000 @@ -26,6 +26,14 @@ resource_dir = os.path.join(os.path.split(__file__)[0], "XSL") +# Generic functions. + +def _ensure_stylesheet(template_name, output_name, fn, *args, **kw): + if not os.path.exists(output_name) or \ + os.path.getmtime(output_name) < os.path.getmtime(template_name): + + fn(template_name, output_name, *args, **kw) + # Web template functions. def make_stylesheet(template_name, output_name, stylesheet_names=["PrepareMacro.xsl", "Prepare.xsl"], encoding=None): @@ -60,10 +68,7 @@ given 'output_name'. """ - if not os.path.exists(output_name) or \ - os.path.getmtime(output_name) < os.path.getmtime(template_name): - - make_stylesheet(template_name, output_name) + _ensure_stylesheet(template_name, output_name, make_stylesheet) def ensure_stylesheet_fragment(template_name, output_name, element_id): @@ -74,10 +79,7 @@ 'element_id'. """ - if not os.path.exists(output_name) or \ - os.path.getmtime(output_name) < os.path.getmtime(template_name): - - make_stylesheet_fragment(template_name, output_name, element_id) + _ensure_stylesheet(template_name, output_name, make_stylesheet_fragment, element_id) # Document initialisation functions. @@ -102,10 +104,7 @@ 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) + _ensure_stylesheet(template_name, input_name, make_input_stylesheet) # Qt Designer functions. @@ -115,9 +114,20 @@ proc.send_output(open(output_name, "wb"), encoding, template) def ensure_qt_fragment(template_name, output_name, widget_name): - if not os.path.exists(output_name) or \ - os.path.getmtime(output_name) < os.path.getmtime(template_name): + _ensure_stylesheet(template_name, output_name, make_qt_fragment, widget_name) + +# Qt Designer Web functions. + +def make_qt_template(template_name, output_name, stylesheet_names=["QtDesigner.xsl"], encoding=None): + return make_stylesheet(template_name, output_name, stylesheet_names, encoding) - make_qt_fragment(template_name, output_name, widget_name) +def ensure_qt_template(template_name, output_name): + _ensure_stylesheet(template_name, output_name, make_qt_template) + +def make_qt_stylesheet(template_name, output_name, stylesheet_names=["QtDesigner.xsl", "PrepareMacro.xsl", "Prepare.xsl"], encoding=None): + return make_stylesheet(template_name, output_name, stylesheet_names, encoding) + +def ensure_qt_stylesheet(template_name, output_name): + _ensure_stylesheet(template_name, output_name, make_qt_stylesheet) # vim: tabstop=4 expandtab shiftwidth=4