~openerp-community/openobject-server/training

« back to all changes in this revision

Viewing changes to presentation.en/tools/FuzzyBuilder.py

  • Committer: Fabien Pinckaers
  • Date: 2009-08-04 16:14:19 UTC
  • Revision ID: fp@tinyerp.com-20090804161419-vwan9tdtjheeua87
add

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/env python
 
2
 
 
3
# 2008/04/13
 
4
# v0.1.1
 
5
# FuzzyBuilder.py
 
6
 
 
7
# An interface to docutils that does textmacros processing
 
8
 
 
9
# Homepage : http://www.voidspace.org.uk/python/firedrop2/textamcros.shtml
 
10
 
 
11
# Copyright Michael Foord, 2004 & 2005.
 
12
# Released subject to the BSD License
 
13
# Please see http://www.voidspace.org.uk/python/license.shtml
 
14
 
 
15
# Adapted for personal needs by Christopher Arndt
 
16
# - Removed pythonutils dependencies
 
17
# - Accepts source directory as command line arg
 
18
 
 
19
# For information about bugfixes, updates and support,
 
20
# please join the Pythonutils mailing list.
 
21
# http://groups.google.com/group/pythonutils/
 
22
# Comments, suggestions and bug reports welcome.
 
23
# Scripts maintained at http://www.voidspace.org.uk/python/index.shtml
 
24
# E-mail fuzzyman@voidspace.org.uk
 
25
 
 
26
"""
 
27
Requires ConfigObj module
 
28
See http://www.voidspace.org.uk/python/modules.shtml#configobj
 
29
 
 
30
"""
 
31
 
 
32
import os
 
33
import sys
 
34
import shutil
 
35
from StringIO import StringIO
 
36
from traceback import print_exc
 
37
 
 
38
from os.path import dirname, join
 
39
 
 
40
try:
 
41
    from configobj import ConfigObj
 
42
except ImportError:
 
43
    from pythonutils.configobj import ConfigObj
 
44
 
 
45
sys.path.insert(0, join(dirname(__file__), 'lib'))
 
46
import textmacros
 
47
import macros
 
48
 
 
49
from buildhtml import Builder
 
50
from tee import Tee
 
51
from walkfiles import walkfiles
 
52
 
 
53
###############
 
54
# global options
 
55
 
 
56
log_file = 'FuzzyBuilder.log'
 
57
pause = False
 
58
 
 
59
###############
 
60
 
 
61
if log_file:
 
62
    stand = Tee(logfile = log_file)
 
63
else:
 
64
    stand = None
 
65
 
 
66
# source directory specified on command line?
 
67
try:
 
68
    srcdir = sys.argv[1]
 
69
except IndexError:
 
70
    srcdir = os.getcwd()
 
71
 
 
72
# do the reST to html conversion
 
73
# then macro processing
 
74
try:
 
75
    Builder().run(directory=srcdir)
 
76
    #
 
77
    # walk through all the files in this directory (and below)
 
78
    for entry in walkfiles(srcdir, '*.html'):
 
79
        print 'Processing "%s" for macros.' % entry
 
80
        body = open(entry).read()
 
81
        newbody = textmacros.replace_all(body, macros.__dict__, 1)
 
82
        print 'Writing "%s".' % entry
 
83
        open(entry, 'w').write(newbody)
 
84
except KeyboardInterrupt:
 
85
    print 'Exited by Keyboard Interrupt.'
 
86
except Exception, e:
 
87
    # print any error without bombing out
 
88
    # (so we can display it, then close our files nicely)
 
89
    f = StringIO()
 
90
    print_exc(file = f)
 
91
    # write error to sys.stderr rather than printing to sys.stdout
 
92
    sys.stderr.write(f.getvalue() + '\n')
 
93
 
 
94
if stand:
 
95
    stand.close()
 
96
 
 
97
if pause:
 
98
    raw_input('Hit return to continue >>> ')