29 |
|
|
30 |
import sys, os, getopt |
import sys, os, getopt |
31 |
import docutils.core |
import docutils.core |
|
import navidoc |
|
32 |
|
|
33 |
|
import navidoc |
34 |
import config |
import config |
35 |
|
|
36 |
|
from navidoc.utils.path import _slashify, _listdir |
37 |
|
|
38 |
""" |
""" |
39 |
The main frontend for running Navidoc. |
The main frontend for running Navidoc. |
40 |
""" |
""" |
41 |
|
|
42 |
dbg = config.dbg.shorthand('navidoc') |
dbg = config.dbg.shorthand('navidoc') |
43 |
dbg_path = config.dbg.shorthand('path') |
dbg_config = config.dbg.shorthand('config') |
44 |
|
|
45 |
# XXX: figure out, why docutils want locals to be cleaned |
# XXX: figure out, why docutils want locals to be cleaned |
46 |
import locale |
import locale |
49 |
except: |
except: |
50 |
pass |
pass |
51 |
|
|
52 |
def run_docutils(path): |
# catching writer parameters from the command line |
53 |
""" |
try: sys.argv.remove('--latex'); latex = 1 |
54 |
Selects all ReST files under ``path`` directory (or the single file |
except ValueError: latex = 0 |
55 |
specified by ``path``) and forwards them to conversion method. |
|
56 |
""" |
# catching writer parameters from the command line |
57 |
if os.path.isdir(path): |
try: sys.argv.remove('--html'); html = 1 |
58 |
config.working_directory = os.path.normpath(path) |
except ValueError: html = 0 |
59 |
rstfiles = _rstFiles(path) |
|
60 |
if os.path.isfile(_slashify(path) + 'docutils.conf'): |
# catching feature parameters from the command line |
61 |
config.docutils = _slashify(path) + 'docutils.conf' |
try: sys.argv.remove('--metalink'); metalink = 1 |
62 |
for rstfile in rstfiles: |
except ValueError: metalink = 0 |
63 |
rst2any(_slashify(path)+rstfile) |
|
64 |
elif os.path.isfile(path): |
# catching feature parameters from the command line |
65 |
config.working_directory = os.path.normpath(os.path.dirname(path)) |
try: sys.argv.remove('--navbar'); navbar = 1 |
66 |
config.input_filename = os.path.basename(path) |
except ValueError: navbar = 0 |
|
rst2any(path) |
|
|
elif os.path.isfile(path+'.rst'): |
|
|
config.working_directory = os.path.normpath(os.path.dirname(path)) |
|
|
config.input_filename = os.path.basename(path+'.rst') |
|
|
rst2any(path+'.rst') |
|
67 |
|
|
68 |
def rst2any(input): |
def rst2any(input): |
69 |
""" |
""" |
70 |
Runs docutils for a single file. |
Runs docutils for a single file. |
71 |
""" |
""" |
72 |
if input.endswith('.rst'): output = input[0:len(input)-4] |
output = input.split(".")[0] |
|
else: output = input |
|
73 |
|
|
74 |
dbg_path("working directory: "+config.working_directory) |
dbg_config("Working directory: "+config.working_directory) |
75 |
dbg_path("input file: "+config.input_filename) |
dbg_config("Input file: "+config.input_filename) |
76 |
|
|
77 |
if html: |
if html: |
78 |
dbg('Compiling: '+input) |
dbg('Compiling: '+input) |
79 |
output = output+".gen.html" |
output = output+".gen.html" |
80 |
config.output_filename = os.path.basename(output) |
config.output_filename = os.path.basename(output) |
81 |
dbg_path("output file: "+config.output_filename) |
dbg_config("Output file: "+config.output_filename) |
82 |
args = "--config "+config.docutils+" "+input+' '+output |
args = "--config "+config.docutils+" "+input+' '+output |
83 |
docutils.core.publish_cmdline(writer_name='html', argv=args.split()) |
docutils.core.publish_cmdline(writer_name='html', argv=args.split()) |
84 |
|
|
86 |
dbg('Compiling: '+input) |
dbg('Compiling: '+input) |
87 |
output = output+".gen.latex" |
output = output+".gen.latex" |
88 |
config.output_filename = os.path.basename(output) |
config.output_filename = os.path.basename(output) |
89 |
dbg_path("output file: "+config.output_filename) |
dbg_config("Output file: "+config.output_filename) |
90 |
args = "--config "+config.docutils+" "+input+' '+output |
args = "--config "+config.docutils+" "+input+' '+output |
91 |
docutils.core.publish_cmdline(writer_name='latex', argv=args.split()) |
docutils.core.publish_cmdline(writer_name='latex', argv=args.split()) |
92 |
|
|
93 |
|
config.output_filename = "" |
94 |
|
|
95 |
|
def postprocess(path): |
96 |
|
""" |
97 |
|
""" |
98 |
|
if metalink and os.path.isdir(path): |
99 |
|
import navidoc.modules.metalink |
100 |
|
config.working_directory = path |
101 |
|
navidoc.modules.metalink.postprocess(path) |
102 |
|
|
103 |
|
if navbar and os.path.isdir(path): |
104 |
|
import navidoc.modules.navbar |
105 |
|
config.working_directory = path |
106 |
|
navidoc.modules.navbar.postprocess(path) |
107 |
|
|
108 |
|
def run_docutils(path): |
109 |
|
""" |
110 |
|
Selects all ReST files under ``path`` directory (or the single file |
111 |
|
specified by ``path``) and forwards them to conversion method. |
112 |
|
""" |
113 |
|
if os.path.isdir(path) and not os.path.islink(path): |
114 |
|
dirlist = _listdir(path,["rst"],dirs=1) |
115 |
|
if os.path.isfile(_slashify(path) + 'docutils.conf'): |
116 |
|
config.docutils = _slashify(path) + 'docutils.conf' |
117 |
|
for entry in dirlist: |
118 |
|
run_docutils(_slashify(path)+entry) |
119 |
|
elif os.path.isfile(path): |
120 |
|
config.working_directory = os.path.normpath(os.path.dirname(path)) |
121 |
|
config.input_filename = os.path.basename(path) |
122 |
|
rst2any(path) |
123 |
|
|
124 |
|
elif os.path.isfile(path+'.rst'): |
125 |
|
config.working_directory = os.path.normpath(os.path.dirname(path)) |
126 |
|
config.input_filename = os.path.basename(path+'.rst') |
127 |
|
rst2any(path+'.rst') |
128 |
|
config.input_filename = "" |
129 |
|
|
130 |
# catching loop parameters from the command line |
# catching loop parameters from the command line |
131 |
try: sys.argv.remove('--loop'); loop = 1 |
try: sys.argv.remove('--loop'); loop = 1 |
132 |
except ValueError: loop = 0 |
except ValueError: loop = 0 |
133 |
|
|
|
# catching writer parameters from the command line |
|
|
try: sys.argv.remove('--latex'); latex = 1 |
|
|
except ValueError: latex = 0 |
|
|
|
|
|
# catching writer parameters from the command line |
|
|
try: sys.argv.remove('--html'); html = 1 |
|
|
except ValueError: html = 0 |
|
|
|
|
134 |
# catching debug parameters |
# catching debug parameters |
135 |
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) |
136 |
for dbg_name in dbg_names: |
for dbg_name in dbg_names: |
144 |
for path in sys.argv: |
for path in sys.argv: |
145 |
run_docutils(path) |
run_docutils(path) |
146 |
|
|
147 |
|
#the second pass, postprocess |
148 |
|
for path in sys.argv: |
149 |
|
postprocess(path) |
150 |
|
|
151 |
# try: |
# try: |
152 |
# run_convert(path) |
# run_convert(path) |
153 |
# except umltool.umlException, e: |
# except umltool.umlException, e: |