1.1 --- a/XSLForms/Resources/WebResources.py Fri Oct 05 23:44:25 2007 +0000
1.2 +++ b/XSLForms/Resources/WebResources.py Sat Nov 17 20:09:20 2007 +0000
1.3 @@ -359,4 +359,53 @@
1.4 for input_identifier in cls.init_resources.keys():
1.5 prepare_initialiser(cls, input_identifier, 1)
1.6
1.7 +# Convenience methods for specifying resources.
1.8 +
1.9 +def split(filename):
1.10 +
1.11 + """
1.12 + Return a tuple containing the directory and filename without extension for
1.13 + 'filename'.
1.14 + """
1.15 +
1.16 + d, leafname = os.path.split(filename)
1.17 + name, ext = os.path.splitext(leafname)
1.18 + return d, name
1.19 +
1.20 +def output(template_filename):
1.21 +
1.22 + """
1.23 + Return a tuple containing the 'template_filename' and a suitable output
1.24 + stylesheet filename.
1.25 + """
1.26 +
1.27 + d, name = split(template_filename)
1.28 + output_name = name.replace("_template", "_output") + os.path.extsep + "xsl"
1.29 + return (template_filename, os.path.join(d, output_name))
1.30 +
1.31 +def input(template_filename):
1.32 +
1.33 + """
1.34 + Return a tuple containing the 'template_filename' and a suitable output
1.35 + stylesheet filename.
1.36 + """
1.37 +
1.38 + d, name = split(template_filename)
1.39 + input_name = name.replace("_template", "_input") + os.path.extsep + "xsl"
1.40 + return (template_filename, os.path.join(d, input_name))
1.41 +
1.42 +def resources(filename, d="Resources"):
1.43 +
1.44 + """
1.45 + Return the resource directory for the given 'filename', using the optional
1.46 + directory name 'd' to indicate the directory relative to the directory of
1.47 + 'filename' (or the default directory name, indicating that the directory
1.48 + called "Resources" - a sibling of 'filename' - is the resource directory).
1.49 +
1.50 + It is envisaged that callers provide the value of the __file__ special
1.51 + variable to get the resource directory relative to a particular module.
1.52 + """
1.53 +
1.54 + return os.path.join(os.path.split(filename)[0], d)
1.55 +
1.56 # vim: tabstop=4 expandtab shiftwidth=4