diff options
author | wiemann <wiemann@929543f6-e4f2-0310-98a6-ba3bd3dd1d04> | 2006-01-09 20:44:25 +0000 |
---|---|---|
committer | wiemann <wiemann@929543f6-e4f2-0310-98a6-ba3bd3dd1d04> | 2006-01-09 20:44:25 +0000 |
commit | d77fdfef70e08114f57cbef5d91707df8717ea9f (patch) | |
tree | 49444e3486c0c333cb7b33dfa721296c08ee4ece /sandbox/paultremblay | |
parent | 53cd16ca6ca5f638cbe5956988e88f9339e355cf (diff) | |
parent | 3993c4097756e9885bcfbd07cb1cc1e4e95e50e4 (diff) | |
download | docutils-0.4.tar.gz |
Release 0.4: tagging released revisiondocutils-0.4
git-svn-id: http://svn.code.sf.net/p/docutils/code/tags/docutils-0.4@4268 929543f6-e4f2-0310-98a6-ba3bd3dd1d04
Diffstat (limited to 'sandbox/paultremblay')
39 files changed, 0 insertions, 5261 deletions
diff --git a/sandbox/paultremblay/README.txt b/sandbox/paultremblay/README.txt deleted file mode 100644 index 4fde07092..000000000 --- a/sandbox/paultremblay/README.txt +++ /dev/null @@ -1,36 +0,0 @@ -============================ - README: Docutils Extensions -============================ - -:Author: Paul Tremblay - -:Contact: phthenry@earthlink.net - -:Date: $Date$ - -:Web site: http://docutils.sourceforge.net/ - - - -======== -Overview -======== - -This directory contains a number of modules that add functionality to -docutils. - -1. The package docutils_nest adds functionality to docutils. XML authors - and developers might find it useful. Others will not find it useful. - - As its name implies, docutils_nest allows users to add nested inline - structure to a rst document. - - See the README.txt in /docutils_nest. - -2. rst_to_docbook - - This script has not been written. It will convert rst to docbook, - using xml tools such as xslt. - - - diff --git a/sandbox/paultremblay/docutils_nest/README.txt b/sandbox/paultremblay/docutils_nest/README.txt deleted file mode 100644 index 9908f8bb5..000000000 --- a/sandbox/paultremblay/docutils_nest/README.txt +++ /dev/null @@ -1,238 +0,0 @@ -.. WARNING TO PAUL: DON'T EDIT THIS FILE - -README: |scriptName| -^^^^^^^^^^^^^^^^^^^^^ -:Author: Paul Tremblay - -:Contact: phthenry@earthlink.net - -:Date: $Date$ - -:Web site: http://docutils.sourceforge.net/ - -.. contents:: - -.. |scriptName| replace:: docultils-nest-xml.py - -.. |moduleName| replace:: docutils_nest - -======== -Overview -======== - -The script |scriptName| extends the power of docultils by allowing XML authors -and developers to include nested inline markup in their documents. While -docutils allows for infinite nesting on the block level, it limits inline -markup to one level. The script |scriptName| elminates this shortcomming. An -XML author could write a document in rst format, and then with |scriptName| -translate it to robust XML, which he could then further transform to docbook -or any other form of XML he desired. Any type of XML markup is possible using -|script_name|. - -In addition to allowing for nested markup, |scriptName| allows you to choose -any type of inline markup you wish. - -Because users of docutils expressed differences as to how they wanted to mark -inline text, |scriptName| allows you to customize the markup. - -Quick Example -============= - -You wantd to include a comment with emphasized text in your final XML -document. You type:: - - [:comment: Maybe I should include *The Sun Also Rises?*] - - -You then issue the command: - -|scriptName| --output my_document.rst - -The output is:: - - <inline arg1 = "comment">Maye I should include <emphasis>The Sun Also - Rises?</emphasis></inline> - - -Installation -============ - -1. Install python. (http://www.python.org) - -2. Install the docutils package. (http://docutils.sourceforge.net/) - -3. Install the PyXml package. (http://pyxml.sourceforge.net/) - -4. Install the |moduleName|. You will need to have cvs installed on -your machine. - - 1. Open a shell. Type - - :: - - cvs -d:pserver:anonymous@cvs.sourceforge.net:/cvsroot/docutils login - - When asked for a password, simpy hit return. - - - 2. Download the |moduleName|. Type - - :: - - cvs -z3 - -d:pserver:anonymous@cvs.sourceforge.net:/cvsroot/docutils co - sandbox/paultremblay - - This command will download the directory sandbox/paultremblay to your - current directory. Change to the directory /sandbox/paultremblay. - - 3. Run the configuration script to set the path and location of the configuration file. - - :: - - python configure.py target = <desired location of configuration file> - - If no target is provided (or you choose not to run the configuration file), - the configuration file will be placed in /etc/|moduleName|. - - - 4. Install the modules in the usual way: - - python setup.py build - - python setup.py install - - -Use -=== - -|scriptName| ``--output <outfile> file.rst`` - -You *must* specify an output option. - -In addition, you can specify any options you would if running docutils-xml.py: - -|scriptName| --indents --quiet --output otupt.xml file.rst - - -How to markup your document -=========================== - -By default, the nested_inline module uses the following structure to markup text:: - - [:some-tag test example: text [:nested: more text [text with brackets]]] - -This markup gets converted to:: - - <inline arg1 = "some-tag" arg2 = "test" arg3 = "example">text <inline arg1 = - "nested" more text [text with brackets]</inline></inline> - -You begin inline markup with an opening bracket followed by a colon, with no - space. You then fill in the arguments by typing in words after the colon. A - colon marks the end of the beginning tag and begins the text. A closing - bracket marks the end of the inline text. - -Note that you can nest your markup to as many levels as you wish. You can also -use brackets just as you norally would and not worry that nest_inline will -confuse regular brackets with text meant to be treated as markup. However, the -brackets must be matched. Consider this markup: - -[:math-formula-containing-closing-bracket: 2x ] ] - -You might mean for the first closing bracket to be part of the formula, but -the nested_inline module will think it marks the end of your inline text. The -script will produce this output:: - - <inline arg1 = "math-forumla-containing-closing-bracket">2x</inline><problematic - description = "solitary closing bracket my produce output you don't want"/>] - -In order to overcome this problem, escape the first closing bracket -with literal markup:: - - [:math-forumula-containing-closing-bracket: 2x ``]`` ] - -Errors -====== - -The module nested_inline will not produce invalid XML. If you write a file -that has the potential to result in ill-formed XML, nested_inline produces an -error message, along with an error tag. Consider the following document:: - - - .. If the script converted the brackets to tag, you would get - - .. <emphasis><inline arg1 = "markup">text</emphasis></inline> - - *[:markup: text*] - -The result is:: - - <emphasis><problematic descrition = "tagging text would result in ill-formed XML"/>[:markup: text</emphasis>] - -Customizing Markup -================== - -The nested_inline module reads from a customization file in order to determine how inline text is marked up. Change this document in order to change how you want to markup your text. - -The configuration file takes 6 values: - -- start-role: the way to mark the start of a role. The default is ":". - -- end-role: the way to mark the end of a role. The default is ":". - -- start-group: the way to mark the start of a group. The default is "[". - -- end-group: the way to mark the end of a group. The default is "]". - -- tag-name: the name of the inline tag. The default is "inline". - -- warning: the name of the warning messge for errors. The default is "problematic". - -Let's say you wanted to markup your text using parenethesis rather than brackets, and that you wanted your role to go outside of the parenthesis. You want your tag name to be "inline-tag", and your warning to be "warning." Your configuration file would look like this:: - - - <configure> - <start-role string = ':'/> - <end-role string = ':'/> - <start-group string = '('/> - <end-group string = ')'/> - <place-of-role place = 'outside'/> - <tag-name name = 'inline-tag'/> - <warning name = 'warning'/> - </configure> - -You would then markup your text as:: - - :comment:(This is a comment with *italics*) - -The output would be:: - - <inline-tag arg1 = "comment">This is a comment with <emhasis>italics</emphasis></inline-tag> - -Project Files & Directories -=========================== - -* README.txt: You're reading it. - -*|moduleName|: Contains all the modules for the script to run - -*doc: The documentation for the module, including a copy of this -README.txt. - -*scripts: the script |scriptName|. - -*test_files: Files to test the script. - - -Getting Help -============ - -Contact me. - -.. - Local Variables: - mode: indented-text - indent-tabs-mode: nil - sentence-end-double-space: t - fill-column: 70 - End: diff --git a/sandbox/paultremblay/docutils_nest/configure.py b/sandbox/paultremblay/docutils_nest/configure.py deleted file mode 100644 index baa44d3c1..000000000 --- a/sandbox/paultremblay/docutils_nest/configure.py +++ /dev/null @@ -1,146 +0,0 @@ - -# /usr/bin/env python - -import sys, os -import docutils_nest.options_trem - -""" - -The configuration script gets the target from the command line. It creates a file with the configuration variable, and a short script for the rest of script to be able to read and locate he configuration files. - -""" - -def configure(): - target = get_target() - make_var_file(target) - make_location(target) - -def get_target(): - """ - This functions uses a module I wrote to parse options. If no options are - determined on the command line, the function returnst the default - /etc/nest_docutis - - """ - options_dict = { - 'target': [1, 't'], - } - options_obj = docutils_nest.options_trem.ParseOptions(sys.argv, - options_dict) - opt_dict, args = options_obj.parse_options() - if opt_dict == 0: - sys.stderr.write('invalid way to run configure:\n' - 'python configure.py --target <directory of choice>' - ) - sys.exit(1) - target = opt_dict.get('target') - if not target: - target = default_target() - return target - -def default_target(): - sys.stdout.write('using default /etc for configuration directory\n') - return '/etc' - -def make_var_file(target): - write_obj = open('var_file', 'w') - # write_obj.write('[global]\n') - write_obj.write(target) - write_obj.close() - -def make_location(target): - write_obj = open('docutils_nest/location.py', 'w') - write_obj.write( - """ -def get_location(): - return '%s' - - - """ - % target) - - -if __name__ == '__main__': - configure() - - - - - -""" -# /usr/bin/env python - -import sys, os -import options_trem - - -def configure(): - target = get_target() - change_setup(target) - change_script(target) - -def get_target(): - options_dict = { - 'target': [1, 't'], - } - options_obj = options_trem.ParseOptions(sys.argv, - options_dict) - opt_dict, args = options_obj.parse_options() - if opt_dict == 0: - sys.stdout.write('Will use the default configuration of /etc/nest_docutils\n') - return '/etc/docutils_nest' - target = opt_dict.get('target') - if not target: - return '/etc/docutils_nest' - return target - -def change_setup(target): - read_obj = open('setup.py', 'r') - write_obj = open('temp', 'w') - line = 1 - while line: - line = read_obj.readline() - index = line.find('data_files=') - if index > -1: - write_obj.write('data_files = [("%s", ["data/configure.xml"])],\n' % target) - else: - write_obj.write(line) - read_obj.close() - write_obj.close() - read_obj = open('temp', 'r') - write_obj = open('setup.py', 'w') - line = 1 - while line: - line = read_obj.readline() - write_obj.write(line) - read_obj.close() - write_obj.close() - - -def change_script(target): - - read_obj = open('docutils_nest/nest_docutils.py', 'r') - write_obj = open('temp', 'w') - line = 1 - while line: - line = read_obj.readline() - index = line.find('$configure$') - if index > -1: - write_obj.write("ext_location = '%s' # $configure$" % \ - target) - else: - write_obj.write(line) - read_obj.close() - write_obj.close() - read_obj = open('temp', 'r') - write_obj = open('docutils_nest/nest_docutils.py', 'w') - line = 1 - while line: - line = read_obj.readline() - write_obj.write(line) - read_obj.close() - write_obj.close() - -if __name__ == '__main__': - configure() -""" diff --git a/sandbox/paultremblay/docutils_nest/data/configure.xml b/sandbox/paultremblay/docutils_nest/data/configure.xml deleted file mode 100644 index 9d60fd139..000000000 --- a/sandbox/paultremblay/docutils_nest/data/configure.xml +++ /dev/null @@ -1,9 +0,0 @@ -<configure> - <start-role string = ':'/> - <end-role string = ':'/> - <start-group string = '['/> - <end-group string = ']'/> - <place-of-role place = 'inside'/> - <tag-name name = 'inline'/> - <warning name = 'problematic'/> -</configure> diff --git a/sandbox/paultremblay/docutils_nest/doc/README.txt b/sandbox/paultremblay/docutils_nest/doc/README.txt deleted file mode 100644 index 6d62f8764..000000000 --- a/sandbox/paultremblay/docutils_nest/doc/README.txt +++ /dev/null @@ -1,236 +0,0 @@ -README: |scriptName| -^^^^^^^^^^^^^^^^^^^^^ -:Author: Paul Tremblay - -:Contact: phthenry@earthlink.net - -:Date: $Date$ - -:Web site: http://docutils.sourceforge.net/ - -.. contents:: - -.. |scriptName| replace:: docultils-nest-xml.py - -.. |moduleName| replace:: docutils_nest - -======== -Overview -======== - -The script |scriptName| extends the power of docultils by allowing XML authors -and developers to include nested inline markup in their documents. While -docutils allows for infinite nesting on the block level, it limits inline -markup to one level. The script |scriptName| elminates this shortcomming. An -XML author could write a document in rst format, and then with |scriptName| -translate it to robust XML, which he could then further transform to docbook -or any other form of XML he desired. Any type of XML markup is possible using -|script_name|. - -In addition to allowing for nested markup, |scriptName| allows you to choose -any type of inline markup you wish. - -Because users of docutils expressed differences as to how they wanted to mark -inline text, |scriptName| allows you to customize the markup. - -Quick Example -============= - -You wantd to include a comment with emphasized text in your final XML -document. You type:: - - [:comment: Maybe I should include *The Sun Also Rises?*] - - -You then issue the command: - -|scriptName| --output my_document.rst - -The output is:: - - <inline arg1 = "comment">Maye I should include <emphasis>The Sun Also - Rises?</emphasis></inline> - - -Installation -============ - -1. Install python. (http://www.python.org) - -2. Install the docutils package. (http://docutils.sourceforge.net/) - -3. Install the PyXml package. (http://pyxml.sourceforge.net/) - -4. Install the |moduleName|. You will need to have cvs installed on -your machine. - - 1. Open a shell. Type - - :: - - cvs -d:pserver:anonymous@cvs.sourceforge.net:/cvsroot/docutils login - - When asked for a password, simpy hit return. - - - 2. Download the |moduleName|. Type - - :: - - cvs -z3 - -d:pserver:anonymous@cvs.sourceforge.net:/cvsroot/docutils co - sandbox/paultremblay - - This command will download the directory sandbox/paultremblay to your - current directory. Change to the directory /sandbox/paultremblay. - - 3. Run the configuration script to set the path and location of the configuration file. - - :: - - python configure.py target = <desired location of configuration file> - - If no target is provided (or you choose not to run the configuration file), - the configuration file will be placed in /etc/|moduleName|. - - - 4. Install the modules in the usual way: - - python setup.py build - - python setup.py install - - -Use -=== - -|scriptName| ``--output <outfile> file.rst`` - -You *must* specify an output option. - -In addition, you can specify any options you would if running docutils-xml.py: - -|scriptName| --indents --quiet --output otupt.xml file.rst - - -How to markup your document -=========================== - -By default, the nested_inline module uses the following structure to markup text:: - - [:some-tag test example: text [:nested: more text [text with brackets]]] - -This markup gets converted to:: - - <inline arg1 = "some-tag" arg2 = "test" arg3 = "example">text <inline arg1 = - "nested" more text [text with brackets]</inline></inline> - -You begin inline markup with an opening bracket followed by a colon, with no - space. You then fill in the arguments by typing in words after the colon. A - colon marks the end of the beginning tag and begins the text. A closing - bracket marks the end of the inline text. - -Note that you can nest your markup to as many levels as you wish. You can also -use brackets just as you norally would and not worry that nest_inline will -confuse regular brackets with text meant to be treated as markup. However, the -brackets must be matched. Consider this markup: - -[:math-formula-containing-closing-bracket: 2x ] ] - -You might mean for the first closing bracket to be part of the formula, but -the nested_inline module will think it marks the end of your inline text. The -script will produce this output:: - - <inline arg1 = "math-forumla-containing-closing-bracket">2x</inline><problematic - description = "solitary closing bracket my produce output you don't want"/>] - -In order to overcome this problem, escape the first closing bracket -with literal markup:: - - [:math-forumula-containing-closing-bracket: 2x ``]`` ] - -Errors -====== - -The module nested_inline will not produce invalid XML. If you write a file -that has the potential to result in ill-formed XML, nested_inline produces an -error message, along with an error tag. Consider the following document:: - - - .. If the script converted the brackets to tag, you would get - - .. <emphasis><inline arg1 = "markup">text</emphasis></inline> - - *[:markup: text*] - -The result is:: - - <emphasis><problematic descrition = "tagging text would result in ill-formed XML"/>[:markup: text</emphasis>] - -Customizing Markup -================== - -The nested_inline module reads from a customization file in order to determine how inline text is marked up. Change this document in order to change how you want to markup your text. - -The configuration file takes 6 values: - -- start-role: the way to mark the start of a role. The default is ":". - -- end-role: the way to mark the end of a role. The default is ":". - -- start-group: the way to mark the start of a group. The default is "[". - -- end-group: the way to mark the end of a group. The default is "]". - -- tag-name: the name of the inline tag. The default is "inline". - -- warning: the name of the warning messge for errors. The default is "problematic". - -Let's say you wanted to markup your text using parenethesis rather than brackets, and that you wanted your role to go outside of the parenthesis. You want your tag name to be "inline-tag", and your warning to be "warning." Your configuration file would look like this:: - - - <configure> - <start-role string = ':'/> - <end-role string = ':'/> - <start-group string = '('/> - <end-group string = ')'/> - <place-of-role place = 'outside'/> - <tag-name name = 'inline-tag'/> - <warning name = 'warning'/> - </configure> - -You would then markup your text as:: - - :comment:(This is a comment with *italics*) - -The output would be:: - - <inline-tag arg1 = "comment">This is a comment with <emhasis>italics</emphasis></inline-tag> - -Project Files & Directories -=========================== - -* README.txt: You're reading it. - -*|moduleName|: Contains all the modules for the script to run - -*doc: The documentation for the module, including a copy of this -README.txt. - -*scripts: the script |scriptName|. - -*test_files: Files to test the script. - - -Getting Help -============ - -Contact me. - -.. - Local Variables: - mode: indented-text - indent-tabs-mode: nil - sentence-end-double-space: t - fill-column: 70 - End: diff --git a/sandbox/paultremblay/docutils_nest/docutils_nest/__init__.py b/sandbox/paultremblay/docutils_nest/docutils_nest/__init__.py deleted file mode 100644 index b3d0c915b..000000000 --- a/sandbox/paultremblay/docutils_nest/docutils_nest/__init__.py +++ /dev/null @@ -1,3 +0,0 @@ -''' -modules for rtf2xml -''' diff --git a/sandbox/paultremblay/docutils_nest/docutils_nest/inline_to_xml.py b/sandbox/paultremblay/docutils_nest/docutils_nest/inline_to_xml.py deleted file mode 100644 index 316a47233..000000000 --- a/sandbox/paultremblay/docutils_nest/docutils_nest/inline_to_xml.py +++ /dev/null @@ -1,459 +0,0 @@ -import re, sys, os -import docutils_nest.well_formed_xml - -""" - - -""" - -class InlineToXML: - - """ - - """ - - - - def __init__( self, - start_role = ':', - end_role = ':', - start_group = '[', - end_group = ']', - place = 'inside', - tag_name = 'inline', - warning = 'problematic' - ): - - """ - - Required: - - nothing - - Options: - - start_role -- the text delimeter that marks the beginning of a role - - end_role -- the text delimeter that marks the end of a role - - start_group -- the text delimeter that marks the start of a group - - end_group -- the text delimiter that marks the end of a group - - place -- whether the role goes inside or outside of the group - - warning -- a string of text to describe problems - - warning_level -- will do away with this - - - """ - self.__start_role = str(start_role) - self.__end_role = str(end_role) - self.__start_group = str(start_group) - self.__end_group = str(end_group) - self.__place = str(place) - exp = self.__make_split_exp() - self.__split_exp = re.compile(exp) - exp = self.__role_exp_func() - self.__start_exp = re.compile(exp) - self.__token_list = [] - self.__reg_bracket = 0 # found regular brackets - self.__bracket_type = [] - self.__tag_name, self.__warning = self.__make_tag_names(tag_name, warning) - - def __make_tag_names(self, tag_name, warning): - tags = [tag_name, warning] - counter = 0 - for name in tags: - new_string = '' - counter += 1 - for char in name: - if not char.isalnum(): - char = '_' - new_string += char - first = new_string[:1] - is_letter = first.isalpha() - if not is_letter: - new_string = 'a' + new_string - if counter == 1: - new_tag_name = new_string - else: - new_warning = new_string - return new_tag_name, new_warning - - def __escape_value(self, value): - - """ - - Required: - - value -- a string - - Returns - - a string of escaped values - - Logic: - - Certain characters have special values in regular expressions. If - the user is using any of these special expressions, then they must - be escaped. - - - """ - special = ['[', ']', '(', ')', '{', '}', '.'] - if value in special: - value = '\\%s' % value - return value - - def __make_split_exp(self): - - """ - - Requires: - - nothing - - Returns: - - nothing - - Logic: - - Use the object values to form a regular expression that will be - used to split a string into tokens. The expression will be - different if the role is inside or outside the group. - - - """ - start_group = self.__escape_value(self.__start_group) - end_group = self.__escape_value(self.__end_group) - start_role = self.__escape_value(self.__start_role) - end_role = self.__escape_value(self.__end_role) - if self.__place == 'inside': - #\[:[^\[\]]+:\s?|\[|\] - exp = '(%s%s[^%s%s]+%s\s?|%s|%s)' % \ - (start_group, - start_role, - start_group, - end_group, - end_role, - start_group, - end_group - ) - - - else: - # :[^\[\]]+:\[|[|] - exp = '(%s[^%s%s]+%s%s|%s|%s)' %\ - (start_role, - start_group, - end_group, - end_role, - start_group, - start_group, - end_group - ) - return exp - - def __role_exp_func(self): - """ - - Requires: - - nothing - - Returns - - nothing - - Logic: - - Make a regular expression to marke the beginning of a group - - """ - start_group = self.__escape_value(self.__start_group) - end_group = self.__escape_value(self.__end_group) - start_role = self.__escape_value(self.__start_role) - end_role = self.__escape_value(self.__end_role) - if self.__place == 'inside': - exp = '%s%s(.*?)%s' % \ - (start_group, - start_role, - end_role - ) - else: - exp = '%s(.*?)%s%s' % \ - (start_role, - end_role, - start_group - ) - return exp - - - - def __well_formed_func(self, my_string): - """ - - Required: - - my_string --string to check - - Returns: - - 0 if the string can be convert to tags, and 0 otherwise - - Logic: - - Use the external module well_formed_xml to test that the tags are - balanced. If they are balanced, the module returns 1. Othewise it - returns 0 - - - """ - well_formed_obj = docutils_nest.well_formed_xml.WellFormed() - well_formed = well_formed_obj.well_formed(my_string) - return well_formed - - - - def __open_tag(self, my_string): - """ - - Requires: - - my_string --string to parse - - Returns: - - A string of arguments for an opening tag. - - Logic: - - Use a simple split expression to turn a string of values with a - space bewteen them into arguments: word1 word2 word3 => - arg1="word1" arg2="word2" arg3="word3" - - """ - arguments = my_string.split() - counter = 0 - final_string = '' - for argument in arguments: - counter += 1 - final_string += 'arg%s="%s" ' % (counter, argument) - final_string = final_string.replace(':', '') - return final_string[:-1] # chop off last space - - - - def __process_inside_group(self, inner_list): - """ - - Requires: - - inner_list -- a list of two values. The first is a string starting - and ending with a colon. :arg1 arg2: - - Returns: - - A string of tagged text. If the string can be converted to XML (or - tagged), then it is tagged: - - [':word1 word2:', 'text'] => <inline arg1="word1" - arg2="word2">text</inline> - - If the string cannot be tagged, it makes the following: - - [':word1 word2:', 'text<i>'] => <warning descrition= - description="tagging brackets will result in invalid XML' - - Logic: - - Check to see if you can tag the text and still form valid XML. If - so, tag and return the text. - - Otherwise, write an error message and return the text. - - - - """ - my_string = inner_list[1] - tag = inner_list[0] - well_formed = self.__well_formed_func(my_string) - if well_formed: - match_obj = re.match(self.__start_exp, tag) - tag = match_obj.group(1) - open_tag = self.__open_tag(tag) #[:wor1: - final_string = '<%s %s>%s</%s>' % ( - self.__tag_name, open_tag, my_string, self.__tag_name) - return final_string - else: - final_string = '<%s description="tagging brackets will result ' % (self.__warning, - ) - final_string += 'in invalid XML"/>' - final_string += tag + my_string + ']' - warning = ( - 'WARNING: tagging brackets will result in invalid XML:' - '%s%s' % (tag, my_string) - ) - sys.stderr.write(repr(warning)) - sys.stderr.write('\n') - return final_string - - def __start_role_func(self, token): - """ - Requires: - - token -- the token to check - - Returns: - - A string if a start expession is found; 0 otherwise - - """ - - match_obj = re.match(self.__start_exp, token) - - if match_obj: - return match_obj.group(1) - return 0 - - def __tag(self, tokens): - """ - - Requires: - - tokens -- a list of tokens - - Returns: - - A string --A string of tagged text - - Logic: - - Read one token at a time. - - If the token is text, add it to the final string. 'Text' => 'text' - - If the token is an opening bracket and a colon, make a new list => - [:word1: text] => [[:word1:, text]] - - If the token is a simple opening bracket, simply set the regular - bracket tag to true. - - If the token is a closed bracket, and the regular bracket is not - true, get the last item in the group. ([:word1: text]). Process - this list and get a string back. If there the list still has - items, add it to the text part: - - returned string = <inline arg1="word1"> text</inline> - - list = [[:arg2:, "more text]] - - Becomes: - - list = [[:arg2:, 'more text <inline arg1="word1" text </inline>'] - - Otherwise, add the token either to the final string, or to the - text portion of the list. - - """ - final_string = '' - for token in tokens: - start_role = self.__start_role_func(token) - ##print repr(token) - ##if token == ']' and not self.__reg_bracket: - if token == self.__end_group and self.__bracket_type and \ - self.__bracket_type[-1] == 'inline': - - inside_string = self.__token_list.pop() - parsed_string = self.__process_inside_group(inside_string) - if self.__token_list: - self.__token_list[-1][1] += parsed_string - else: - final_string += parsed_string - - self.__bracket_type.pop() - - # check for solitary closing brackets - elif token == self.__end_group and not self.__bracket_type: - sys.stderr.write('ending bracket may cause unwanted results\n') - if self.__token_list: - self.__token_list[-1][1] += token - else: - final_string += token - elif start_role: - self.__token_list.append([]) - self.__token_list[-1].append(token) - self.__bracket_type.append('inline') # inline bracket group - self.__token_list[-1].append('') - else: - # first test if you should add or pop list type - if token == self.__end_group: - ##self.__bracket_type.pop() - try: - self.__bracket_type.pop() - except IndexError: - pass - elif token[0:1] == self.__start_group: - self.__bracket_type.append('regular') # regular bracket group - - # now add the string to the right place - if self.__token_list: - self.__token_list[-1][1] += token # add to middle group - else: - final_string += token - if self.__token_list: - warning = 'WARNING Brackets not closed out\n' - warning += self.__token_list[0][0] + self.__token_list[0][1] - sys.stderr.write(repr(warning)) - warning = '<%s description="Brackets not closed properly"/>' % ( - self.__warning) - final_string += warning + self.__token_list[0][0] + self.__token_list[0][1] - self.__token_list = [] - - return final_string - - def make_tags(self, my_string): - my_list = re.split(self.__split_exp, my_string) - my_string = self.__tag(my_list) - return my_string - - - -if __name__ == '__main__': - start_role = ':' - end_role = ':' - start_group = '[' - end_group = ']' - place = 'inside' - - test_obj = InlineToXML( - start_role = start_role, - end_role = end_role, - place = place, - start_group = start_group, - end_group = end_group - ) - the_test_string = '<i role = "arg">[:role: test22 [:role2: text2]</i>][]' - return_string = test_obj.make_tags(the_test_string) - print '@%s@' % return_string - - start_role = ':' - end_role = ':' - start_group = '[' - end_group = ']' - place = 'outside' - - test_obj = InlineToXML( - start_role = start_role, - end_role = end_role, - place = place, - start_group = start_group, - end_group = end_group - ) - - the_test_string = ':role:[ test :role2:[ text2]]' - return_string = test_obj.make_tags(the_test_string) - print return_string diff --git a/sandbox/paultremblay/docutils_nest/docutils_nest/nest_docutils.py b/sandbox/paultremblay/docutils_nest/docutils_nest/nest_docutils.py deleted file mode 100644 index 61941fbb1..000000000 --- a/sandbox/paultremblay/docutils_nest/docutils_nest/nest_docutils.py +++ /dev/null @@ -1,123 +0,0 @@ -#!/usr/bin/env python -import sys, os -import docutils_nest.nested_inline -import docutils_nest.read_config -import docutils_nest.options_trem -import docutils_nest.location - -""" -converst an XML file to nested tags - - -""" -outer_dir = docutils_nest.location.get_location() -doc_nest_dir = os.path.join(outer_dir, '.docutils_nest') - - -class GetOptions: - def __init__(self, sys_string): - self.__sys_string = sys_string - - def get_options(self): - options_dict = { - 'output': [1,'o'] - } - options_obj = docutils_nest.options_trem.ParseOptions( - system_string = self.__sys_string, - options_dict = options_dict, - ) - - options, arguments = options_obj.parse_options() - output = '' - file = '' - if options == 0: - sys.stderr.write('Script will quit because of invalid options') - sys.exit(1) - output = options.get('output') - - if not output: - sys.stderr.write('must provide output for script to work\n') - sys.exit(1) - if arguments: - file = arguments[0] - - if not file: - sys.stderr.write('must provide a file for script to work\n') - sys.exit(1) - - return file, output - -class GetConfig: - - def __init__(self, file): - self.__file = file - - def get_config(self): - config_obj = docutils_nest.read_config.Configure(self.__file) - config_values = config_obj.read_configs() - return config_values - -class MakeTags: - def __init__( self, - file, - output, - config_values - - ): - self.__file = file - self.__output = output - self.__start_role = config_values.get('start_role') - self.__end_role = config_values.get('end_role') - self.__start_group = config_values.get('start_group') - self.__end_group = config_values.get('end_group') - self.__place_of_role = config_values.get('place_of_role') - self.__tag_name = config_values.get('tag_name') - self.__warning = config_values.get('warning') - - def make_tags(self): - convert_obj = docutils_nest.nested_inline.InlineBrackets( - file = self.__file, - output = self.__output, - start_role = self.__start_role, - end_role = self.__end_role, - start_group = self.__start_group, - end_group = self.__end_group, - place = self.__place_of_role, - tag_name = self.__tag_name, - warning = self.__warning - ) - convert_obj.make_tags() - - - - -class NestDocutils: - - def __init__(self, file, output): - self.__file = file - self.__output = output - - def nest_tags(self): - config_file = os.path.join(doc_nest_dir, 'configure.xml') - config_obj = GetConfig(config_file) - config_values = config_obj.get_config() - tags_obj = MakeTags(self.__file, self.__output, config_values) - tags_obj.make_tags() - -if __name__ == '__main__': - - # file = '/home/paul/lib/python/paul/restructure_tools/test_inline.xml' - # output = '/home/paul/paultemp/brackets_to_tags.temp.xml' - # nest_obj = NestDocutils(file, output) - # nest_obj.nest_tags() - # sys.exit(0) - options_obj = GetOptions(sys.argv) - file, output = options_obj.get_options() - config_file = os.path.join(doc_nest_dir, 'configure.xml') - config_obj = GetConfig(config_file) - config_values = config_obj.get_config() - tags_obj = MakeTags(file, output, config_values) - tags_obj.make_tags() - command = 'xmlvalid -c -v %s' % output - os.system(command) - diff --git a/sandbox/paultremblay/docutils_nest/docutils_nest/nest_utils.py b/sandbox/paultremblay/docutils_nest/docutils_nest/nest_utils.py deleted file mode 100644 index c158334f9..000000000 --- a/sandbox/paultremblay/docutils_nest/docutils_nest/nest_utils.py +++ /dev/null @@ -1,181 +0,0 @@ -""" - -This script converts a document marked up as rst to XML. It uses the -docutils-xml.py conversion tools, and then performs one more transformation to -convert text specially marked up to XML as well. - -NOTE: This is not part of the official docutils package. Rather, it is my own -extension. - -""" - -import os, sys -import docutils_nest.nest_docutils -import docutils_nest.rst_options - -class RstWithInline: - - def __init__(self, file, output, docutils_opts = []): - self.__file = file - self.__output = output - self.__docutils_opts = docutils_opts - - def convert(self): - - """ - - Requires: - - nothing - - Returns: - - nothing - - Logic: - - First convert the txt file to a temp XML file. Then convert this - temp file, chagning inline marked-up text to tags. - - """ - temp_file = self.__convert_restructure() - self.__convert_inline(temp_file) - - - - - def __convert_restructure(self): - """ - - Requires: - - nothing - - Returns: - - nothing - - Logic: - - Use the docuitls-xml script to convert the file from rst to XML - - - """ - import locale - try: - locale.setlocale(locale.LC_ALL, '') - except: - pass - ##--no-doctype - argv = self.__docutils_opts - argv.append('--no-doctype') - argv.append(self.__file) # input file - restructure_temp = '/tmp/restructure_text_temp' # temp output - argv.append(restructure_temp) - - - from docutils.core import publish_cmdline, default_description - - # I think this is just for the description at the beginning of the - # resulting file - description = ('Generates Docutils-native XML from standalone ' - 'reStructuredText sources. \n' - 'From script resruct_to_tei.py ' + default_description) - - # invoke the method for coversion - publish_cmdline(writer_name='xml', description=description, - argv = argv) - - return restructure_temp - # os.rename(restructure_temp, self.__output) - - def __convert_inline(self, temp): - - """ - - Requires: - - temp -- a valid, XML file converted from docutils-xml.py - - Returns: - - nothing - - Logic: - - Use the module nest_docutils to transform text marked up as inline to XML. - - """ - nest_obj = docutils_nest.nest_docutils.NestDocutils(temp, self.__output) - nest_obj.nest_tags() - - - - -def print_help_message(): - sys.stdout.write( - '\n\n' - 'Use For rst_convert_with_inline:\n' - '=================================' - '\n\n' - 'python rst_convert_with_inline.py [docuitls options] --output <output> file.txt\n' - '(--output *must* be provided!)\n' - '\n\n' - 'An invalid docutils options will cause an error.\n' - 'Hold on while the docutils help message prints out...' - '\n\n' - ) - - - import locale - try: - locale.setlocale(locale.LC_ALL, '') - except: - pass - argv = ['--help'] - - from docutils.core import publish_cmdline, default_description - - # I think this is just for the description at the beginning of the - # resulting file - description = ('Generates Docutils-native XML from standalone ' - 'reStructuredText sources. \n' - 'From script resruct_to_tei.py ' + default_description) - - # invoke the method for coversion - publish_cmdline(writer_name='xml', description=description, - argv = argv) - -def convert_file(): - - options_dict = { - 'output': [1] - } - opt_obj = docutils_nest.rst_options.OptionsRst(sys.argv, options_dict) - inline_opts, args, doc_opts = opt_obj.parse_options() - if inline_opts == 0: - print_help_message() - sys.stderr.write('Script will now quite because of illegal options\n') - sys.exit(1) - try: - file = args[0] - except IndexError: - sys.stderr.write('You must provide a file for the script to convert.\n' - 'Script will now quit' - ) - sys.exit(1) - output = inline_opts.get('output') - if not output: - sys.stderr.write('You must provide an output option for the script to work\n' - 'Script will now quit\n' - ) - sys.exit(1) - convert_obj = RstWithInline(file, output, docutils_opts = doc_opts) - convert_obj.convert() - -if __name__ == '__main__': - # # file = os.path.join(nest_inline_location, 'nest_inline/test_files/simple1.txt') - # # output = os.path.join(nest_inline_location, 'nest_inline/output.xml') - convert_file() - - nest_inline_location = '/home/paul/lib/python/' diff --git a/sandbox/paultremblay/docutils_nest/docutils_nest/nested_inline.py b/sandbox/paultremblay/docutils_nest/docutils_nest/nested_inline.py deleted file mode 100644 index 7937f070e..000000000 --- a/sandbox/paultremblay/docutils_nest/docutils_nest/nested_inline.py +++ /dev/null @@ -1,352 +0,0 @@ -import os, re, sys, codecs - -import xml.sax.saxutils -import xml.sax - -# turn on this line if you want to disablenamespaces -##from xml.sax.handler import feature_namespaces - -##import paul.restructure_tools.handle_inline_text -import docutils_nest.inline_to_xml -# # import txt_to_xml.brackets_to_xml - -""" - -Inline -^^^^^^ - -:author: Paul Tremblay - -:revision: - - :revnumber: .2 - - :date: 2003-05-03 - - :revremark: When I first started writing this document. - - :revnumber: .21 - - :date: 2003-05-06 - - :revremark: Turned off namespaces. Tried "to get rid of using import .. - from" construction, since I don't understand it. - - :revnumber: .22 - - :date: 2003-05-09 - - :revremark: Documented the module. Escaped brackets such as \[. Escaped any - bracket in an attribute. - - :revnumber: .23 - - :date: 2003-05-31 - - :revremark: The user can now choose his or her own way to define groups. - -======== -Overview -======== - -This module gets a file and changes brackets to inline tags: - -<document> - - <paragraph>Text [:word1 word2 word3: Text [:word1 word2: Text2 [regular bracket]]Text3] - </paragraph> - -</document> - - -<document> - - <paragraph>Text <arg1="word1" arg2="word2" arg3="word3"> Text <inline arg1="word1" arg2= "word2"> Text2 [regular bracket]</inline>Text3</inline> - </paragraph> - -</document> - -""" - - - - -class InlineHandler(xml.sax.saxutils.DefaultHandler): - """ - - Class for handling the XML file. SAX uses the methods in this class to - handle the data. - - - """ - def __init__( self, - write_obj, - start_role = ':', - end_role = ':', - start_group = '[', - end_group = ']', - place = 'inside', - tag_name = 'inline', - warning = 'problematic' - - ): - - """ - - - Requires: - - write_obj -- a write object - - Returns: - - nothing - - - Logic: - - Set the necessary parameters: - - self.__write_obj --the object for outputing text - - self.__name --name of current element - - self.__character --string containg characters in current - element. - - self.__in_block --whether the text is in a block element. - - self.__block_tags -- a list of tags that include blocks of - text. In other words, all tags except those tags that surround - inline items. - - self.__block_tags -- the string of all text and elements in - the current block. - - self.__handl_br_text_obj -- an object to handle all block text - that contains an open bracket. - - """ - self.__write_obj = write_obj - self.__name = '' - self.__character = '' - self.__in_block = 0 - self.__block_tags = ['paragraph', 'author', 'date', 'revision', - 'version'] - self.__block_tag_string = '' - # self.__handle_br_text_obj = \ - # rst_bracket_inline.handle_bracket_string.Inline() - self.__handle_br_text_obj = \ - docutils_nest.inline_to_xml.InlineToXML( - start_role = start_role, - end_role = end_role, - start_group = start_group, - end_group = end_group, - place = place, - tag_name = tag_name, - warning = warning - ) - - def startElement(self, name, attrs): - """ - - Logic: - - The SAX driver uses this function when if finds a beginning tag. - - Escape all opening and closing brackets for the values of - attributes, so they won't be processed. - - Make a string from the opening tag. If you are in a block element, - add this string to the block element string. Otherwise, write the - string to the file. - - - - """ - self.__name = name - if name in self.__block_tags: - self.__in_block = 1 - open_tag = '<%s' % name - keys = attrs.keys() - for key in keys: - att = key - value = attrs[key] - # kind of a kludge. Only escape text that is going to be unescaped - # later on - if self.__in_block: - value = value.replace('[', '\000') - value = value.replace(']', '\001') - open_tag += ' %s="%s"' % (att, value) - open_tag += '>' - if self.__in_block: - self.__block_tag_string += open_tag - else: - self.__write_obj.write(open_tag) - - - def characters(self, character): - """ - - Logic: - - The SAX driver uses this function when it finds text. - - If the text is between two literal tags, then I want to escape all - opening and closing brackts to that they are not processed. - - If the text is not between two literal tags, I want to escape a - backlash followed by a bracket. - - (Note: The only way that a file processed by docutils-xml will - pass on a backslash followed by a bracket is if the original file - has *2* backslashes followed by a bracket.) - - Add the changed string to the block test string. - - If the text is not in a block (which I don't think should happen), - it simply outputs it to the file. - - """ - - character = character.replace('&', '&') - character = character.replace('<', '<') - character = character.replace('>', '>') - if self.__in_block: - if self.__name == 'literal': - character = character.replace('[', '\000') - character = character.replace(']', '\001') - # replace escaped backslashes not in literal - else: - character = character.replace('\\]', '\001') - self.__block_tag_string += character - else: - self.__write_obj.write(character) - - - def endElement(self, name): - """ - - Logic: - - The SAX driver uses the function when it finds an end tag. It - pases to this function the name of the end element. - - If the name is a block element, the function checks if it has any - starting brackets. If it does, the string should be processed with - the handle bracket module. - - The text that has been escaped is not unescaped, and the string is - written to the output file. - - If the tag does not indicate the end of a block, but you are in a - block tag, add the text to the block string. - - If the text has nothing to do with a block, simly output it to the - file. - - - """ - - - if name in self.__block_tags: - self.__block_tag_string += '</%s>' % name - # handle all the text - if '[' in self.__block_tag_string: - tagged_text = \ - self.__handle_br_text_obj.make_tags(self.__block_tag_string) - else: - tagged_text = self.__block_tag_string - tagged_text = tagged_text.replace('\000', '[') - tagged_text = tagged_text.replace('\001', ']') - self.__write_obj.write(tagged_text) - self.__in_block = 0 - self.__block_tag_string = '' - elif self.__in_block: - self.__block_tag_string += '</%s>' % name - else: - self.__write_obj.write('</%s>' % name) - - - - -class InlineBrackets: - - def __init__( self, - file, - output, - start_role = ':', - end_role = ':', - start_group = '[', - end_group = ']', - place = 'inside', - tag_name = 'inline', - warning = 'problematic' - - ): - - - """ - - - Requires: - - file --file to be read - - output --file to output to - - - Returns: - - Nothing. Outputs a file - - Logic: - - Set up a write object. - - Create an instance of the InlineHandler for sax to use. - - Pass this instance to the SAX driver. - - Use the SAX driver to handle the file. - - - """ - self.__output = output - self.__file = file - self.__start_role = start_role - self.__end_role = end_role - self.__start_group = start_group - self.__end_group = end_group - self.__place = place - self.__tag_name = tag_name - self.__warning = warning - - def make_tags(self): - (utf8_encode, utf8_decode, utf8_reader, utf8_writer) = codecs.lookup("utf-8") - write_obj = utf8_writer(open(self.__output, 'w')) - parser = xml.sax.make_parser() - # turn on this line if you want to disable namespaces - ##parser.setFeature(feature_namespaces, 0) - inline_handler = InlineHandler( write_obj = write_obj, - start_role = self.__start_role, - end_role = self.__end_role, - start_group = self.__start_group, - end_group = self.__end_group, - place = self.__place, - tag_name = self.__tag_name, - warning = self.__warning - ) - parser.setContentHandler(inline_handler) - parser.parse(self.__file) - write_obj.close() - - - -if __name__ == '__main__': - file = '/home/paul/lib/python/paul/restructure_tools/test_inline.xml' - output = '/home/paul/paultemp/brackets_to_tags.temp.xml' - obj = InlineBrackets(file, output = output, warning = '5fuck:? yo&<>u') - obj.make_tags() - command = 'xmlvalid -c -v %s' % output - os.system(command) diff --git a/sandbox/paultremblay/docutils_nest/docutils_nest/options_trem.py b/sandbox/paultremblay/docutils_nest/docutils_nest/options_trem.py deleted file mode 100644 index 6cf60a3db..000000000 --- a/sandbox/paultremblay/docutils_nest/docutils_nest/options_trem.py +++ /dev/null @@ -1,386 +0,0 @@ -import sys -class ParseOptions: - - """ - - Requires: - - system_string --The string from the command line - - options_dict -- a dictionary with the key equal to the opition, and - a list describing that option. (See below) - - - Returns: - - A tupple. The first item in the tupple is a dictionary containing - the arguments for each options. The second is a list of the - arguments. - - If invalid options are passed to the module, 0,0 is returned. - - Examples: - - Your script has the option '--indents', and '--output=file'. - - You want to give short option names as well: - - --i and -o=file - - Use this: - - options_dict = {'output': [1, 'o'], - 'indents': [0, 'i'] - } - - options_obj = ParseOptions( - system_string = sys.argv, - options_dict = options_dict - ) - - options, arguments = options_obj.parse_options() - print options - print arguments - - The result will be: - - - {indents:None, output:'/home/paul/file'}, ['/home/paul/input'] - - - """ - def __init__(self, system_string, options_dict): - self.__system_string = system_string[1:] - long_list = self.__make_long_list_func(options_dict) - # # print long_list - short_list = self.__make_short_list_func(options_dict) - # # print short_list - self.__legal_options = long_list + short_list - # # print self.__legal_options - self.__short_long_dict = self.__make_short_long_dict_func(options_dict) - # # print self.__short_long_dict - self.__opt_with_args = self.__make_options_with_arg_list(options_dict) - # # print self.__opt_with_args - self.__options_okay = 1 - - - - def __make_long_list_func(self, options_dict): - """ - Required: - - options_dict -- the dictionary mapping options to a list - - Returns: - - a list of legal options - - - - - """ - legal_list = [] - keys = options_dict.keys() - for key in keys: - key = '--' + key - legal_list.append(key) - return legal_list - - def __make_short_list_func(self, options_dict): - """ - Required: - - options_dict --the dictionary mapping options to a list - - Returns: - - a list of legal short options - - """ - legal_list = [] - keys = options_dict.keys() - for key in keys: - values = options_dict[key] - try: - legal_list.append('-' + values[1]) - except IndexError: - pass - - return legal_list - - - - def __make_short_long_dict_func(self, options_dict): - """ - Required: - - options_dict --the dictionary mapping options to a list - - Returns: - - a dictionary with keys of short options and values of long options - - """ - short_long_dict = {} - keys = options_dict.keys() - for key in keys: - values = options_dict[key] - try: - short = '-' + values[1] - long = '--' + key - short_long_dict[short] = long - except IndexError: - pass - - return short_long_dict - - def __make_options_with_arg_list(self, options_dict): - """ - Required: - - options_dict --the dictionary mapping options to a list - - Returns: - - a list of options that take arguments. - - """ - opt_with_arg = [] - keys = options_dict.keys() - for key in keys: - values = options_dict[key] - try: - if values[0]: - opt_with_arg.append('--' + key) - except IndexError: - pass - - return opt_with_arg - - - def __sub_short_with_long(self): - """ - Required: - - nothing - - Returns: - - a new system string - - Logic: - - iterate through the system string and replace short options with long options - - - """ - new_string = [] - sub_list = self.__short_long_dict.keys() - for item in self.__system_string: - if item in sub_list: - item = self.__short_long_dict[item] - new_string.append(item) - return new_string - - - - def __pair_arg_with_option(self): - - """ - - Required: - - nothing - - Returns - - nothing (changes value of self.__system_string) - - Logic: - - iterate through the system string, and match arguments with options: - - old_list = ['--foo', 'bar'] - - new_list = ['--foo=bar' - - """ - opt_len = len(self.__system_string) - new_system_string = [] - counter = 0 - slurp_value = 0 - for arg in self.__system_string: - - # previous value was an option with an argument, so this arg is - # actually an argument that has already been added - counter += 1 - if slurp_value: - slurp_value = 0 - continue - - # not an option--an argument - if arg[0] != '-': - new_system_string.append(arg) - - # option and argument already paired - elif '=' in arg: - new_system_string .append(arg) - else: - # this option takes an argument - if arg in self.__opt_with_args: - # option is the last in the list - if counter + 1 > opt_len: - sys.stderr.write('option "%s" must take an argument\n' % arg) - new_system_string.append(arg) - self.__options_okay = 0 - else: - # the next item in list is also an option - if self.__system_string[counter][0] == '-': - sys.stderr.write('option "%s" must take an argument\n' % arg) - new_system_string.append(arg) - self.__options_okay = 0 - # the next item in the list is the argument - else: - new_system_string.append(arg + '=' + self.__system_string[counter]) - slurp_value = 1 - # this option does not take an argument - else: - new_system_string.append(arg) - return new_system_string - - - def __get_just_options(self): - - """ - - Requires: - - nothing - - Returns: - - list of options - - Logic: - - Iterate through the self.__system string, looking for the last - option. The options are everything in the sysem string before the - last option. - - Check to see that the options contain no arguments. - - - """ - highest = 0 - counter = 0 - found_options = 0 - for item in self.__system_string: - if item[0] == '-': - highest = counter - found_options = 1 - counter += 1 - - if found_options: - just_options = self.__system_string[:highest + 1] - arguments = self.__system_string[highest + 1:] - else: - just_options = [] - arguments = self.__system_string - - if found_options: - for item in just_options: - if item[0] != '-': - sys.stderr.write('%s is an argument in an option list\n' % item) - self.__options_okay = 0 - return just_options, arguments - - - def __is_legal_option_func(self): - - """ - Requires: - - nothing - - Returns: - - nothing - - Logic: - - Check each value in the newly creatd options list to see if it - matches what the user describes as a legal option. - - - """ - illegal_options = [] - for arg in self.__system_string: - if '=' in arg: - temp_list = arg.split('=') - arg = temp_list[0] - if arg not in self.__legal_options and arg[0] == '-': - illegal_options.append(arg) - - if illegal_options: - self.__options_okay = 0 - sys.stderr.write('The following options are not permitted:\n') - for not_legal in illegal_options: - sys.stderr.write('%s\n' % not_legal) - - - def __make_options_dict(self, options): - options_dict = {} - for item in options: - if '=' in item: - option, arg = item.split('=') - else: - option = item - arg = None - - if option[0] == '-': - option = option[1:] - if option[0] == '-': - option = option[1:] - - options_dict[option] = arg - - return options_dict - - def parse_options(self): - self.__system_string = self.__sub_short_with_long() - # # print 'subbed list is %s' % self.__system_string - self.__system_string = self.__pair_arg_with_option() - # # print 'list with pairing is %s' % self.__system_string - options, arguments = self.__get_just_options() - # # print 'options are %s ' % options - # # print 'arguments are %s ' % arguments - self.__is_legal_option_func() - if self.__options_okay: - options_dict = self.__make_options_dict(options) - # # print options_dict - return options_dict, arguments - - else: - return 0,0 - - - - -if __name__ == '__main__': - this_dict = { - 'indents': [0, 'i'], - 'output': [1, 'o'], - 'test3': [1, 't'], - } - test_obj = ParseOptions(system_string = sys.argv, - options_dict = this_dict - ) - - options, the_args = test_obj.parse_options() - print options, the_args - - """ - this_options = ['--foo', '-o'] - this_opt_with_args = ['--foo'] - - """ diff --git a/sandbox/paultremblay/docutils_nest/docutils_nest/read_config.py b/sandbox/paultremblay/docutils_nest/docutils_nest/read_config.py deleted file mode 100644 index 84ac7b4ad..000000000 --- a/sandbox/paultremblay/docutils_nest/docutils_nest/read_config.py +++ /dev/null @@ -1,143 +0,0 @@ -import os, re, sys, codecs - -import xml.sax.saxutils -import xml.sax - -# turn on this line if you want to disablenamespaces -##from xml.sax.handler import feature_namespaces - - -config_values = { - 'start_role' : ':', - 'end_role' : ':', - 'start_group' : '[', - 'end_group' : ']', - 'place_of_role' : 'inside', - 'tag_name' : 'inline', - 'warning' : 'problematic', - -} - - -class ConfigHandler(xml.sax.saxutils.DefaultHandler): - """ - - Class for handling the XML file. SAX uses the methods in this class to - handle the data. - - - """ - def __init__(self): - - """ - - - Requires: - - - Returns: - - nothing - - - Logic: - - - """ - self.__allowed = [ - 'start-role', 'end-role', 'start-group', 'end-group', 'place-of-role', - 'tag-name', 'warning', 'configure' - ] - - - - def startElement(self, name, attrs): - """ - - Logic: - - The SAX driver uses this function when if finds a beginning tag. - - - - """ - if name in self.__allowed: - values = attrs.values() - config_values[name] = values - - else: - sys.stderr.write('%s not a valid option\n' % name) - - - def characters(self, character): - """ - - Logic: - - The SAX driver uses this function when it finds text. - - """ - pass - - - - def endElement(self, name): - """ - - Logic: - - - """ - - pass - - - - -class Configure: - - def __init__(self, file): - - - """ - - - Requires: - - - - Returns: - - - Logic: - - Set up a write object. - - Create an instance of the InlineHandler for sax to use. - - Pass this instance to the SAX driver. - - Use the SAX driver to handle the file. - - - """ - file_exists = os.path.exists(file) - if not file_exists: - raise IOError, 'file %s does not exist' % file - self.__file = file - - def read_configs(self): - parser = xml.sax.make_parser() - # turn on this line if you want to disable namespaces - ##parser.setFeature(feature_namespaces, 0) - config_handler = ConfigHandler() - parser.setContentHandler(config_handler) - parser.parse(self.__file) - return config_values - - - -if __name__ == '__main__': - file = '/home/paul/docutils-extensions/configure.xml' - obj = Configure(file) - obj.read_configs() diff --git a/sandbox/paultremblay/docutils_nest/docutils_nest/rst_options.py b/sandbox/paultremblay/docutils_nest/docutils_nest/rst_options.py deleted file mode 100644 index b0d3737bf..000000000 --- a/sandbox/paultremblay/docutils_nest/docutils_nest/rst_options.py +++ /dev/null @@ -1,106 +0,0 @@ -""" - -Parse options from the command line in order to convert an rst text to XML. - -This script separates the options a script needs from the options that docuitls needs. - -Takes a system string. Returns a dictionary of options for docutils inline, a list of argumetns for docutils-inline, and a string for docutils. - -""" - -import sys, os -import options_trem - -class OptionsRst: - - def __init__(self, sys_argv, script_options): - - - self.__sys_argv = sys_argv - self.__rst_options_dict = { - 'pep-references': [], - 'rfc-references': [], - 'tab-width': [1], - 'newlines': [], - 'indents': [], - 'no-xml-declaration': [], - 'no-doctype': [], - 'generator': [0,'g'], - 'no-generator': [], - 'date': [0,'d'], - 'time': [0,'t'], - 'no-datestamp': [], - 'source-link': [0, 's'], - 'source-url': [1], - 'no-source-link': [], - 'toc-entry-backlinks': [], - 'toc-top-backlinks': [], - 'no-toc-backlinks': [], - 'footnote-backlinks': [], - 'no-footnote-backlinks': [], - 'report': [1, 'r'], - 'verbose': [0,'v'], - 'quiet': [0, 'q'], - 'halt': [1], - 'strict': [], - 'debug': [], - 'no-debug': [], - 'warnings': [], - 'input-encoding': [1, 'i'], - 'output-encoding': [1, 'o'], - 'language': [1, 'l'], - 'config': [1], - 'version': [0, 'V'], - 'help': [0, 'h'], - } - - - self.__inline_options_dict = script_options - self.__rst_options_list = self.__rst_options_dict.keys() - self.__inline_options_list = self.__inline_options_dict.keys() - - self.__both_options = {} - self.__both_options.update(self.__rst_options_dict) - self.__both_options.update(self.__inline_options_dict) - - def parse_options(self): - opts, args = self.__get_raw_options() - if opts == 0: - return 0, 0, 0 - doc_opts, inline_opts = self.__split_options(opts) - return inline_opts, args, doc_opts - - def __get_raw_options(self): - raw_obj = options_trem.ParseOptions( - options_dict = self.__both_options, - system_string = self.__sys_argv - ) - - options, arguments = raw_obj.parse_options() - return options, arguments - - def __split_options(self, options): - inline_options = {} - docutils_options = [] - keys = options.keys() - for key in keys: - if key in self.__rst_options_list: - if options[key] == None: - docutils_options.append('--%s' % key) - else: - docutils_options.append('--%s=%s' % (key, options[key])) - - else: - inline_options[key] = options[key] - - return docutils_options, inline_options - - - - -if __name__ == '__main__': - this_options_dict = { - 'output': [1], - } - test_obj = OptionsRst(sys.argv, this_options_dict) - test_obj.parse_options() diff --git a/sandbox/paultremblay/docutils_nest/docutils_nest/well_formed_xml.py b/sandbox/paultremblay/docutils_nest/docutils_nest/well_formed_xml.py deleted file mode 100644 index 643565382..000000000 --- a/sandbox/paultremblay/docutils_nest/docutils_nest/well_formed_xml.py +++ /dev/null @@ -1,73 +0,0 @@ -import xml.parsers.expat - -""" - -well_formed module -^^^^^^^^^^^^^^^^^^ - -======== -Overview -======== - -Takes a string, and returns either a zero or one, depending if the string has -balanced tags. - - -""" - -class WellFormed: - - def __init__(self): - pass - - def well_formed(self, my_string): - """ - - Requires: - - my_string --string to test for well-formedness - - Returns: - - 1, if the tags are balanced, and 0 if the tags are not - - Logic: - - Enclose the string around an artifical root element. - - Change the encoding, if necessary. - - Try to parse the string with expat. If there is success, return 1. - Otherwise, catch the exception and return 0. - - """ - enclosing_tag = 'doc-string-test6685866' - my_string = '<%s>%s</%s>' % (enclosing_tag, my_string, enclosing_tag) - try: - if isinstance(my_string, type(u"")): - my_string = my_string.encode("utf-8") - parser = xml.parsers.expat.ParserCreate() - parser.Parse(my_string, 1) - return 1 - except xml.parsers.expat.ExpatError: - return 0 - - -if __name__ == '__main__': - test_strings = [ - '<tag>simplest test</tag>', - '<tag>simplest fail test<tag>', - '<tag>&text\u201c</tag><tag>text,</tag>', - '<tag>&text<</tag><tag>text,</tag>', - '</tag>&text<</tag><tag>text,<tag>', - ] - test_obj = WellFormed() - for test_string in test_strings: - well_formed = test_obj.well_formed(test_string) - if well_formed: - print '%s is well formed' % test_string - else: - print '%s is not well formed' % test_string - - - diff --git a/sandbox/paultremblay/docutils_nest/options_trem.py b/sandbox/paultremblay/docutils_nest/options_trem.py deleted file mode 100644 index 09eb3e4f4..000000000 --- a/sandbox/paultremblay/docutils_nest/options_trem.py +++ /dev/null @@ -1,377 +0,0 @@ -import sys -class ParseOptions: - - """ - - Requiries: - - system_string --The string from the command line - - options_dict -- a dictionary with the key equal to the opition, and - a list describing that option. (See below) - - - Returns: - - A tupple. The first item in the tupple is a dictionary containing - the arguments for each options. The second is a list of the - arguments. - - If invalid options are passed to the module, 0,0 is returned. - - Examples: - - Your script has the option '--indents', and '--output=file'. - - You want to give short option names as well: - - --i and -o=file - - Use this: - - options_dict = {'output': [1, 'o'], - 'indents': [0, 'i'] - } - - options_obj = ParseOptions( - system_string = sys.argv, - options_dict = options_dict - ) - - options, arguments = options_obj.parse_options() - print options - print arguments - - The result will be: - - - {indents:None, output:'/home/paul/file'}, ['/home/paul/input'] - - - """ - def __init__(self, system_string, options_dict): - self.__system_string = system_string[1:] - long_list = self.__make_long_list_func(options_dict) - # # print long_list - short_list = self.__make_short_list_func(options_dict) - # # print short_list - self.__legal_options = long_list + short_list - # # print self.__legal_options - self.__short_long_dict = self.__make_short_long_dict_func(options_dict) - # # print self.__short_long_dict - self.__opt_with_args = self.__make_options_with_arg_list(options_dict) - # # print self.__opt_with_args - self.__options_okay = 1 - - - - def __make_long_list_func(self, options_dict): - """ - Required: - - options_dict -- the dictionary mapping options to a list - - Returns: - - a list of legal options - - - - - """ - legal_list = [] - keys = options_dict.keys() - for key in keys: - key = '--' + key - legal_list.append(key) - return legal_list - - def __make_short_list_func(self, options_dict): - """ - Required: - - options_dict --the dictionary mapping options to a list - - Returns: - - a list of legal short options - - """ - legal_list = [] - keys = options_dict.keys() - for key in keys: - values = options_dict[key] - try: - legal_list.append('-' + values[1]) - except IndexError: - pass - - return legal_list - - - - def __make_short_long_dict_func(self, options_dict): - """ - Required: - - options_dict --the dictionary mapping options to a list - - Returns: - - a dictionary with keys of short options and values of long options - - """ - short_long_dict = {} - keys = options_dict.keys() - for key in keys: - values = options_dict[key] - try: - short = '-' + values[1] - long = '--' + key - short_long_dict[short] = long - except IndexError: - pass - - return short_long_dict - - def __make_options_with_arg_list(self, options_dict): - """ - Required: - - options_dict --the dictionary mapping options to a list - - Returns: - - a list of options that take arguments. - - """ - opt_with_arg = [] - keys = options_dict.keys() - for key in keys: - values = options_dict[key] - try: - if values[0]: - opt_with_arg.append('--' + key) - except IndexError: - pass - - return opt_with_arg - - - def __sub_short_with_long(self): - """ - Required: - - nothing - - Returns: - - a new system string - - Logic: - - iterate through the system string and replace short options with long options - - - """ - new_string = [] - sub_list = self.__short_long_dict.keys() - for item in self.__system_string: - if item in sub_list: - item = self.__short_long_dict[item] - new_string.append(item) - return new_string - - - - def __pair_arg_with_option(self): - - """ - - Required: - - nothing - - Returns - - nothing (changes value of self.__system_string) - - Logic: - - iterate through the system string, and match arguments with options: - - old_list = ['--foo', 'bar'] - - new_list = ['--foo=bar' - - """ - opt_len = len(self.__system_string) - new_system_string = [] - counter = 0 - slurp_value = 0 - for arg in self.__system_string: - - # previous value was an option with an argument, so this arg is - # actually an argument that has already been added - if slurp_value: - slurp_value = 0 - continue - counter += 1 - - # not an option--an argument - if arg[0] != '-': - new_system_string.append(arg) - - # option and argument already paired - elif '=' in arg: - new_system_string .append(arg) - else: - # this option takes an argument - if arg in self.__opt_with_args: - # option is the last in the list - if counter + 1 > opt_len: - sys.stderr.write('option "%s" must take an argument\n' % arg) - new_system_string.append(arg) - self.__options_okay = 0 - else: - # the next item in list is also an option - if self.__system_string[counter][0] == '-': - sys.stderr.write('option "%s" must take an argument\n' % arg) - new_system_string.append(arg) - self.__options_okay = 0 - # the next item in the list is the argument - else: - new_system_string.append(arg + '=' + self.__system_string[counter]) - slurp_value = 1 - # this option does not take an argument - else: - new_system_string.append(arg) - return new_system_string - - - def __get_just_options(self): - - """ - - Requires: - - nothing - - Returns: - - list of options - - Logic: - - Iterate through the self.__system string, looking for the last - option. The options are everything in the sysem string before the - last option. - - Check to see that the options contain no arguments. - - - """ - highest = 0 - counter = 0 - for item in self.__system_string: - if item[0] == '-': - highest = counter - counter += 1 - - just_options = self.__system_string[:highest + 1] - arguments = self.__system_string[highest + 1:] - - for item in just_options: - if item[0] != '-': - sys.stderr.write('%s is an argument in an option list\n' % item) - self.__options_okay = 0 - return just_options, arguments - - - def __is_legal_option_func(self): - - """ - Requires: - - nothing - - Returns: - - nothing - - Logic: - - Check each value in the newly creatd options list to see if it - matches what the user describes as a legal option. - - - """ - illegal_options = [] - for arg in self.__system_string: - if '=' in arg: - temp_list = arg.split('=') - arg = temp_list[0] - if arg not in self.__legal_options and arg[0] == '-': - illegal_options.append(arg) - - if illegal_options: - self.__options_okay = 0 - sys.stderr.write('The following options are not permitted:\n') - for not_legal in illegal_options: - sys.stderr.write('%s\n' % not_legal) - - - def __make_options_dict(self, options): - options_dict = {} - for item in options: - if '=' in item: - option, arg = item.split('=') - else: - option = item - arg = None - - if option[0] == '-': - option = option[1:] - if option[0] == '-': - option = option[1:] - - options_dict[option] = arg - - return options_dict - - def parse_options(self): - self.__system_string = self.__sub_short_with_long() - # # print 'subbed list is %s' % self.__system_string - self.__system_string = self.__pair_arg_with_option() - # # print 'list with pairing is %s' % self.__system_string - options, arguments = self.__get_just_options() - # # print 'options are %s ' % options - # # print 'arguments are %s ' % arguments - self.__is_legal_option_func() - if self.__options_okay: - options_dict = self.__make_options_dict(options) - # # print options_dict - return options_dict, arguments - - else: - return 0,0 - - - - -if __name__ == '__main__': - this_dict = { - 'indents': [0, 'i'], - 'output': [1, 'o'], - } - test_obj = ParseOptions(system_string = sys.argv, - options_dict = this_dict - ) - - options, the_args = test_obj.parse_options() - - """ - this_options = ['--foo', '-o'] - this_opt_with_args = ['--foo'] - - """ diff --git a/sandbox/paultremblay/docutils_nest/read_config.py b/sandbox/paultremblay/docutils_nest/read_config.py deleted file mode 100644 index f7eaddaee..000000000 --- a/sandbox/paultremblay/docutils_nest/read_config.py +++ /dev/null @@ -1,144 +0,0 @@ -import os, re, sys, codecs - -import xml.sax.saxutils -import xml.sax - -# turn on this line if you want to disablenamespaces -##from xml.sax.handler import feature_namespaces - - -config_values = { - 'start_role' : ':', - 'end_role' : ':', - 'start_group' : '[', - 'end_group' : ']', - 'place_of_role' : 'inside', - 'tag_name' : 'inline', - 'warning' : 'problematic', - -} - - -class ConfigHandler(xml.sax.saxutils.DefaultHandler): - """ - - Class for handling the XML file. SAX uses the methods in this class to - handle the data. - - - """ - def __init__(self): - - """ - - - Requires: - - - Returns: - - nothing - - - Logic: - - - """ - self.__allowed = [ - 'start-role', 'end-role', 'start-group', 'end-group', 'place-of-role', - 'tag-name', 'warning', 'configure' - ] - - - - def startElement(self, name, attrs): - """ - - Logic: - - The SAX driver uses this function when if finds a beginning tag. - - - - """ - if name in self.__allowed: - values = attrs.values() - config_values[name] = values - - else: - sys.stderr.write('%s not a valid option\n' % name) - - - def characters(self, character): - """ - - Logic: - - The SAX driver uses this function when it finds text. - - """ - pass - - - - def endElement(self, name): - """ - - Logic: - - - """ - - pass - - - - -class Configure: - - def __init__(self, file): - - - """ - - - Requires: - - - - Returns: - - - Logic: - - Set up a write object. - - Create an instance of the InlineHandler for sax to use. - - Pass this instance to the SAX driver. - - Use the SAX driver to handle the file. - - - """ - file_exists = os.path.exists(file) - if not file_exists: - sys.stderr.write('file does not exist\n') - sys.exit(1) - self.__file = file - - def read_configs(self): - parser = xml.sax.make_parser() - # turn on this line if you want to disable namespaces - ##parser.setFeature(feature_namespaces, 0) - config_handler = ConfigHandler() - parser.setContentHandler(config_handler) - parser.parse(self.__file) - return config_values - - - -if __name__ == '__main__': - file = '/home/paul/docutils-extensions/configure.xml' - obj = Configure(file) - obj.read_configs() diff --git a/sandbox/paultremblay/docutils_nest/scripts/docutils-nest-xml.py b/sandbox/paultremblay/docutils_nest/scripts/docutils-nest-xml.py deleted file mode 100755 index 788f34190..000000000 --- a/sandbox/paultremblay/docutils_nest/scripts/docutils-nest-xml.py +++ /dev/null @@ -1,37 +0,0 @@ -#!/usr/bin/env python - -import sys, os -import docutils_nest.nest_utils -import docutils_nest.rst_options - - -def convert_file(): - options_dict = { - 'output': [1] - } - opt_obj = docutils_nest.rst_options.OptionsRst(sys.argv, options_dict) - inline_opts, args, doc_opts = opt_obj.parse_options() - if inline_opts == 0: - print_help_message() - sys.stderr.write('Script will now quite because of illegal options\n') - sys.exit(1) - try: - file = args[0] - except IndexError: - sys.stderr.write('You must provide a file for the script to convert.\n' - 'Script will now quit' - ) - sys.exit(1) - output = inline_opts.get('output') - if not output: - sys.stderr.write('You must provide an output option for the script to work\n' - 'Script will now quit\n' - ) - sys.exit(1) - convert_obj = docutils_nest.nest_utils.RstWithInline(file, output, docutils_opts = doc_opts) - convert_obj.convert() - -if __name__ == '__main__': - convert_file() - - diff --git a/sandbox/paultremblay/docutils_nest/setup.py b/sandbox/paultremblay/docutils_nest/setup.py deleted file mode 100644 index 88c123e55..000000000 --- a/sandbox/paultremblay/docutils_nest/setup.py +++ /dev/null @@ -1,28 +0,0 @@ -#!/usr/bin/env python - -import os, sys -from distutils.core import setup - - -# get the location for the data -var_file_exists = os.path.isfile('var_file') -if not var_file_exists: - sys.stderr.write('Please run python configure.py first\n') - sys.exit(1) -read_obj = open('var_file', 'r') -lines = read_obj.readlines() -target = lines[0] -data_location = os.path.join(target, '.docutils_nest') -read_obj.close() - - -setup(name="docutils_nest", - version=".1", - description="Add nested inline markup to an rst file.", - author="Paul Tremblay", - author_email="phthenry@earthlink.net", - packages=['docutils_nest'], - data_files = [(data_location, ["data/configure.xml"])], - scripts=["scripts/docutils-nest-xml.py"], - ) - diff --git a/sandbox/paultremblay/docutils_nest/test_files/test.txt b/sandbox/paultremblay/docutils_nest/test_files/test.txt deleted file mode 100644 index 824823a33..000000000 --- a/sandbox/paultremblay/docutils_nest/test_files/test.txt +++ /dev/null @@ -1,10 +0,0 @@ -Simple Doc -^^^^^^^^^^ - -:author: Paul Tremblay - -Start the body - -A paragraph with inline markup. [:comment: I should have read *The Sun Also Rises.*] Another sentence. - -A paragraph with deeper nesting inline markup. [:comment: I should have read *The Sun A/home/pusetup.pylso Rises* [:note: note text [:date: 6/01/03]]] diff --git a/sandbox/paultremblay/rst_to_docbook/README.txt b/sandbox/paultremblay/rst_to_docbook/README.txt deleted file mode 100644 index 426b8b6e2..000000000 --- a/sandbox/paultremblay/rst_to_docbook/README.txt +++ /dev/null @@ -1,2 +0,0 @@ -The rst_to_docbook module translates an rst document to docbook. It -uses XML tools, namely SAX and xslt. diff --git a/sandbox/paultremblay/rst_to_docbook/configure.py b/sandbox/paultremblay/rst_to_docbook/configure.py deleted file mode 100644 index 41070820b..000000000 --- a/sandbox/paultremblay/rst_to_docbook/configure.py +++ /dev/null @@ -1,138 +0,0 @@ -# /usr/bin/env python - -import sys, os -import rst_to_docbook.options_trem - -""" - -The configuration script gets the target from the command line. It creates a -file with the configuration variable, and a short script for the rest of -script to be able to read and locate he configuration files. - -""" - -def configure(): - target, processor = get_target() - if processor == None: - sys.stderr.write('Since you need an xslt processor to run this script, the configuration will now quit\n' - ) - try: - os.remove('var_file') - except: - pass - sys.exit(1) - make_var_file(target) - make_location(target) - make_configuration_file(processor) - -def get_target(): - """ - This functions uses a module I wrote to parse options. If no options are - determined on the command line, the function returnst the default - /etc/nest_docutis - - """ - options_dict = { - 'target': [1, 't'], - 'processor': [1, 'p'], - } - options_obj = rst_to_docbook.options_trem.ParseOptions(sys.argv, - options_dict) - opt_dict, args = options_obj.parse_options() - if opt_dict == 0: - sys.stderr.write('invalid options for configure.py\n' - 'use python configure --target <desired folder>' - ' --processor <xslt proccessor>' - - ) - sys.exit(1) - target = opt_dict.get('target') - if not target: - target = default_target() - processor = opt_dict.get('processor') - processor = determine_processor(processor) - return target, processor - -def default_target(): - sys.stdout.write('using default \'/etc\' for the configuration directory\n') - return '/etc' - -def determine_processor(processor = None): - sys.stdout.write('determining xslt processor...\n') - if processor == None: - processor = 'xmllint' - if processor == 'xalan': - file = 'test_files/simple.xml' - xsl_file = 'test_files/simple.xsl' - output = 'output.xml' - command = 'java org.apache.xalan.xslt.Process \ - -Ts -in %s -xsl %s -out %s' % (file, xsl_file, output) - error = os.system(command) - if error: - sys.stderr.write('xalan does not appear to be set up correctly ' - ' on your system\n' - 'The command "java org.apache.xalan.xslt.Process" failed\n' - 'Is the CLASSPATH set for xalan?\n' - 'Configuraton will now quit\n' - ) - sys.exit(1) - else: - return 'xalan' - elif processor == '4suite': - try: - from Ft.Xml import InputSource - from Ft.Xml.Xslt.Processor import Processor - return '4suite' - except: - sys.stderr.write('4suite does not appear to be set up correctly on your system\n' - 'Could not find the Ft.Xml libraries\n' - 'Script cannot work without an xslt procesor!\n' - ) - sys.exit(1) - elif processor == 'xsltproc' or processor == 'xmllint': - try: - import libxml2 - import libxslt - return 'xmllint' - except: - sys.stderr.write('You either choose xmllint as your processor, or xmllint was tested because not other\n' - 'processor was found\n' - 'However, the libraries "libxml2" and or "libxslt" cannot be found.\n' - ) - - else: - sys.stderr.write('The processor "%s" is not a valid choice for this script\n' % processor) - return None - - - - -def make_var_file(target): - write_obj = open('var_file', 'w') - # write_obj.write('[global]\n') - write_obj.write(target) - write_obj.close() - -def make_location(target): - write_obj = open('rst_to_docbook/location.py', 'w') - write_obj.write( - """ -def get_location(): - return '%s' - - - """ - % target) - -def make_configuration_file(processor): - write_obj = open('data/configure.xml', 'w') - write_obj.write(""" -<configuration> - <xslt-processor processor = "%s"/> -</configuration> - """ % processor - ) - -if __name__ == '__main__': - configure() - diff --git a/sandbox/paultremblay/rst_to_docbook/data/configure.xml b/sandbox/paultremblay/rst_to_docbook/data/configure.xml deleted file mode 100644 index 4aa25c259..000000000 --- a/sandbox/paultremblay/rst_to_docbook/data/configure.xml +++ /dev/null @@ -1,5 +0,0 @@ - -<configuration> - <xslt-processor processor = "xmllint"/> -</configuration> -
\ No newline at end of file diff --git a/sandbox/paultremblay/rst_to_docbook/data/xslt_stylesheets/reStruct_field_names.xsl b/sandbox/paultremblay/rst_to_docbook/data/xslt_stylesheets/reStruct_field_names.xsl deleted file mode 100644 index 04f365cd9..000000000 --- a/sandbox/paultremblay/rst_to_docbook/data/xslt_stylesheets/reStruct_field_names.xsl +++ /dev/null @@ -1,117 +0,0 @@ -<!--WARNING TO PAUL: DON'T EDIT THIS FILE use update.py instead. ---> - -<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> - <!-- - - This template changes field_name attributes to tags and attributes: - - - --> - - - - - <xsl:template match = "field"> - <xsl:element name = "{field_name/arguments[1]}"> - <xsl:if test= "field_name/arguments[2]"> - <xsl:attribute name = "{field_name/arguments[2]}"> - <xsl:value-of select = "field_name/arguments[3]"/> - </xsl:attribute> - </xsl:if> - <xsl:if test= "field_name/arguments[4]"> - <xsl:attribute name = "{field_name/arguments[4]}"> - <xsl:value-of select = "field_name/arguments[5]"/> - </xsl:attribute> - </xsl:if> - <xsl:if test= "field_name/arguments[6]"> - <xsl:attribute name = "{field_name/arguments[6]}"> - <xsl:value-of select = "field_name/arguments[7]"/> - </xsl:attribute> - </xsl:if> - <xsl:if test= "field_name/arguments[8]"> - <xsl:attribute name = "{field_name/arguments[8]}"> - <xsl:value-of select = "field_name/arguments[9]"/> - </xsl:attribute> - </xsl:if> - <xsl:if test= "field_name/arguments[10]"> - <xsl:attribute name = "{field_name/arguments[10]}"> - <xsl:value-of select = "field_name/arguments[11]"/> - </xsl:attribute> - </xsl:if> - <xsl:if test= "field_name/arguments[12]"> - <xsl:attribute name = "{field_name/arguments[12]}"> - <xsl:value-of select = "field_name/arguments[13]"/> - </xsl:attribute> - </xsl:if> - <xsl:if test= "field_name/arguments[14]"> - <xsl:attribute name = "{field_name/arguments[14]}"> - <xsl:value-of select = "field_name/arguments[15]"/> - </xsl:attribute> - </xsl:if> - <xsl:if test= "field_name/arguments[16]"> - <xsl:attribute name = "{field_name/arguments[16]}"> - <xsl:value-of select = "field_name/arguments[17]"/> - </xsl:attribute> - </xsl:if> - <xsl:if test= "field_name/arguments[18]"> - <xsl:attribute name = "{field_name/arguments[18]}"> - <xsl:value-of select = "field_name/arguments[19]"/> - </xsl:attribute> - </xsl:if> - <xsl:if test= "field_name/arguments[20]"> - <xsl:attribute name = "{field_name/arguments[20]}"> - <xsl:value-of select = "field_name/arguments[21]"/> - </xsl:attribute> - </xsl:if> - <xsl:apply-templates/> - </xsl:element> - </xsl:template> - - <xsl:template match="inline"> - <xsl:if test="@arg1"> - <xsl:element name = "{@arg1}"> - <xsl:if test = "@arg2"> - <xsl:attribute name = "{@arg2}"> - <xsl:value-of select = "@arg3"/> - </xsl:attribute> - </xsl:if> - <xsl:if test = "@arg4"> - <xsl:attribute name = "{@arg4}"> - <xsl:value-of select="@arg5"/> - </xsl:attribute> - </xsl:if> - <xsl:if test = "@arg6"> - <xsl:attribute name = "{@arg6}"> - <xsl:value-of select = "@arg7"/> - </xsl:attribute> - </xsl:if> - <xsl:if test = "@arg8"> - <xsl:attribute name = "{@arg8}"> - <xsl:value-of select = "@arg9"/> - </xsl:attribute> - </xsl:if> - <xsl:apply-templates/> - </xsl:element> - </xsl:if> - </xsl:template> - - - <xsl:template match = 'field_list'> - <xsl:apply-templates/> - </xsl:template> - - <xsl:template match = "field_name"/> - - <xsl:template match = 'field_body'> - <xsl:apply-templates/> - </xsl:template> - - - <xsl:template match="@*|node()"> - <xsl:copy> - <xsl:apply-templates select="@*|node()"/> - </xsl:copy> - </xsl:template> - -</xsl:stylesheet> diff --git a/sandbox/paultremblay/rst_to_docbook/data/xslt_stylesheets/reStruct_field_names_tokenize.xsl b/sandbox/paultremblay/rst_to_docbook/data/xslt_stylesheets/reStruct_field_names_tokenize.xsl deleted file mode 100644 index 6de06c068..000000000 --- a/sandbox/paultremblay/rst_to_docbook/data/xslt_stylesheets/reStruct_field_names_tokenize.xsl +++ /dev/null @@ -1,57 +0,0 @@ -<!--WARNING TO PAUL: DON'T EDIT THIS FILE use update.py instead. ---> - -<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" - version="1.0"> - -<!-- - -change the file name string into individual fiels for easier transformation later - - ---> - - <xsl:template match="field_name"> - <field_name> - <xsl:call-template name="tokens"/> - </field_name> - </xsl:template> - -<xsl:template name="tokens"> - <xsl:param name="str" select="normalize-space(.)"/> - <xsl:param name="sep" select="' '"/> - <xsl:choose> - <xsl:when test="contains($str,' ')"> - <xsl:call-template name="arguments"> - <xsl:with-param name="str" select="substring-before($str,' ')"/> - </xsl:call-template> - <xsl:value-of select="$sep"/> - <xsl:call-template name="tokens"> - <xsl:with-param name="str" select="substring-after($str,' ')"/> - </xsl:call-template> - </xsl:when> - <xsl:otherwise> - <xsl:call-template name="arguments"> - <xsl:with-param name="str" select="$str"/> - </xsl:call-template> - </xsl:otherwise> - </xsl:choose> - </xsl:template> - - <xsl:template name= "arguments"> - <xsl:param name="str" select="string(.)"/> - <arguments> - <xsl:value-of select = '$str'/> - </arguments> - </xsl:template> - - - - - <xsl:template match="@*|node()"> - <xsl:copy> - <xsl:apply-templates select="@*|node()"/> - </xsl:copy> - </xsl:template> - -</xsl:stylesheet> diff --git a/sandbox/paultremblay/rst_to_docbook/data/xslt_stylesheets/reStruct_to_docbook.xsl b/sandbox/paultremblay/rst_to_docbook/data/xslt_stylesheets/reStruct_to_docbook.xsl deleted file mode 100644 index 18ab27fdd..000000000 --- a/sandbox/paultremblay/rst_to_docbook/data/xslt_stylesheets/reStruct_to_docbook.xsl +++ /dev/null @@ -1,343 +0,0 @@ -<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> - <!-- - - This template changed a XML document that has already been processed by docutils - with the filed names template to docbook. - - --> - - - <xsl:output method='xml' doctype-system='/home/paul/Documents/data/dtds/docbookx.dtd'/> - - - <xsl:template match = "document"> - <TEI.2> - <teiHeader> - <fileDesc> - <titleStmt> - <xsl:choose> - <xsl:when test='/document/title'> - <xsl:apply-templates select = '/document/title' mode = 'keep'/> - </xsl:when> - <xsl:when test = '/document/docinfo/title'> - <xsl:apply-templates select = '/document/docinfo/title'/> - </xsl:when> - </xsl:choose> - <xsl:apply-templates select = "/document/docinfo/author"/> - </titleStmt> - <publicationStmt> - <distributor> - none - </distributor> - </publicationStmt> - <sourceDesc> - <p>no source--a manuscript</p> - </sourceDesc> - - </fileDesc> - <xsl:if test = "/document/docinfo/change"> - <revisionDesc> - <xsl:apply-templates select = "/document/docinfo/change"/> - </revisionDesc> - </xsl:if> - - <!-- - <revisionDesc> - </revisionDesc> - --> - - </teiHeader> - <text> - <body> - <xsl:apply-templates/> - </body> - </text> - </TEI.2> - </xsl:template> - - <xsl:template match = "/document/docinfo/change"> - <change> - <xsl:apply-templates/> - </change> - </xsl:template> - - - - <!--info to delte--> - <xsl:template match = "docinfo"/> - <xsl:template match = "/document/title"/> - <xsl:template match = "system_message"/> - <xsl:template match = "literal"/> - <xsl:template match = "substitution_definition"/> - <xsl:template match = "transition"/> - <xsl:template match = "substitution_definition"/> - - - <!--Info to get rid of paragraph tags--> - <xsl:template match = "p/paragraph|foreName/paragraph|surname/paragraph"> - <xsl:apply-templates/> - </xsl:template> - - <xsl:template match = "/document/docinfo/author"> - <author> - <xsl:apply-templates/> - </author> - </xsl:template> - - <xsl:template match = "/document/docinfo/change/date"> - <xsl:call-template name = 'my-date'/> - <!-- - <date> - <xsl:apply-templates/> - </date> - --> - <respStmt> - <resp>written by</resp> - <name> - Paul Tremblay - </name> - </respStmt> - </xsl:template> - <xsl:template match = "/document/docinfo/item"> - <item> - <xsl:apply-templates/> - </item> - </xsl:template> - - <xsl:template match = "paragraph"> - <xsl:choose> - <xsl:when test = "preceding-sibling::*[1]/self::transition"> - - <!-- - <xsl:when test = "name(preceding-sibling::*[1])='transition'"> - --> - <p rend="transition"> - <xsl:apply-templates/> - </p> - </xsl:when> - <xsl:otherwise> - <p> - <xsl:apply-templates/> - </p> - </xsl:otherwise> - </xsl:choose> - </xsl:template> - - <xsl:template match = 'l/paragraph'> - <xsl:apply-templates/> - </xsl:template> - - <xsl:template match = 'date/paragraph|item/paragraph'> - <xsl:apply-templates/> - </xsl:template> - - <xsl:template match = "/document/docinfo/title|/document/title" mode = 'keep'> - <title> - <xsl:apply-templates/> - </title> - </xsl:template> - - <xsl:template match = "section"> - <xsl:element name = "div"> - <xsl:attribute name = 'rend'> - <xsl:text>1</xsl:text> - </xsl:attribute> - <xsl:attribute name = 'id'> - <xsl:value-of select = '@id'/> - </xsl:attribute> - <xsl:attribute name = "type"> - <xsl:value-of select = "@name"/> - </xsl:attribute> - <xsl:apply-templates/> - </xsl:element> - </xsl:template> - - - <xsl:template match = "section/section"> - <xsl:element name = "div"> - <xsl:attribute name = 'rend'> - <xsl:text>2</xsl:text> - </xsl:attribute> - <xsl:attribute name = 'id'> - <xsl:value-of select = '@id'/> - </xsl:attribute> - <xsl:attribute name = "type"> - <xsl:value-of select = "@name"/> - </xsl:attribute> - <xsl:apply-templates/> - </xsl:element> - </xsl:template> - - <xsl:template match = "section/section/section"> - <xsl:element name = "div"> - <xsl:attribute name = 'rend'> - <xsl:text>3</xsl:text> - </xsl:attribute> - <xsl:attribute name = 'id'> - <xsl:value-of select = '@id'/> - </xsl:attribute> - <xsl:attribute name = "type"> - <xsl:value-of select = "@name"/> - </xsl:attribute> - <xsl:apply-templates/> - </xsl:element> - </xsl:template> - - <xsl:template match = "section/section/section/section"> - <xsl:element name = "div"> - <xsl:attribute name = 'rend'> - <xsl:text>4</xsl:text> - </xsl:attribute> - <xsl:attribute name = 'id'> - <xsl:value-of select = '@id'/> - </xsl:attribute> - <xsl:attribute name = "type"> - <xsl:value-of select = "@name"/> - </xsl:attribute> - <xsl:apply-templates/> - </xsl:element> - </xsl:template> - - <xsl:template match = "section/section/section/section/section"> - <xsl:element name = "div"> - <xsl:attribute name = 'rend'> - <xsl:text>5</xsl:text> - </xsl:attribute> - <xsl:attribute name = 'id'> - <xsl:value-of select = '@id'/> - </xsl:attribute> - <xsl:attribute name = "type"> - <xsl:value-of select = "@name"/> - </xsl:attribute> - <xsl:apply-templates/> - </xsl:element> - </xsl:template> - - <xsl:template match="section/title"> - <head> - <xsl:apply-templates/> - </head> - </xsl:template> - - <xsl:template match = 'reference'> - <xsl:element name = "ref"> - <xsl:attribute name = "target"> - <xsl:value-of select = "@refid"/> - </xsl:attribute> - <xsl:apply-templates/> - </xsl:element> - </xsl:template> - - <xsl:template match = 'target'> - <xsl:element name= "anchor"> - <xsl:attribute name = "id"> - <xsl:value-of select = "@id"/> - </xsl:attribute> - </xsl:element> - <xsl:apply-templates/> - </xsl:template> - - <xsl:template match = "instant"> - <dateline> - <date> - <xsl:value-of select = "substring(.,0,11)"/> - </date> - <xsl:element name = "time"> - <xsl:attribute name = "value"> - <xsl:value-of select = "substring(.,12,8)"/> - </xsl:attribute> - <xsl:attribute name = 'zone'> - <xsl:choose> - <xsl:when test = 'substring(normalize-space(.),20,6)'> - <xsl:value-of select = 'substring(normalize-space(.),20,6)'/> - </xsl:when> - <xsl:otherwise> - <xsl:text>-05:00</xsl:text> - </xsl:otherwise> - </xsl:choose> - </xsl:attribute> - <xsl:attribute name = "type"> - <xsl:text>24hour</xsl:text> - </xsl:attribute> - </xsl:element> - </dateline> - </xsl:template> - - <xsl:template name = "my-date"> - <xsl:element name = 'date'> - <xsl:attribute name = 'value'> - <xsl:value-of select = "substring(normalize-space(.),0,11)"/> - </xsl:attribute> - </xsl:element> - </xsl:template> - - <!--This is just and example of how to parse time?--> - <xsl:template name = "my-time"> - <test> - <xsl:value-of select='normalize-space(.)'/> - </test> - <xsl:element name = 'date'> - <xsl:attribute name = 'value'> - <xsl:value-of select = "substring(normalize-space(.),0,11)"/> - </xsl:attribute> - <xsl:attribute name = 'zone'> - <xsl:choose> - <xsl:when test = 'substring(normalize-space(.),12,13)'> - <xsl:value-of select = 'substring(normalize-space(.),12,5)'/> - </xsl:when> - <xsl:otherwise> - <xsl:text>-05:00</xsl:text> - </xsl:otherwise> - </xsl:choose> - </xsl:attribute> - <xsl:attribute name = "type"> - <xsl:text>24hour</xsl:text> - </xsl:attribute> - </xsl:element> - </xsl:template> - <xsl:template match = 'body'> - <text> - <body> - <xsl:apply-templates/> - </body> - </text> - </xsl:template> - - <xsl:template match = 'block_quote'> - <q rend = "block"> - <xsl:apply-templates/> - </q> - </xsl:template> - - <xsl:template match = "comment"> - <xsl:comment> - <xsl:value-of select = "."/> - </xsl:comment> - </xsl:template> - - <xsl:template match = "emphasis"> - <emph> - <xsl:apply-templates/> - </emph> - </xsl:template> - - <xsl:template match = "enumerated_list"> - <list type="ordered"> - <xsl:apply-templates/> - </list> - </xsl:template> - - <xsl:template match = "list_item"> - <item> - <xsl:apply-templates/> - </item> - </xsl:template> - - - <xsl:template match="@*|node()"> - <xsl:copy> - <xsl:apply-templates select="@*|node()"/> - </xsl:copy> - </xsl:template> - -</xsl:stylesheet> diff --git a/sandbox/paultremblay/rst_to_docbook/data/xslt_stylesheets/reStructure_to_docbook.xsl b/sandbox/paultremblay/rst_to_docbook/data/xslt_stylesheets/reStructure_to_docbook.xsl deleted file mode 100644 index ec76bdd03..000000000 --- a/sandbox/paultremblay/rst_to_docbook/data/xslt_stylesheets/reStructure_to_docbook.xsl +++ /dev/null @@ -1,387 +0,0 @@ -<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> - <!-- - - This template changed a XML document that has already been processed by docutils - with the filed names template to docbook. - - --> - - - <xsl:output method='xml' doctype-system='/home/paul/Documents/data/dtds/docbookx.dtd'/> - - - <xsl:template match = "document"> - <article> - <articleinfo> - <xsl:apply-templates select = "/document/docinfo/author"/> - <xsl:choose> - <xsl:when test='/document/title'> - <xsl:apply-templates select = '/document/title' mode = 'keep'/> - </xsl:when> - <xsl:when test = '/document/docinfo/title'> - <xsl:apply-templates select = '/document/docinfo/title'/> - </xsl:when> - </xsl:choose> - - - <xsl:if test = "/document/docinfo/revision"> - <revhistory> - <xsl:apply-templates select = "/document/docinfo/revision"/> - </revhistory> - </xsl:if> - - - </articleinfo> - <xsl:apply-templates/> - </article> - </xsl:template> - - - <xsl:template match = "/document/docinfo/author"> - <author> - <xsl:apply-templates/> - </author> - </xsl:template> - - <xsl:template match = "/document/docinfo/author/firstname|/document/docinfo/author/first"> - <firstname> - <xsl:apply-templates/> - </firstname> - </xsl:template> - - - <xsl:template match = "/document/docinfo/author/surname"> - <surname> - <xsl:apply-templates/> - </surname> - </xsl:template> - - <xsl:template match = "/document/docinfo/author/address|/document/docinfo/author/email"> - <email> - <xsl:apply-templates/> - </email> - </xsl:template> - - <xsl:template match = "/document/docinfo/author/firstname/paragraph|/document/docinfo/author/surname/paragraph|document/docinfo/author/address/paragraph|/document/docinfo/author/first/paragraph|/document/docinfo/author/email/paragraph|/document/docinfo/author/address/pararaph"> - <xsl:apply-templates/> - </xsl:template> - - - <xsl:template match = "/document/docinfo/author/email/paragraph/reference|/document/docinfo/author/address/reference"> - <xsl:apply-templates/> - </xsl:template> - - <xsl:template match = "/document/docinfo/revision"> - <revision> - <xsl:apply-templates/> - </revision> - </xsl:template> - - <xsl:template match = "revremark/paragraph"> - <xsl:apply-templates/> - </xsl:template> - - - - <!--info to delte--> - <xsl:template match = "docinfo"/> - <xsl:template match = "/document/title"/> - <xsl:template match = "system_message"/> - <xsl:template match = "literal"/> - <xsl:template match = "substitution_definition"/> - <xsl:template match = "transition"/> - <xsl:template match = "substitution_definition"/> - <xsl:template match = "system_warning"/> - - - <!--Info to get rid of paragraph tags--> - <xsl:template match = "p/paragraph|foreName/paragraph|surname/paragraph"> - <xsl:apply-templates/> - </xsl:template> - - <xsl:template match = "/document/docinfo/author"> - <author> - <xsl:apply-templates/> - </author> - </xsl:template> - - <xsl:template match = "/document/docinfo/revnumber"> - <revnumber> - <xsl:apply-templates/> - </revnumber> - </xsl:template> - - <xsl:template match = "/document/docinfo/revision/revnumber/paragraph"> - <xsl:apply-templates/> - </xsl:template> - - <xsl:template match = "/document/docinfo/revision/date"> - <date> - <xsl:apply-templates/> - </date> - </xsl:template> - - - <xsl:template match = "document/docinfo/revision/date/paragraph"> - <xsl:apply-templates/> - </xsl:template> - - <xsl:template match = "/document/docinfo/revision/date_bogus"> - <xsl:call-template name = 'my-date'/> - <!-- - <date> - <xsl:apply-templates/> - </date> - --> - <respStmt> - <resp>written by</resp> - <name> - Paul Tremblay - </name> - </respStmt> - </xsl:template> - <xsl:template match = "/document/docinfo/item"> - <item> - <xsl:apply-templates/> - </item> - </xsl:template> - - <xsl:template match = "paragraph"> - <xsl:choose> - <xsl:when test = "preceding-sibling::*[1]/self::transition"> - - <!-- - <xsl:when test = "name(preceding-sibling::*[1])='transition'"> - --> - <para role="transition"> - <xsl:apply-templates/> - </para> - </xsl:when> - <xsl:otherwise> - <para> - <xsl:apply-templates/> - </para> - </xsl:otherwise> - </xsl:choose> - </xsl:template> - - <xsl:template match = 'l/paragraph'> - <xsl:apply-templates/> - </xsl:template> - - <!--examples--> - - <xsl:template match = "example[@program]"> - <example> - <xsl:apply-templates/> - </example> - </xsl:template> - <xsl:template match = "example/title/paragraph"> - <xsl:apply-templates/> - </xsl:template> - - <xsl:template match = "example[@program]/literal_block"> - <programlisting> - <xsl:apply-templates/> - </programlisting> - </xsl:template> - - <xsl:template match = "literal_block"> - <literallayout> - <xsl:apply-templates/> - </literallayout> - </xsl:template> - - - <xsl:template match = "/document/docinfo/title|/document/title" mode = 'keep'> - <title> - <xsl:apply-templates/> - </title> - </xsl:template> - - <xsl:template match = "section"> - <xsl:element name = "sect1"> - <xsl:attribute name = 'id'> - <xsl:value-of select = '@id'/> - </xsl:attribute> - <xsl:apply-templates/> - </xsl:element> - </xsl:template> - - - <xsl:template match = "section/section"> - <xsl:element name = "sect2"> - <xsl:attribute name = 'id'> - <xsl:value-of select = '@id'/> - </xsl:attribute> - <xsl:attribute name = "type"> - <xsl:value-of select = "@name"/> - </xsl:attribute> - <xsl:apply-templates/> - </xsl:element> - </xsl:template> - - <xsl:template match = "section/section/section"> - <xsl:element name = "sect3"> - <xsl:attribute name = 'id'> - <xsl:value-of select = '@id'/> - </xsl:attribute> - <xsl:attribute name = "type"> - <xsl:value-of select = "@name"/> - </xsl:attribute> - <xsl:apply-templates/> - </xsl:element> - </xsl:template> - - <xsl:template match = "section/section/section/section"> - <xsl:element name = "sect4"> - <xsl:attribute name = 'id'> - <xsl:value-of select = '@id'/> - </xsl:attribute> - <xsl:attribute name = "type"> - <xsl:value-of select = "@name"/> - </xsl:attribute> - <xsl:apply-templates/> - </xsl:element> - </xsl:template> - - <xsl:template match = "section/section/section/section/section"> - <xsl:element name = "sect5"> - <xsl:attribute name = 'id'> - <xsl:value-of select = '@id'/> - </xsl:attribute> - <xsl:attribute name = "type"> - <xsl:value-of select = "@name"/> - </xsl:attribute> - <xsl:apply-templates/> - </xsl:element> - </xsl:template> - - <xsl:template match="section/title"> - <title> - <xsl:apply-templates/> - </title> - </xsl:template> - - <xsl:template match = 'reference'> - <xsl:element name = "ref"> - <xsl:attribute name = "target"> - <xsl:value-of select = "@refid"/> - </xsl:attribute> - <xsl:apply-templates/> - </xsl:element> - </xsl:template> - - <xsl:template match = 'target'> - <xsl:element name= "anchor"> - <xsl:attribute name = "id"> - <xsl:value-of select = "@id"/> - </xsl:attribute> - </xsl:element> - <xsl:apply-templates/> - </xsl:template> - - <xsl:template match = "instant"> - <dateline> - <date> - <xsl:value-of select = "substring(.,0,11)"/> - </date> - <xsl:element name = "time"> - <xsl:attribute name = "value"> - <xsl:value-of select = "substring(.,12,8)"/> - </xsl:attribute> - <xsl:attribute name = 'zone'> - <xsl:choose> - <xsl:when test = 'substring(normalize-space(.),20,6)'> - <xsl:value-of select = 'substring(normalize-space(.),20,6)'/> - </xsl:when> - <xsl:otherwise> - <xsl:text>-05:00</xsl:text> - </xsl:otherwise> - </xsl:choose> - </xsl:attribute> - <xsl:attribute name = "type"> - <xsl:text>24hour</xsl:text> - </xsl:attribute> - </xsl:element> - </dateline> - </xsl:template> - - <xsl:template name = "my-date"> - <xsl:element name = 'date'> - <xsl:attribute name = 'value'> - <xsl:value-of select = "substring(normalize-space(.),0,11)"/> - </xsl:attribute> - </xsl:element> - </xsl:template> - - <!--This is just and example of how to parse time?--> - <xsl:template name = "my-time"> - <test> - <xsl:value-of select='normalize-space(.)'/> - </test> - <xsl:element name = 'date'> - <xsl:attribute name = 'value'> - <xsl:value-of select = "substring(normalize-space(.),0,11)"/> - </xsl:attribute> - <xsl:attribute name = 'zone'> - <xsl:choose> - <xsl:when test = 'substring(normalize-space(.),12,13)'> - <xsl:value-of select = 'substring(normalize-space(.),12,5)'/> - </xsl:when> - <xsl:otherwise> - <xsl:text>-05:00</xsl:text> - </xsl:otherwise> - </xsl:choose> - </xsl:attribute> - <xsl:attribute name = "type"> - <xsl:text>24hour</xsl:text> - </xsl:attribute> - </xsl:element> - </xsl:template> - <xsl:template match = 'body'> - <text> - <body> - <xsl:apply-templates/> - </body> - </text> - </xsl:template> - - <xsl:template match = 'block_quote'> - <q rend = "block"> - <xsl:apply-templates/> - </q> - </xsl:template> - - <xsl:template match = "comment"> - <xsl:comment> - <xsl:value-of select = "."/> - </xsl:comment> - </xsl:template> - - <xsl:template match = "emphasis"> - <emph> - <xsl:apply-templates/> - </emph> - </xsl:template> - - <xsl:template match = "enumerated_list"> - <list type="ordered"> - <xsl:apply-templates/> - </list> - </xsl:template> - - <xsl:template match = "list_item"> - <item> - <xsl:apply-templates/> - </item> - </xsl:template> - - - <xsl:template match="@*|node()"> - <xsl:copy> - <xsl:apply-templates select="@*|node()"/> - </xsl:copy> - </xsl:template> - -</xsl:stylesheet> diff --git a/sandbox/paultremblay/rst_to_docbook/rst_to_docbook/__init__.py b/sandbox/paultremblay/rst_to_docbook/rst_to_docbook/__init__.py deleted file mode 100644 index b3d0c915b..000000000 --- a/sandbox/paultremblay/rst_to_docbook/rst_to_docbook/__init__.py +++ /dev/null @@ -1,3 +0,0 @@ -''' -modules for rtf2xml -''' diff --git a/sandbox/paultremblay/rst_to_docbook/rst_to_docbook/convert_rst_to_docbook.py b/sandbox/paultremblay/rst_to_docbook/rst_to_docbook/convert_rst_to_docbook.py deleted file mode 100644 index 6634d86af..000000000 --- a/sandbox/paultremblay/rst_to_docbook/rst_to_docbook/convert_rst_to_docbook.py +++ /dev/null @@ -1,194 +0,0 @@ -#!/usr/bin/env python - -# configure rst_2_dbk_dir by hand -configure_dir = '' - -import sys, os, tempfile, codecs -import docutils_nest.nest_utils -import docutils_nest.rst_options -import rst_to_docbook.xsl_convert, rst_to_docbook.location -import rst_to_docbook.read_config - -""" -Module for convert rst documents to docbook -""" - -# read input file - - - - - -class ConvertRstToDoc: - - def __init__(self, doc_debug = 0): - outer_dir = rst_to_docbook.location.get_location() - self.__rst_2_dbk_dir = os.path.join(outer_dir, '.rst_to_docbook') - config_file = os.path.join(self.__rst_2_dbk_dir, 'configure.xml') - self.__xslt_processor = self.__get_configs(config_file) - if doc_debug: - self.__setup_debug() - else: - self.__debug = 0 - - - - def __setup_debug(self): - self.__debug_dir = os.path.join(self.__rst_2_dbk_dir, 'debug') - if not (os.path.isdir(self.__debug_dir)): - os.mkdir(self.__debug_dir) - list_of_files = os.listdir(self.__debug_dir) - sys.stdout.write('Removing files from %s...\n' % self.__debug_dir) - for file in list_of_files: - file = os.path.join(self.__debug_dir, file) - sys.stdout.write('%s\n' % file) - os.remove(file) - self.__debug = 1 - - - def __get_configs(self, config_file): - config_obj = rst_to_docbook.read_config.Configure(config_file) - config_dict = config_obj.read_configs() - processor = config_dict.get('xslt-processor') - processor = processor[0] - return processor - - - def convert_to_docbook(self): - # get file, output, and the docutils_options - file, output, docutils_options = self.__handle_options() - docutils_nest_file = tempfile.mktemp() - main_temp_file = tempfile.mktemp() - self.__convert_to_nest_utils( file, - output = docutils_nest_file, - docutils_options = docutils_options) - self.__copy_file(docutils_nest_file, main_temp_file) - if self.__debug: - new_file = os.path.join(self.__debug_dir, 'converted_to_nest_utils_info') - self.__copy_file(docutils_nest_file, new_file) - - os.remove(docutils_nest_file) - - # convert with first xslt - converted_string_file = tempfile.mktemp() - self.__string_to_attributes(main_temp_file, converted_string_file) - self.__copy_file(converted_string_file, main_temp_file) - if self.__debug: - new_file = os.path.join(self.__debug_dir, 'converted_string_info') - self.__copy_file(converted_string_file, new_file) - os.remove(converted_string_file) - - # convert with second xslt - converted_arg_file = tempfile.mktemp() - self.__convert_args(main_temp_file, converted_arg_file) - self.__copy_file(converted_arg_file, main_temp_file) - if self.__debug: - new_file = os.path.join(self.__debug_dir, 'converted_to_args_info') - self.__copy_file(converted_arg_file, new_file) - os.remove(converted_arg_file) - - # final convert with xslt - docbook_file = tempfile.mktemp() - self.__xsl_convert_to_docbook(main_temp_file, docbook_file) - self.__copy_file(docbook_file, main_temp_file) - if self.__debug: - new_file = os.path.join(self.__debug_dir, 'converted_to_docbook_info') - self.__copy_file(docbook_file, new_file) - os.remove(docbook_file) - - # write to output - self.__copy_file(main_temp_file, output) - os.remove(main_temp_file) - - - def __handle_options(self): - options_dict = { - 'output': [1], - 'doc_debug': [], - } - opt_obj = docutils_nest.rst_options.OptionsRst(sys.argv, options_dict) - inline_opts, args, doc_opts = opt_obj.parse_options() - if inline_opts == 0: - self.__print_help_message() - sys.stderr.write('Script will now quite because of illegal options\n') - sys.exit(1) - try: - file = args[0] - except IndexError: - sys.stderr.write('You must provide a file for the script to convert.\n' - 'Script will now quit' - ) - sys.exit(1) - output = inline_opts.get('output') - if not output: - sys.stderr.write('You must provide an output option for the script to work\n' - 'Script will now quit\n' - ) - sys.exit(1) - return file, output, doc_opts - - def __convert_to_nest_utils(self, file, output, docutils_options): - - sys.stdout.write('converting to nest-utils.xml ...\n') - convert_obj = docutils_nest.nest_utils.RstWithInline(file, output, docutils_opts = docutils_options) - convert_obj.convert() - - def __string_to_attributes(self, file, output): - xsl_file = os.path.join(self.__rst_2_dbk_dir, - 'xslt_stylesheets', 'reStruct_field_names_tokenize.xsl' - ) - sys.stdout.write('converting string in nest-utils ' - 'with xslt...\n') - trans_obj = rst_to_docbook.xsl_convert.XslConvert(processor = self.__xslt_processor) - trans_obj.transform(file = file, - xsl_file = xsl_file, - output = output) - - def __convert_args(self, file, output): - xsl_file = os.path.join(self.__rst_2_dbk_dir, - 'xslt_stylesheets', 'reStruct_field_names.xsl' - ) - sys.stdout.write('converting args in nest-utils ' - 'with xslt...\n') - trans_obj = rst_to_docbook.xsl_convert.XslConvert(processor = self.__xslt_processor) - trans_obj.transform(file = file, - xsl_file = xsl_file, - output = output) - def __xsl_convert_to_docbook(self, file, output): - sys.stdout.write('doing final converstion with xslt...\n') - xsl_file = os.path.join(self.__rst_2_dbk_dir, - 'xslt_stylesheets', 'reStructure_to_docbook.xsl' - ) - # reStructure_to_docbook.xsl - trans_obj = rst_to_docbook.xsl_convert.XslConvert(processor = self.__xslt_processor) - trans_obj.transform(file = file, - xsl_file = xsl_file, - output = output) - - def __copy_file(self, file, output): - (utf8_encode, utf8_decode, utf8_reader, utf8_writer) = codecs.lookup("utf-8") - write_obj = utf8_writer(open(output, 'w')) - read_obj = open(file, 'r') - line = 1 - while line: - line = read_obj.readline() - write_obj.write(line) - read_obj.close() - write_obj.close() - - def __print_help_message(self): - sys.stderr.write('script will now quit') - sys.exit(1) - -if __name__ == '__main__': - if len(sys.argv) == 1: - file = '/home/paul/Documents/in_progress/cvs/sandbox/paultremblay/rst_to_docbook/test_files/test_simple.rst' - file = '/home/paul/Documents/in_progress/cvs/sandbox/paultremblay/rst_to_docbook/test_files/reStructure_docbook_example.rst' - sys.argv.append('--indents') - sys.argv.append('--doc_debug') - sys.argv.append('--output') - sys.argv.append('output.xml') - sys.argv.append('%s' % file) - test_obj = ConvertRstToDoc(doc_debug = 1) - test_obj.convert_to_docbook() - diff --git a/sandbox/paultremblay/rst_to_docbook/rst_to_docbook/location.py b/sandbox/paultremblay/rst_to_docbook/rst_to_docbook/location.py deleted file mode 100644 index c74dd5ecf..000000000 --- a/sandbox/paultremblay/rst_to_docbook/rst_to_docbook/location.py +++ /dev/null @@ -1,6 +0,0 @@ - -def get_location(): - return '/etc' - - -
\ No newline at end of file diff --git a/sandbox/paultremblay/rst_to_docbook/rst_to_docbook/options_trem.py b/sandbox/paultremblay/rst_to_docbook/rst_to_docbook/options_trem.py deleted file mode 100644 index 7176b165d..000000000 --- a/sandbox/paultremblay/rst_to_docbook/rst_to_docbook/options_trem.py +++ /dev/null @@ -1,387 +0,0 @@ -# WARNING TO PAUL: DON'T EDIT THIS FILE use update.py instead. -import sys -class ParseOptions: - - """ - - Requires: - - system_string --The string from the command line - - options_dict -- a dictionary with the key equal to the opition, and - a list describing that option. (See below) - - - Returns: - - A tupple. The first item in the tupple is a dictionary containing - the arguments for each options. The second is a list of the - arguments. - - If invalid options are passed to the module, 0,0 is returned. - - Examples: - - Your script has the option '--indents', and '--output=file'. - - You want to give short option names as well: - - --i and -o=file - - Use this: - - options_dict = {'output': [1, 'o'], - 'indents': [0, 'i'] - } - - options_obj = ParseOptions( - system_string = sys.argv, - options_dict = options_dict - ) - - options, arguments = options_obj.parse_options() - print options - print arguments - - The result will be: - - - {indents:None, output:'/home/paul/file'}, ['/home/paul/input'] - - - """ - def __init__(self, system_string, options_dict): - self.__system_string = system_string[1:] - long_list = self.__make_long_list_func(options_dict) - # # print long_list - short_list = self.__make_short_list_func(options_dict) - # # print short_list - self.__legal_options = long_list + short_list - # # print self.__legal_options - self.__short_long_dict = self.__make_short_long_dict_func(options_dict) - # # print self.__short_long_dict - self.__opt_with_args = self.__make_options_with_arg_list(options_dict) - # # print self.__opt_with_args - self.__options_okay = 1 - - - - def __make_long_list_func(self, options_dict): - """ - Required: - - options_dict -- the dictionary mapping options to a list - - Returns: - - a list of legal options - - - - - """ - legal_list = [] - keys = options_dict.keys() - for key in keys: - key = '--' + key - legal_list.append(key) - return legal_list - - def __make_short_list_func(self, options_dict): - """ - Required: - - options_dict --the dictionary mapping options to a list - - Returns: - - a list of legal short options - - """ - legal_list = [] - keys = options_dict.keys() - for key in keys: - values = options_dict[key] - try: - legal_list.append('-' + values[1]) - except IndexError: - pass - - return legal_list - - - - def __make_short_long_dict_func(self, options_dict): - """ - Required: - - options_dict --the dictionary mapping options to a list - - Returns: - - a dictionary with keys of short options and values of long options - - """ - short_long_dict = {} - keys = options_dict.keys() - for key in keys: - values = options_dict[key] - try: - short = '-' + values[1] - long = '--' + key - short_long_dict[short] = long - except IndexError: - pass - - return short_long_dict - - def __make_options_with_arg_list(self, options_dict): - """ - Required: - - options_dict --the dictionary mapping options to a list - - Returns: - - a list of options that take arguments. - - """ - opt_with_arg = [] - keys = options_dict.keys() - for key in keys: - values = options_dict[key] - try: - if values[0]: - opt_with_arg.append('--' + key) - except IndexError: - pass - - return opt_with_arg - - - def __sub_short_with_long(self): - """ - Required: - - nothing - - Returns: - - a new system string - - Logic: - - iterate through the system string and replace short options with long options - - - """ - new_string = [] - sub_list = self.__short_long_dict.keys() - for item in self.__system_string: - if item in sub_list: - item = self.__short_long_dict[item] - new_string.append(item) - return new_string - - - - def __pair_arg_with_option(self): - - """ - - Required: - - nothing - - Returns - - nothing (changes value of self.__system_string) - - Logic: - - iterate through the system string, and match arguments with options: - - old_list = ['--foo', 'bar'] - - new_list = ['--foo=bar' - - """ - opt_len = len(self.__system_string) - new_system_string = [] - counter = 0 - slurp_value = 0 - for arg in self.__system_string: - - # previous value was an option with an argument, so this arg is - # actually an argument that has already been added - counter += 1 - if slurp_value: - slurp_value = 0 - continue - - # not an option--an argument - if arg[0] != '-': - new_system_string.append(arg) - - # option and argument already paired - elif '=' in arg: - new_system_string .append(arg) - else: - # this option takes an argument - if arg in self.__opt_with_args: - # option is the last in the list - if counter + 1 > opt_len: - sys.stderr.write('option "%s" must take an argument\n' % arg) - new_system_string.append(arg) - self.__options_okay = 0 - else: - # the next item in list is also an option - if self.__system_string[counter][0] == '-': - sys.stderr.write('option "%s" must take an argument\n' % arg) - new_system_string.append(arg) - self.__options_okay = 0 - # the next item in the list is the argument - else: - new_system_string.append(arg + '=' + self.__system_string[counter]) - slurp_value = 1 - # this option does not take an argument - else: - new_system_string.append(arg) - return new_system_string - - - def __get_just_options(self): - - """ - - Requires: - - nothing - - Returns: - - list of options - - Logic: - - Iterate through the self.__system string, looking for the last - option. The options are everything in the sysem string before the - last option. - - Check to see that the options contain no arguments. - - - """ - highest = 0 - counter = 0 - found_options = 0 - for item in self.__system_string: - if item[0] == '-': - highest = counter - found_options = 1 - counter += 1 - - if found_options: - just_options = self.__system_string[:highest + 1] - arguments = self.__system_string[highest + 1:] - else: - just_options = [] - arguments = self.__system_string - - if found_options: - for item in just_options: - if item[0] != '-': - sys.stderr.write('%s is an argument in an option list\n' % item) - self.__options_okay = 0 - return just_options, arguments - - - def __is_legal_option_func(self): - - """ - Requires: - - nothing - - Returns: - - nothing - - Logic: - - Check each value in the newly creatd options list to see if it - matches what the user describes as a legal option. - - - """ - illegal_options = [] - for arg in self.__system_string: - if '=' in arg: - temp_list = arg.split('=') - arg = temp_list[0] - if arg not in self.__legal_options and arg[0] == '-': - illegal_options.append(arg) - - if illegal_options: - self.__options_okay = 0 - sys.stderr.write('The following options are not permitted:\n') - for not_legal in illegal_options: - sys.stderr.write('%s\n' % not_legal) - - - def __make_options_dict(self, options): - options_dict = {} - for item in options: - if '=' in item: - option, arg = item.split('=') - else: - option = item - arg = None - - if option[0] == '-': - option = option[1:] - if option[0] == '-': - option = option[1:] - - options_dict[option] = arg - - return options_dict - - def parse_options(self): - self.__system_string = self.__sub_short_with_long() - # # print 'subbed list is %s' % self.__system_string - self.__system_string = self.__pair_arg_with_option() - # # print 'list with pairing is %s' % self.__system_string - options, arguments = self.__get_just_options() - # # print 'options are %s ' % options - # # print 'arguments are %s ' % arguments - self.__is_legal_option_func() - if self.__options_okay: - options_dict = self.__make_options_dict(options) - # # print options_dict - return options_dict, arguments - - else: - return 0,0 - - - - -if __name__ == '__main__': - this_dict = { - 'indents': [0, 'i'], - 'output': [1, 'o'], - 'test3': [1, 't'], - } - test_obj = ParseOptions(system_string = sys.argv, - options_dict = this_dict - ) - - options, the_args = test_obj.parse_options() - print options, the_args - - """ - this_options = ['--foo', '-o'] - this_opt_with_args = ['--foo'] - - """ diff --git a/sandbox/paultremblay/rst_to_docbook/rst_to_docbook/output.xml b/sandbox/paultremblay/rst_to_docbook/rst_to_docbook/output.xml deleted file mode 100644 index 222f109c0..000000000 --- a/sandbox/paultremblay/rst_to_docbook/rst_to_docbook/output.xml +++ /dev/null @@ -1,93 +0,0 @@ -<?xml version="1.0"?> -<!DOCTYPE TEI.2 SYSTEM "/home/paul/Documents/data/dtds/docbookx.dtd"> -<TEI.2><teiHeader><fileDesc><titleStmt><title> - Example of reStructure document that can be converted to docbook - </title><author> - - - - <first> - - - <p> - Paul - </p> - - </first> - <surname> - - - - Tremblay - - - </surname> - <email> - - - <p> - <ref target=""> - phthenry@earthlink.net - </ref> - </p> - - </email> - - - - </author></titleStmt><publicationStmt><distributor> - none - </distributor></publicationStmt><sourceDesc><p>no source--a manuscript</p></sourceDesc></fileDesc></teiHeader><text><body> - - - <!-- - author: Paul Tremblay Won't work like that - --> - <!-- - start body - --> - <div rend="1" id="using-snippets-of-code" type="using snippets of code"> - <head> - Using snippets of code - </head> - <p> - How to represent a snippet of code: - </p> - - <example program=""> - - - - <title> - - - <p> - Processing a variable - </p> - - </title> - - <literal_block xml:space="preserve"> - if var = 5 - self.__process(var) - </literal_block> - - </example> - - <p> - Keep in mind that the docbook should look like: - </p> - <literal_block xml:space="preserve"> - <example> - <title>A formal example</title> - <programlisting> - if var = 5 - self.__process(var) - </programlisting> -</example> - </literal_block> - <!-- - end of example - --> - </div> -</body></text></TEI.2> diff --git a/sandbox/paultremblay/rst_to_docbook/rst_to_docbook/read_config.py b/sandbox/paultremblay/rst_to_docbook/rst_to_docbook/read_config.py deleted file mode 100644 index 187ab1a48..000000000 --- a/sandbox/paultremblay/rst_to_docbook/rst_to_docbook/read_config.py +++ /dev/null @@ -1,131 +0,0 @@ -import os, re, sys, codecs - -import xml.sax.saxutils -import xml.sax - -# turn on this line if you want to disablenamespaces -##from xml.sax.handler import feature_namespaces - -config_values = {} - - - -class ConfigHandler(xml.sax.saxutils.DefaultHandler): - """ - - Class for handling the XML file. SAX uses the methods in this class to - handle the data. - - - """ - def __init__(self): - - """ - - - Requires: - - - Returns: - - nothing - - - Logic: - - - """ - self.__allowed = [ 'configuration', 'xslt-processor', ] - - - - def startElement(self, name, attrs): - """ - - Logic: - - The SAX driver uses this function when if finds a beginning tag. - - - - """ - if name in self.__allowed: - values = attrs.values() - config_values[name] = values - - else: - sys.stderr.write('%s not a valid option\n' % name) - - - def characters(self, character): - """ - - Logic: - - The SAX driver uses this function when it finds text. - - """ - pass - - - - def endElement(self, name): - """ - - Logic: - - - """ - - pass - - - - -class Configure: - - def __init__(self, file): - - - """ - - - Requires: - - - - Returns: - - - Logic: - - Set up a write object. - - Create an instance of the InlineHandler for sax to use. - - Pass this instance to the SAX driver. - - Use the SAX driver to handle the file. - - - """ - file_exists = os.path.exists(file) - if not file_exists: - raise IOError, 'file %s does not exist' % file - self.__file = file - - def read_configs(self): - parser = xml.sax.make_parser() - # turn on this line if you want to disable namespaces - ##parser.setFeature(feature_namespaces, 0) - config_handler = ConfigHandler() - parser.setContentHandler(config_handler) - parser.parse(self.__file) - return config_values - - - -if __name__ == '__main__': - file = '/home/paul/docutils-extensions/configure.xml' - obj = Configure(file) - obj.read_configs() diff --git a/sandbox/paultremblay/rst_to_docbook/rst_to_docbook/xsl_convert.py b/sandbox/paultremblay/rst_to_docbook/rst_to_docbook/xsl_convert.py deleted file mode 100644 index 3fba134a3..000000000 --- a/sandbox/paultremblay/rst_to_docbook/rst_to_docbook/xsl_convert.py +++ /dev/null @@ -1,145 +0,0 @@ -# WARNING TO PAUL: DON'T EDIT THIS FILE use update.py instead. -import sys, os, tempfile - - - - -""" - - -""" - - -class XslConvert: - - def __init__(self, processor = 'xsltproc'): - - """ - - - - """ - self.__determine_processor(processor) - - - - def __determine_processor(self, processor): - if processor == 'xsltproc' or processor == 'xmllint': - self.__processor = 'xmllint' - elif processor == '4suite': - self.__processor = '4suite' - elif processor == 'xalan': - self.__processor = 'xalan' - else: - sys.stderr.write('%s not a valid processor choice\n' % processor) - sys.exit(1) - - def transform(self, file, xsl_file, output, params = {}): - """ - Requires: - - file -- the file to parse - - xsl_file --the xsl style sheet - - Returns: - - nothing - - Logic: - - Check for the existence of the files and the stylesheet. Determine - the processor to be used, and let the othe methods do the processing. - - """ - - if not (os.path.exists(file)): - sys.stderr.write('"%s" does not exist\n' % file) - sys.exit(1) - if not (os.path.exists(xsl_file)): - sys.stderr.write('"%s" does not exist\n' % xsl_file) - sys.exit(1) - - if self.__processor == 'xmllint': - self.__transform_xmllint(file, xsl_file, output, params) - if self.__processor == 'xalan': - self.__transform_xalan(file, xsl_file, output, params) - - elif self.__processor == '4suite': - self.__transform_4suite(file, xsl_file, output, params) - - def __transform_xmllint(self, file, xsl_file, output, params = {}): - import libxml2 - import libxslt - - new_params = {} - keys = params.keys() - for key in keys: - new_params[key] = '"%s"' % params[key] - params = new_params - - - - xml_doc = file - # parse stylesheet - styledoc = libxml2.parseFile(xsl_file) - style = libxslt.parseStylesheetDoc(styledoc) - # parse doc - doc = libxml2.parseFile(xml_doc) - result = style.applyStylesheet(doc, params) - style.saveResultToFilename(output, result, 0) - style.freeStylesheet() - doc.freeDoc() - result.freeDoc() - - - - def __transform_4suite(self, file, xsl_file, output, params): - - import codecs - from Ft.Xml import InputSource - from Ft.Xml.Xslt.Processor import Processor - - document = InputSource.DefaultFactory.fromUri(file) - stylesheet = InputSource.DefaultFactory.fromUri(xsl_file) - # there's also a fromString() method - - processor = Processor() - processor.appendStylesheet(stylesheet) - result = processor.run(document, topLevelParams=params) - (utf8_encode, utf8_decode, utf8_reader, utf8_writer) = codecs.lookup("utf-8") - write_obj = utf8_writer(open(output, 'w')) - write_obj.write(result) - write_obj.close() - - def __transform_xalan(self, file, xsl_file, output, params): - command = 'java org.apache.xalan.xslt.Process \ - -Ts -in %s -xsl %s -out %s' % (file, xsl_file, output) - - param_string = '' - keys = params.keys() - for key in keys: - param_string += ' %s "%s"' % (key, params[key]) - - command += ' -PARAM %s' % param_string - print command - os.system(command) - - - -if __name__ == '__main__': - test_xml_dir = '/home/paul/lib/python/xml_tools_trem/test_files/xml_files' - test_xsl_dir = '/home/paul/lib/python/xml_tools_trem/test_files/xsl_stylesheets' - output_dir = '/home/paul/paultemp' - - file = 'simple.xml' - xsl_file = 'simple1.xsl' - output = 'output.xml' - - - test_file = os.path.join(test_xml_dir, file) - test_xsl = os.path.join(test_xsl_dir, xsl_file) - test_output = os.path.join(output_dir, output) - - test_obj = XslConvert('xalan') - test_obj.transform (test_file, test_xsl, test_output, params = {'test-param': 'changed in xalan'}) diff --git a/sandbox/paultremblay/rst_to_docbook/scripts/rst2docbook.py b/sandbox/paultremblay/rst_to_docbook/scripts/rst2docbook.py deleted file mode 100644 index ccc52fa15..000000000 --- a/sandbox/paultremblay/rst_to_docbook/scripts/rst2docbook.py +++ /dev/null @@ -1,25 +0,0 @@ -#!/usr/bin/env python -import sys, os -import rst_to_docbook.convert_rst_to_docbook -import rst_to_docbook.options_trem - -class Convert: - - def __init__(self): - pass - - def convert(self): - debug_doc = self.__parse_options() - - convert_obj = rst_to_docbook.convert_rst_to_docbook.ConvertRstToDoc(doc_debug = debug_doc) - convert_obj.convert_to_docbook() - - def __parse_options(self): - if '--debug-doc' in sys.argv: - sys.argv.remove('--debug-doc') - return 1 - return 0 - -if __name__ == '__main__': - execute_obj = Convert() - execute_obj.convert() diff --git a/sandbox/paultremblay/rst_to_docbook/setup.py b/sandbox/paultremblay/rst_to_docbook/setup.py deleted file mode 100644 index 4a93d0880..000000000 --- a/sandbox/paultremblay/rst_to_docbook/setup.py +++ /dev/null @@ -1,44 +0,0 @@ -#!/usr/bin/env python -import sys, os -from distutils.core import setup - -from distutils.core import setup - - -# get the location for the data -var_file_exists = os.path.isfile('var_file') -if not var_file_exists: - sys.stderr.write('Please run python configure.py first\n') - sys.exit(1) -read_obj = open('var_file', 'r') -lines = read_obj.readlines() -data_location = lines[0] -data_xslt_location = os.path.join(data_location, '.rst_to_docbook', 'xslt_stylesheets') -data_config_location = os.path.join(data_location, '.rst_to_docbook') -read_obj.close() - - - -setup(name="rst_to_docbook", - version=".1", - description="convert rst to docbook.", - author="Paul Tremblay", - author_email="phthenry@earthlink.net", - packages=['rst_to_docbook'], - data_files = [(data_xslt_location, - [ - 'data/xslt_stylesheets/reStruct_field_names_tokenize.xsl', - 'data/xslt_stylesheets/reStruct_field_names.xsl', - 'data/xslt_stylesheets/reStruct_to_docbook.xsl', - 'data/xslt_stylesheets/reStructure_to_docbook.xsl' - ] - ), - (data_config_location, ['data/configure']) - - ], - scripts=["scripts/rst2docbook.py"], - ) - -## os.remove('var_file') - - diff --git a/sandbox/paultremblay/rst_to_docbook/test_files/reStructure_docbook_example.rst b/sandbox/paultremblay/rst_to_docbook/test_files/reStructure_docbook_example.rst deleted file mode 100644 index 304f8f4ab..000000000 --- a/sandbox/paultremblay/rst_to_docbook/test_files/reStructure_docbook_example.rst +++ /dev/null @@ -1,65 +0,0 @@ -.. WARNING TO PAUL: DON'T EDIT THIS FILE use update.py instead. -Example of reStructure document that can be converted to docbook -^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -.. author: Paul Tremblay Won't work like that - -:author: - - :first: Paul - - :surname: Tremblay - - :email: phthenry@earthlink.net - - -:revision: - - :revnumber: 01 - - :date: 2003-04-24 - - :revremark: When I first started writing this document. - -:revision: - - :revnumber: 02 - - :date: 2003-05-01 - - :revremark: Made the following changes - -.. start body - -======================== -Using snippets of code -======================== - -How to represent a snippet of code: - -:example program: - - :title: Processing a variable - - :: - - if var = 5 - self.__process(var) - - -Keep in mind that the docbook should look like: - -:: - - <example> - <title>A formal example</title> - <programlisting> - if var = 5 - self.__process(var) - </programlisting> - </example> - -.. end of example - - - diff --git a/sandbox/paultremblay/rst_to_docbook/test_files/simple.xml b/sandbox/paultremblay/rst_to_docbook/test_files/simple.xml deleted file mode 100644 index 16b68e755..000000000 --- a/sandbox/paultremblay/rst_to_docbook/test_files/simple.xml +++ /dev/null @@ -1,3 +0,0 @@ -<doc> - <element1>text</element1> -</doc> diff --git a/sandbox/paultremblay/rst_to_docbook/test_files/simple.xsl b/sandbox/paultremblay/rst_to_docbook/test_files/simple.xsl deleted file mode 100644 index 8e15469c1..000000000 --- a/sandbox/paultremblay/rst_to_docbook/test_files/simple.xsl +++ /dev/null @@ -1,18 +0,0 @@ -<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> - <!-- - - This template is a simple test - - - --> - - - - - <xsl:template match = "element1"> - <element1-changed> - <xsl:apply-templates/> - </element1-changed> - </xsl:template> - -</xsl:stylesheet> diff --git a/sandbox/paultremblay/rst_to_docbook/test_files/test_simple.rst b/sandbox/paultremblay/rst_to_docbook/test_files/test_simple.rst deleted file mode 100644 index c314721ba..000000000 --- a/sandbox/paultremblay/rst_to_docbook/test_files/test_simple.rst +++ /dev/null @@ -1,11 +0,0 @@ -.. simple test file - -:author: Paul Tremblay - -Main body - -:custom-field arg1 arg2: - - body of block custom field - - more body [:role arg1 arg2: inline [:role2 arg1 arg2: more inline]] last of body |