removed obsolete issues (many of them fixed with AE)
[docutils.git] / sandbox / paultremblay / rst_to_docbook / configure.py
blob41070820bc57061273d50df96de66868e9bf0cec
1 # /usr/bin/env python
3 import sys, os
4 import rst_to_docbook.options_trem
6 """
8 The configuration script gets the target from the command line. It creates a
9 file with the configuration variable, and a short script for the rest of
10 script to be able to read and locate he configuration files.
12 """
14 def configure():
15 target, processor = get_target()
16 if processor == None:
17 sys.stderr.write('Since you need an xslt processor to run this script, the configuration will now quit\n'
19 try:
20 os.remove('var_file')
21 except:
22 pass
23 sys.exit(1)
24 make_var_file(target)
25 make_location(target)
26 make_configuration_file(processor)
28 def get_target():
29 """
30 This functions uses a module I wrote to parse options. If no options are
31 determined on the command line, the function returnst the default
32 /etc/nest_docutis
34 """
35 options_dict = {
36 'target': [1, 't'],
37 'processor': [1, 'p'],
39 options_obj = rst_to_docbook.options_trem.ParseOptions(sys.argv,
40 options_dict)
41 opt_dict, args = options_obj.parse_options()
42 if opt_dict == 0:
43 sys.stderr.write('invalid options for configure.py\n'
44 'use python configure --target <desired folder>'
45 ' --processor <xslt proccessor>'
48 sys.exit(1)
49 target = opt_dict.get('target')
50 if not target:
51 target = default_target()
52 processor = opt_dict.get('processor')
53 processor = determine_processor(processor)
54 return target, processor
56 def default_target():
57 sys.stdout.write('using default \'/etc\' for the configuration directory\n')
58 return '/etc'
60 def determine_processor(processor = None):
61 sys.stdout.write('determining xslt processor...\n')
62 if processor == None:
63 processor = 'xmllint'
64 if processor == 'xalan':
65 file = 'test_files/simple.xml'
66 xsl_file = 'test_files/simple.xsl'
67 output = 'output.xml'
68 command = 'java org.apache.xalan.xslt.Process \
69 -Ts -in %s -xsl %s -out %s' % (file, xsl_file, output)
70 error = os.system(command)
71 if error:
72 sys.stderr.write('xalan does not appear to be set up correctly '
73 ' on your system\n'
74 'The command "java org.apache.xalan.xslt.Process" failed\n'
75 'Is the CLASSPATH set for xalan?\n'
76 'Configuraton will now quit\n'
78 sys.exit(1)
79 else:
80 return 'xalan'
81 elif processor == '4suite':
82 try:
83 from Ft.Xml import InputSource
84 from Ft.Xml.Xslt.Processor import Processor
85 return '4suite'
86 except:
87 sys.stderr.write('4suite does not appear to be set up correctly on your system\n'
88 'Could not find the Ft.Xml libraries\n'
89 'Script cannot work without an xslt procesor!\n'
91 sys.exit(1)
92 elif processor == 'xsltproc' or processor == 'xmllint':
93 try:
94 import libxml2
95 import libxslt
96 return 'xmllint'
97 except:
98 sys.stderr.write('You either choose xmllint as your processor, or xmllint was tested because not other\n'
99 'processor was found\n'
100 'However, the libraries "libxml2" and or "libxslt" cannot be found.\n'
103 else:
104 sys.stderr.write('The processor "%s" is not a valid choice for this script\n' % processor)
105 return None
110 def make_var_file(target):
111 write_obj = open('var_file', 'w')
112 # write_obj.write('[global]\n')
113 write_obj.write(target)
114 write_obj.close()
116 def make_location(target):
117 write_obj = open('rst_to_docbook/location.py', 'w')
118 write_obj.write(
120 def get_location():
121 return '%s'
125 % target)
127 def make_configuration_file(processor):
128 write_obj = open('data/configure.xml', 'w')
129 write_obj.write("""
130 <configuration>
131 <xslt-processor processor = "%s"/>
132 </configuration>
133 """ % processor
136 if __name__ == '__main__':
137 configure()