removed obsolete issues (many of them fixed with AE)
[docutils.git] / sandbox / paultremblay / docutils_nest / configure.py
blobbaa44d3c16304f5c0e32c577649af01154afa0a9
2 # /usr/bin/env python
4 import sys, os
5 import docutils_nest.options_trem
7 """
9 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.
11 """
13 def configure():
14 target = get_target()
15 make_var_file(target)
16 make_location(target)
18 def get_target():
19 """
20 This functions uses a module I wrote to parse options. If no options are
21 determined on the command line, the function returnst the default
22 /etc/nest_docutis
24 """
25 options_dict = {
26 'target': [1, 't'],
28 options_obj = docutils_nest.options_trem.ParseOptions(sys.argv,
29 options_dict)
30 opt_dict, args = options_obj.parse_options()
31 if opt_dict == 0:
32 sys.stderr.write('invalid way to run configure:\n'
33 'python configure.py --target <directory of choice>'
35 sys.exit(1)
36 target = opt_dict.get('target')
37 if not target:
38 target = default_target()
39 return target
41 def default_target():
42 sys.stdout.write('using default /etc for configuration directory\n')
43 return '/etc'
45 def make_var_file(target):
46 write_obj = open('var_file', 'w')
47 # write_obj.write('[global]\n')
48 write_obj.write(target)
49 write_obj.close()
51 def make_location(target):
52 write_obj = open('docutils_nest/location.py', 'w')
53 write_obj.write(
54 """
55 def get_location():
56 return '%s'
59 """
60 % target)
63 if __name__ == '__main__':
64 configure()
70 """
71 # /usr/bin/env python
73 import sys, os
74 import options_trem
77 def configure():
78 target = get_target()
79 change_setup(target)
80 change_script(target)
82 def get_target():
83 options_dict = {
84 'target': [1, 't'],
86 options_obj = options_trem.ParseOptions(sys.argv,
87 options_dict)
88 opt_dict, args = options_obj.parse_options()
89 if opt_dict == 0:
90 sys.stdout.write('Will use the default configuration of /etc/nest_docutils\n')
91 return '/etc/docutils_nest'
92 target = opt_dict.get('target')
93 if not target:
94 return '/etc/docutils_nest'
95 return target
97 def change_setup(target):
98 read_obj = open('setup.py', 'r')
99 write_obj = open('temp', 'w')
100 line = 1
101 while line:
102 line = read_obj.readline()
103 index = line.find('data_files=')
104 if index > -1:
105 write_obj.write('data_files = [("%s", ["data/configure.xml"])],\n' % target)
106 else:
107 write_obj.write(line)
108 read_obj.close()
109 write_obj.close()
110 read_obj = open('temp', 'r')
111 write_obj = open('setup.py', 'w')
112 line = 1
113 while line:
114 line = read_obj.readline()
115 write_obj.write(line)
116 read_obj.close()
117 write_obj.close()
120 def change_script(target):
122 read_obj = open('docutils_nest/nest_docutils.py', 'r')
123 write_obj = open('temp', 'w')
124 line = 1
125 while line:
126 line = read_obj.readline()
127 index = line.find('$configure$')
128 if index > -1:
129 write_obj.write("ext_location = '%s' # $configure$" % \
130 target)
131 else:
132 write_obj.write(line)
133 read_obj.close()
134 write_obj.close()
135 read_obj = open('temp', 'r')
136 write_obj = open('docutils_nest/nest_docutils.py', 'w')
137 line = 1
138 while line:
139 line = read_obj.readline()
140 write_obj.write(line)
141 read_obj.close()
142 write_obj.close()
144 if __name__ == '__main__':
145 configure()