1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 """SCons targets for building the relax manuals."""
24
25
26 from datetime import datetime
27 from glob import glob
28 from os import F_OK, access, chdir, getcwd, listdir, path, remove, rename, sep, system
29 from re import search
30 from subprocess import PIPE, Popen
31 import sys
32
33
34 from info import Info_box
35 from status import Status; status = Status()
36 import version
37
38
40 """Builder action for removing the temporary manual files."""
41
42
43 print('')
44 print("##########################################")
45 print("# Cleaning up the temporary manual files #")
46 print("##########################################\n\n")
47
48
49 files = [
50 "relax.bbl",
51 "relax.blg",
52 "relax.dvi",
53 "relax.idx",
54 "relax.ilg",
55 "relax.ind",
56 "relax.lof",
57 "relax.log",
58 "relax.lot",
59 "relax.out",
60 "relax.toc",
61 "copyright.tex"
62 ]
63
64
65 for i in range(len(files)):
66 files[i] = path.join(env['LATEX_DIR'], files[i])
67
68
69 for file in glob(env['LATEX_DIR'] + '*.aux'):
70 files.append(file)
71 for file in glob(env['LATEX_DIR'] + 'frame_order' + sep + '*.aux'):
72 files.append(file)
73
74
75 for file in files:
76 try:
77 remove(file)
78 except OSError:
79 message = sys.exc_info()[1]
80
81
82 if message.errno == 2:
83 pass
84
85
86 else:
87 raise
88 else:
89 print("Removing the file " + repr(file) + ".")
90
91
92 print("\n\n\n")
93
94
96 """Builder action for compiling the API documentation manual (HTML version) using Epydoc."""
97
98
99 print('')
100 print("#####################################################")
101 print("# Compiling API documentation manual (HTML version) #")
102 print("#####################################################\n\n")
103
104
105
106
107
108
109
110 exclude = [
111 'devel_scripts',
112 'extern',
113 'graphics',
114 'minfx.scipy_subset',
115 'multi.test_implementation',
116 'multi.test_implementation2',
117 'sample_scripts',
118 'test_suite.system_tests.scripts',
119 'test_suite.shared_data'
120 ]
121
122
123
124
125 output = 'html'
126
127
128
129 target = 'docs'+sep+'api'
130
131
132
133
134 docformat = 'epytext'
135
136
137
138
139 css = 'white'
140
141
142
143 name = 'relax'
144
145
146
147 url = 'http://www.nmr-relax.com'
148
149
150
151
152
153 link = '<a href="/">relax</a>'
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168 frames = 1
169
170
171
172
173 private = 1
174
175
176
177 imports = 1
178
179
180
181
182
183 verbosity = 1
184
185
186
187 parse = 1
188
189
190
191 introspect = 1
192
193
194
195
196
197
198 graph = 'all'
199
200
201
202
203
204
205
206
207
208 sourcecode = 1
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226 epydoc_cmd = 'epydoc' + ' --' + output + ' -o ' + target + ' --docformat ' + docformat + ' --css ' + css + ' --name ' + name + ' --url ' + url + ' --simple-term'
227 if 'link' in locals():
228 epydoc_cmd += ' --navlink \'%s\'' % link
229
230
231 if frames:
232 epydoc_cmd = epydoc_cmd + ' --show-frames'
233 else:
234 epydoc_cmd = epydoc_cmd + ' --no-frames'
235
236
237 if private:
238 epydoc_cmd = epydoc_cmd + ' --show-private'
239 else:
240 epydoc_cmd = epydoc_cmd + ' --no-private'
241
242
243 if imports:
244 epydoc_cmd = epydoc_cmd + ' --show-imports'
245 else:
246 epydoc_cmd = epydoc_cmd + ' --no-imports'
247
248
249 if verbosity > 0:
250 for i in range(verbosity):
251 epydoc_cmd = epydoc_cmd + ' -v'
252 elif verbosity < 0:
253 for i in range(-verbosity):
254 epydoc_cmd = epydoc_cmd + ' -q'
255
256
257 if parse and not introspect:
258 epydoc_cmd = epydoc_cmd + ' --parse-only'
259 elif not parse and introspect:
260 epydoc_cmd = epydoc_cmd + ' --introspect-only'
261
262
263 epydoc_cmd = epydoc_cmd + ' --graph ' + graph
264
265
266 if sourcecode:
267 epydoc_cmd = epydoc_cmd + ' --show-sourcecode'
268 else:
269 epydoc_cmd = epydoc_cmd + ' --no-sourcecode'
270
271
272 for name in exclude:
273 epydoc_cmd = epydoc_cmd + ' --exclude=' + name
274
275
276 blacklist = ['relax_gui_mode.py']
277 files = listdir(getcwd())
278 for file in files:
279
280 if file in blacklist:
281 continue
282
283
284 if file in exclude:
285 continue
286
287
288 if search(r'^\.', file):
289 continue
290
291
292 if not path.isdir(file) and not search('.py$', file):
293 continue
294
295
296 epydoc_cmd = "%s %s" % (epydoc_cmd, file)
297
298
299
300
301
302
303 print("Running the command:\n$ " + epydoc_cmd + "\n\n\n")
304
305
306 pipe = Popen(epydoc_cmd, shell=True, stdout=PIPE, stderr=PIPE, close_fds=False)
307
308
309 issues = []
310 for line in pipe.stdout.readlines():
311 if len(line.strip()) and line[0] in ['+', '|']:
312
313 sys.stdout.write(line)
314
315
316 if search(r"^\+----------", line):
317 issues.append("")
318 continue
319
320
321 issues[-1] += line[2:].rstrip()
322
323
324 for issue in issues:
325
326 if "wx/" in issue:
327 continue
328
329
330 if "pystarlib/" in issue:
331 continue
332
333
334 raise NameError("Errors or warnings found.")
335
336
337
338
339
340
341 css_file = open(target + sep+'epydoc.css', 'a')
342
343
344 css_file.write("\n\n\n\n/* Edward */\n\n")
345
346
347 css_file.write("a { text-decoration:none; color:#0017aa; font-weight:normal; }\n")
348 css_file.write("a:hover { color:#316fff; }\n")
349
350
351 css_file.close()
352
353
354
355
356
357
358 print("\n\nModifying the header of all HTML files.\n")
359
360
361 today = datetime.today()
362 creator = "Edward d'Auvergne"
363 copyright = """\
364 <!--
365 Copyright (C) %i %s
366
367 Permission is granted to copy, distribute and/or modify this document
368 under the terms of the GNU Free Documentation License, Version 1.3
369 or any later version published by the Free Software Foundation;
370 with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts.
371 A copy of the license is included in the section titled "GNU
372 Free Documentation License" (fdl.html).
373 -->
374 """ % (today.year, creator)
375
376
377 head_lines = []
378
379
380 file = open(status.install_path + sep + 'devel_scripts' + sep + 'google_analytics.js')
381 for line in file.readlines():
382 head_lines.append(line)
383 file.close()
384
385
386 for file_name in listdir(status.install_path + sep + 'docs' + sep + 'api'):
387
388 full_path = status.install_path + sep + 'docs' + sep + 'api' + sep + file_name
389
390
391 if not search('.html$', full_path):
392 continue
393
394
395 file = open(full_path)
396 lines = file.readlines()
397 file.close()
398
399
400 file = open(full_path, 'w')
401
402
403 i = 0
404 while 1:
405
406 if i > len(lines)-1:
407 break
408
409
410 if search('<head>', lines[i]):
411 file.write(copyright)
412
413
414 if search('</head>', lines[i]):
415 start = False
416 for j in range(len(head_lines)):
417
418 if not start and search("Google analytics JS", head_lines[j]):
419 start = True
420
421
422 if start:
423 file.write(head_lines[j])
424
425
426 file.write(lines[i])
427
428
429 i += 1
430
431
432 file.close()
433
434
435 print("\n\n\n")
436
437
439 """Builder action for compiling the user manual (HTML version) from the LaTeX sources."""
440
441
442 compile_user_manual_pdf(target, source, env, convert=False)
443
444
445 print('')
446 print("############################################")
447 print("# Compiling the user manual (HTML version) #")
448 print("############################################\n\n")
449
450
451 base_dir = getcwd()
452 chdir(env['LATEX_DIR'])
453
454
455 dir = path.pardir + path.sep + "html"
456
457
458 cmd = "latex2html -dir %s relax.tex" % (dir)
459 print("Running the command:\n$ %s\n\n\n" % cmd)
460 system(cmd)
461
462
463 cmd = "cp -vp %s%sThe_relax_user_manual.html %s%sindex.html" % (dir, path.sep, dir, path.sep)
464 print("Running the command:\n$ %s\n\n\n" % cmd)
465 system(cmd)
466
467
468 css_file = open(path.join(dir, 'relax.css'))
469 css = css_file.readlines()
470 css_file.close()
471 css_file = open(path.join(dir, 'relax.css'), 'w')
472 for line in css:
473
474 if search("^BODY { ", line):
475 css_file.write("BODY { width:95%; }\n")
476
477
478 else:
479 css_file.write(line)
480
481
482 chdir(base_dir)
483
484
485 print("\n\n\n")
486
487
489 """Builder action for compiling the user manual (PDF version) from the LaTeX sources."""
490
491
492 print('')
493 print("###########################################")
494 print("# Compiling the user manual (PDF version) #")
495 print("###########################################\n\n")
496
497
498 base_dir = getcwd()
499 chdir(env['LATEX_DIR'])
500
501 print("\n\n\n <<< LaTeX (first round) >>>\n\n\n")
502 system('latex relax')
503
504 print("\n\n\n <<< Bibtex >>>\n\n\n")
505 system('bibtex relax')
506
507 print("\n\n\n <<< Makeindex >>>\n\n\n")
508 system('makeindex relax')
509
510 print("\n\n\n <<< LaTeX (second round) >>>\n\n\n")
511 system('latex relax')
512
513 print("\n\n\n <<< LaTeX (third round) >>>\n\n\n")
514 system('latex relax')
515
516 print("\n\n\n <<< Makeindex >>>\n\n\n")
517 system('makeindex relax')
518
519 print("\n\n\n <<< LaTeX (fourth round) >>>\n\n\n")
520 system('latex relax')
521
522
523 if not convert:
524
525 chdir(base_dir)
526
527
528 return
529
530 print("\n\n\n <<< dvips >>>\n\n\n")
531 system('dvips -R0 -o relax.ps relax.dvi')
532
533 print("\n\n\n <<< ps2pdf >>>\n\n\n")
534 if env['SYSTEM'] == 'Windows':
535
536
537
538 assign = '#'
539 else:
540 assign = '='
541 system('ps2pdf -dAutoFilterColorImages' + assign + 'false -dAutoFilterGrayImages' + assign + 'false -dColorImageFilter' + assign + '/FlateEncode -dColorImageFilter' + assign + '/FlateEncode -dGrayImageFilter' + assign + '/FlateEncode -dMonoImageFilter' + assign + '/FlateEncode -dPDFSETTINGS' + assign + '/prepress relax.ps relax.pdf')
542
543 print("\n\n\n <<< Removing the PS file and shifting the PDF down a directory >>>\n\n\n")
544 if access('relax.ps', F_OK):
545 remove('relax.ps')
546 if access('relax.pdf', F_OK):
547 rename('relax.pdf', path.pardir+path.sep+'relax.pdf')
548
549
550 chdir(base_dir)
551
552
553 print("\n\n\n")
554
555
557 """Builder action for creating the LaTeX copyright notice file."""
558
559
560 print('')
561 print("##################################################")
562 print("# Creating the LaTeX relax copyright notice file #")
563 print("##################################################")
564
565
566 file = open(env['LATEX_DIR'] + sep + 'copyright.tex', 'w')
567
568
569 info = Info_box()
570
571
572 file.write("\\noindent %s\n\n" % info.copyright_latex)
573 file.write("\\vspace{5px}\n\n")
574
575
576 file.write("\\noindent Permission is granted to copy, distribute and/or modify this document under the terms of the GNU General Public License (GPL), Version 3 or any later version published by the Free Software Foundation.\n")
577 file.write("\\vspace{5px}\n\n")
578 file.write("\\noindent The Oxygen Icons used herein are licensed under the terms of the GNU Lesser General Public License (GPL), Version 3 or any later version published by the Free Software Foundation.\n")
579
580
581 file.close()
582
583
584 print("\n\n\n")
585
586
588 """Builder action for fetching the relax user function docstrings."""
589
590
591 print('')
592 print("###############################################")
593 print("# Fetching the relax user function docstrings #")
594 print("###############################################\n\n")
595
596
597 sys.path.insert(0, getcwd())
598 from docs.latex.fetch_docstrings import Fetch_docstrings
599
600
601 Fetch_docstrings(env['LATEX_DIR'] + sep + 'docstring.tex')
602
603
604 del Fetch_docstrings
605
606
607 print("\n\n\n")
608
609
611 """Builder action for checking for replicated titles in the LaTeX sources."""
612
613
614 print('')
615 print("#######################################################")
616 print("# Checking for replicated titles in the LaTeX sources #")
617 print("#######################################################\n\n")
618
619
620 sys.path.insert(0, getcwd())
621 from docs.latex.find_replicate_titles import Replicated_titles
622
623
624 replicates = Replicated_titles()
625 if replicates.find():
626 print("\n\nFatal error: Replicated titles found.")
627 print("\n\n\n")
628 sys.exit(1)
629
630
631 del replicates
632 del Replicated_titles
633
634
635 print("No replicated titles found.")
636 print("\n\n\n")
637
638
640 """Builder action for creating the LaTeX relax version file."""
641
642
643 print('')
644 print("################################################")
645 print("# Creating the LaTeX relax version number file #")
646 print("################################################")
647
648
649 text = version.version
650 if text == 'repository commit':
651 if version.repo_type == 'git':
652 text += ' %s' % version.repo_head
653 else:
654 text += ' r%s' % version.repo_head
655
656
657 file = open(env['LATEX_DIR'] + sep + 'relax_version.tex', 'w')
658 file.write("Version " + text + '\n')
659 file.close()
660
661
662 print("\n\n\n")
663