removed obsolete issues (many of them fixed with AE)
[docutils.git] / sandbox / paultremblay / docutils_nest / docutils_nest / nest_docutils.py
blob61941fbb12d0d68d9e2366eb27c19b897c528484
1 #!/usr/bin/env python
2 import sys, os
3 import docutils_nest.nested_inline
4 import docutils_nest.read_config
5 import docutils_nest.options_trem
6 import docutils_nest.location
8 """
9 converst an XML file to nested tags
12 """
13 outer_dir = docutils_nest.location.get_location()
14 doc_nest_dir = os.path.join(outer_dir, '.docutils_nest')
17 class GetOptions:
18 def __init__(self, sys_string):
19 self.__sys_string = sys_string
21 def get_options(self):
22 options_dict = {
23 'output': [1,'o']
25 options_obj = docutils_nest.options_trem.ParseOptions(
26 system_string = self.__sys_string,
27 options_dict = options_dict,
30 options, arguments = options_obj.parse_options()
31 output = ''
32 file = ''
33 if options == 0:
34 sys.stderr.write('Script will quit because of invalid options')
35 sys.exit(1)
36 output = options.get('output')
38 if not output:
39 sys.stderr.write('must provide output for script to work\n')
40 sys.exit(1)
41 if arguments:
42 file = arguments[0]
44 if not file:
45 sys.stderr.write('must provide a file for script to work\n')
46 sys.exit(1)
48 return file, output
50 class GetConfig:
52 def __init__(self, file):
53 self.__file = file
55 def get_config(self):
56 config_obj = docutils_nest.read_config.Configure(self.__file)
57 config_values = config_obj.read_configs()
58 return config_values
60 class MakeTags:
61 def __init__( self,
62 file,
63 output,
64 config_values
67 self.__file = file
68 self.__output = output
69 self.__start_role = config_values.get('start_role')
70 self.__end_role = config_values.get('end_role')
71 self.__start_group = config_values.get('start_group')
72 self.__end_group = config_values.get('end_group')
73 self.__place_of_role = config_values.get('place_of_role')
74 self.__tag_name = config_values.get('tag_name')
75 self.__warning = config_values.get('warning')
77 def make_tags(self):
78 convert_obj = docutils_nest.nested_inline.InlineBrackets(
79 file = self.__file,
80 output = self.__output,
81 start_role = self.__start_role,
82 end_role = self.__end_role,
83 start_group = self.__start_group,
84 end_group = self.__end_group,
85 place = self.__place_of_role,
86 tag_name = self.__tag_name,
87 warning = self.__warning
89 convert_obj.make_tags()
94 class NestDocutils:
96 def __init__(self, file, output):
97 self.__file = file
98 self.__output = output
100 def nest_tags(self):
101 config_file = os.path.join(doc_nest_dir, 'configure.xml')
102 config_obj = GetConfig(config_file)
103 config_values = config_obj.get_config()
104 tags_obj = MakeTags(self.__file, self.__output, config_values)
105 tags_obj.make_tags()
107 if __name__ == '__main__':
109 # file = '/home/paul/lib/python/paul/restructure_tools/test_inline.xml'
110 # output = '/home/paul/paultemp/brackets_to_tags.temp.xml'
111 # nest_obj = NestDocutils(file, output)
112 # nest_obj.nest_tags()
113 # sys.exit(0)
114 options_obj = GetOptions(sys.argv)
115 file, output = options_obj.get_options()
116 config_file = os.path.join(doc_nest_dir, 'configure.xml')
117 config_obj = GetConfig(config_file)
118 config_values = config_obj.get_config()
119 tags_obj = MakeTags(file, output, config_values)
120 tags_obj.make_tags()
121 command = 'xmlvalid -c -v %s' % output
122 os.system(command)