From: <pau...@us...> - 2011-01-10 04:02:50
|
Author: paultremblay Date: 2011-01-10 05:02:42 +0100 (Mon, 10 Jan 2011) New Revision: 6532 Modified: trunk/sandbox/paultremblay/scripts/docutils_to_fo.py Log: Code added for reading in a config file (produced during an email exchange!) Modified: trunk/sandbox/paultremblay/scripts/docutils_to_fo.py =================================================================== --- trunk/sandbox/paultremblay/scripts/docutils_to_fo.py 2011-01-10 02:18:56 UTC (rev 6531) +++ trunk/sandbox/paultremblay/scripts/docutils_to_fo.py 2011-01-10 04:02:42 UTC (rev 6532) @@ -173,3 +173,46 @@ convert_obj.print_result(out_doc) main() +# Here is new code to read the configuration file. +import sys +import ConfigParser +stylesheet = '/Library/svn/trunk/sandbox/paultremblay/xsl_fo/docutils_to_fo.xsl' +config = ConfigParser.RawConfigParser() +config.read('config.txt') +opts = config.items('FO') + + +def make_attribute_set(the_name, the_dict): + sys.stdout.write('<xsl:attribute-set name="%s">\n' % (the_name)) + the_keys = the_dict.keys() + the_keys.sort() + for the_key in the_keys: + sys.stdout.write(' <xsl:attribute name="%s">' % (the_key)) + sys.stdout.write(the_dict[the_key]) + sys.stdout.write('</xsl:attribute>\n') + sys.stdout.write('</xsl:attribute-set>\n\n') +sys.stdout.write(""" +<xsl:stylesheet + xmlns:xsl="http://www.w3.org/1999/XSL/Transform" + xmlns:fo="http://www.w3.org/1999/XSL/Format" + version="1.1" + > + <xsl:import href="%s"/> + """ % (stylesheet)) + +opts_dict = {} +for pair_tupple in opts: + first = pair_tupple[0] + second = pair_tupple[1] + the_class, att = first.split('.') + class_exists = opts_dict.get(the_class) + if not class_exists: + opts_dict[the_class] = {} + opts_dict[the_class][att] = second + +the_keys = opts_dict.keys() +the_keys.sort() +for the_key in the_keys: + make_attribute_set(the_key, opts_dict[the_key]) + +sys.stdout.write('\n</xsl:stylesheet>') |