29 |
|
|
30 |
__docformat__ = 'reStructuredText' |
__docformat__ = 'reStructuredText' |
31 |
|
|
32 |
|
""" |
33 |
|
The main frontend for running Navidoc. |
34 |
|
""" |
35 |
|
|
36 |
import config |
import config |
37 |
config.read_config(config, config.navidoc_conf) |
config.read_config(config, config.navidoc_conf) |
38 |
|
|
39 |
import sys, os, getopt |
import sys, os, getopt |
|
import docutils.core |
|
40 |
|
|
41 |
|
import docutils.core |
42 |
|
|
43 |
import navidoc.directives |
import navidoc.directives |
|
import navidoc.writers |
|
|
import navidoc.languages |
|
|
import navidoc.transforms |
|
44 |
import navidoc.modules |
import navidoc.modules |
45 |
|
|
46 |
from navidoc.util.path import * |
from navidoc.util.path import * |
47 |
|
|
48 |
# imports parser "plugins" |
# Import parser "plugins" from 'navidoc/link' and 'navidoc/mp' |
49 |
config.mp_includes = listdir('navidoc/mp',['mp'],dirs=0) |
config.mp_includes = listdir('navidoc/mp',['mp'],dirs=0) |
50 |
dirlist = listdir('navidoc/mp',['py'],dirs=0) |
dirlist = listdir('navidoc/mp',['py'],dirs=0) |
51 |
for module in dirlist: |
for module in dirlist: |
55 |
for module in dirlist: |
for module in dirlist: |
56 |
if module != '__init__.py': exec('import navidoc.link.%s' % module[0:len(module)-3]) |
if module != '__init__.py': exec('import navidoc.link.%s' % module[0:len(module)-3]) |
57 |
|
|
|
""" |
|
|
The main frontend for running Navidoc. |
|
|
""" |
|
|
|
|
58 |
dbg = config.dbg.shorthand('navidoc') |
dbg = config.dbg.shorthand('navidoc') |
59 |
dbg_config = config.dbg.shorthand('config') |
dbg_config = config.dbg.shorthand('config') |
60 |
|
|
61 |
# XXX: figure out, why docutils want locals to be cleaned |
# Docutils wants locales to be cleaned |
62 |
import locale |
import locale |
63 |
try: |
try: |
64 |
locale.setlocale(locale.LC_ALL, '') |
locale.setlocale(locale.LC_ALL, '') |
65 |
except: |
except: |
66 |
pass |
pass |
67 |
|
|
68 |
# catching writer parameters from the command line |
# Catch actions from the command line |
69 |
try: sys.argv.remove('--imagemap'); imagemap = 1 |
try: sys.argv.remove('--imagemap'); imagemap = 1 |
70 |
except ValueError: imagemap = 0 |
except ValueError: imagemap = 0 |
71 |
|
|
|
# catching writer parameters from the command line |
|
72 |
try: sys.argv.remove('--latex'); latex = 1 |
try: sys.argv.remove('--latex'); latex = 1 |
73 |
except ValueError: latex = 0 |
except ValueError: latex = 0 |
74 |
|
|
|
# catching writer parameters from the command line |
|
75 |
try: sys.argv.remove('--html'); html = 1 |
try: sys.argv.remove('--html'); html = 1 |
76 |
except ValueError: html = 0 |
except ValueError: html = 0 |
77 |
|
|
|
# catching feature parameters from the command line |
|
78 |
try: sys.argv.remove('--metalink'); metalink = 1 |
try: sys.argv.remove('--metalink'); metalink = 1 |
79 |
except ValueError: metalink = 0 |
except ValueError: metalink = 0 |
80 |
|
|
|
# catching feature parameters from the command line |
|
81 |
try: sys.argv.remove('--navbar'); navbar = 1 |
try: sys.argv.remove('--navbar'); navbar = 1 |
82 |
except ValueError: navbar = 0 |
except ValueError: navbar = 0 |
83 |
|
|
|
# catching feature parameters from the command line |
|
84 |
try: sys.argv.remove('--texture'); texture = 1 |
try: sys.argv.remove('--texture'); texture = 1 |
85 |
except ValueError: texture = 0 |
except ValueError: texture = 0 |
86 |
|
|
87 |
|
try: sys.argv.remove('--loop'); loop = 1 |
88 |
|
except ValueError: loop = 0 |
89 |
|
|
90 |
def rst2any(input): |
def rst2any(input): |
91 |
""" |
""" |
92 |
Runs docutils for a single file. |
rst2any(input) |
93 |
|
|
94 |
|
Run docutils for a single file. |
95 |
""" |
""" |
96 |
last_dot = input.replace("../", "__/").rfind('.') |
last_dot = input.replace("../", "__/").rfind('.') |
97 |
if last_dot != -1: output = input[:last_dot] |
if last_dot != -1: output = input[:last_dot] |
130 |
|
|
131 |
def postprocess(path): |
def postprocess(path): |
132 |
""" |
""" |
133 |
|
postprocess(path) |
134 |
|
|
135 |
|
Run selected postprocessing modules. |
136 |
""" |
""" |
137 |
if metalink and os.path.isdir(path): |
|
|
import navidoc.modules.metalink |
|
|
config.working_directory = path |
|
|
navidoc.modules.metalink.postprocess(path) |
|
|
|
|
|
if navbar and os.path.isdir(path): |
|
|
import navidoc.modules.navbar |
|
|
config.working_directory = path |
|
|
navidoc.modules.navbar.postprocess(path) |
|
|
|
|
138 |
if imagemap: |
if imagemap: |
139 |
if os.path.isfile(path): |
if os.path.isfile(path): |
140 |
last_dot = path.replace("../", "__/").rfind('.') |
last_dot = path.replace("../", "__/").rfind('.') |
146 |
navidoc.modules.imagemap.postprocess(path) |
navidoc.modules.imagemap.postprocess(path) |
147 |
config.link_emphasize = 0 |
config.link_emphasize = 0 |
148 |
|
|
|
if texture: |
|
|
if os.path.isfile(path): |
|
|
last_dot = path.replace("../", "__/").rfind('.') |
|
|
if last_dot != -1: path = path[:last_dot]+midfix+'.html' |
|
|
|
|
|
import navidoc.modules.texture |
|
|
config.working_directory = os.path.normpath(os.path.dirname(path)) |
|
|
navidoc.modules.texture.postprocess(path) |
|
|
|
|
149 |
def run_docutils(path): |
def run_docutils(path): |
150 |
""" |
""" |
151 |
Selects all reST files under ``path`` directory (or the single file |
run_docutils(path) |
152 |
specified by ``path``) and forwards them to conversion method. |
|
153 |
|
Select all reST files under ``path`` directory (or the single file |
154 |
|
specified by ``path``) and forward them to conversion method. |
155 |
""" |
""" |
156 |
if os.path.isdir(path) and not os.path.islink(path): |
if os.path.isdir(path) and not os.path.islink(path): |
157 |
dirlist = listdir(path,['rst'],dirs=1) |
dirlist = listdir(path,['rst'],dirs=1) |
181 |
rst2any(path+'.rst') |
rst2any(path+'.rst') |
182 |
config.input_filename = '' |
config.input_filename = '' |
183 |
|
|
184 |
# catching loop parameters from the command line |
# Catch debug parameters |
|
try: sys.argv.remove('--loop'); loop = 1 |
|
|
except ValueError: loop = 0 |
|
|
|
|
|
# catching debug parameters |
|
185 |
dbg_names, sys.argv = getopt.getopt(sys.argv[1:], config.dbg.short, config.dbg.long) |
dbg_names, sys.argv = getopt.getopt(sys.argv[1:], config.dbg.short, config.dbg.long) |
186 |
for dbg_name in dbg_names: |
for dbg_name in dbg_names: |
187 |
config.dbg.enable(dbg_name[1]) |
config.dbg.enable(dbg_name[1]) |
188 |
print 'Enabling debug output for:', dbg_name[1] |
print 'Enabling debug output for:', dbg_name[1] |
189 |
|
|
190 |
# conversion loop |
# Conversion loop |
191 |
while 1: |
while 1: |
192 |
|
|
193 |
#the first pass, docutils |
# The first pass; Docutils with Navidoc directives |
194 |
for filepath in sys.argv: |
for filepath in sys.argv: |
195 |
try: |
try: |
196 |
run_docutils(filepath) |
run_docutils(filepath) |
206 |
except navidoc.mp.uml.UMLException, e: |
except navidoc.mp.uml.UMLException, e: |
207 |
dbg("Fatal, UMLException: "+e.value) |
dbg("Fatal, UMLException: "+e.value) |
208 |
break |
break |
209 |
#the second pass, postprocess |
|
210 |
|
# The second pass; Postprocessing modules |
211 |
for filepath in sys.argv: |
for filepath in sys.argv: |
212 |
try: |
try: |
213 |
postprocess(filepath) |
postprocess(filepath) |
225 |
break |
break |
226 |
|
|
227 |
if not loop: break |
if not loop: break |
228 |
print "\n\n"+'Navidoc finished. Press Enter to recompile.'+"\n"+ \ |
print "\n\n"+'Navidoc has finished. Press Enter to recompile.'+"\n"+ \ |
229 |
'Enter any other key to exit loop and quit.' |
'Enter any other key to exit the loop and quit Navidoc.' |
230 |
if raw_input().lower() != '': |
if raw_input().lower() != '': |
231 |
break |
break |
232 |
print 'Rerunning Navidoc...' |
print 'Rerunning Navidoc...' |