2
Script to build the the dot2tex examples.
6
import re, os,shutil, glob,sys,logging
8
from os.path import join,basename,splitext,normpath,abspath
10
# intitalize logging module
11
log = logging.getLogger("test_graphparser")
12
console = logging.StreamHandler()
13
console.setLevel(logging.WARNING)
14
# set a format which is simpler for console use
15
formatter = logging.Formatter('%(levelname)-8s %(message)s')
16
# tell the handler to use this format
17
console.setFormatter(formatter)
18
log.addHandler(console)
21
BASE_DIR = join(abspath(os.path.dirname(__file__)),"")
22
DEST_DIR = join(BASE_DIR,'exrender/')
23
EXAMPLES_DIR = normpath(abspath(join(BASE_DIR,"../examples/")))
26
def copyifnewer(source, dest):
27
"""Copy source to dest if dest is older than source or doesn't exists"""
29
# Check that dest exists. Create dir if necessary
30
if os.path.exists(dest):
31
# get source's and dest's timpestamps
32
source_ts = os.path.getmtime(source)
33
dest_ts = os.path.getmtime(dest)
35
if source_ts > dest_ts: copy = True
38
dir = os.path.dirname(dest)
39
if dir != '' and not os.path.exists(dir):
43
shutil.copy2(source, dest)
47
#err = os.system(syscmd)
48
sres = os.popen(syscmd)
52
log.warning('Failed to run command:\n%s',syscmd)
53
log.debug('Output:\n%s',resdata)
57
fn = splitext(filename)[0]
58
s = "latex -halt-on-error -interaction nonstopmode %s.tex" % fn
61
if sys.platform=='win32':
62
s = "dvips -Ppdf -G0 -D600 -E* -o%s.eps %s.dvi" % (fn,fn)
65
s = "epstool --bbox --copy --output %s_tmp.eps %s.eps" % (fn,fn)
69
os.remove("%s.eps" % fn)
70
os.remove("%s.dvi" % fn)
71
os.remove("%s.aux" % fn)
72
os.remove("%s.log" % fn)
73
#os.remove("%s.pgf" % fn)
77
os.rename("%s_tmp.eps" % fn,"%s.eps" % fn)
78
s = "epstopdf %s.eps" % fn
81
s = "dvips %s.dvi" % fn
83
s = "ps2eps -B -f %s.ps" % fn
86
s = "epstopdf %s.eps" % fn
91
def create_pdf(texfile,use_pdftex=True):
92
if not splitext(texfile)[1]:
93
fn = basename(texfile)+'.tex'
95
fn = basename(texfile)
96
if sys.platform=='win32':
97
syscmd = 'texify --pdf --clean %s' % (fn)
99
syscmd = 'pdflatex -halt-on-error -interaction nonstopmode %s' % (fn)
104
def find_command(data):
105
commands = re.findall(r"\$ ((?:.*?) dot2tex (?:.*?))$", data,
106
re.MULTILINE|re.VERBOSE)
108
return commands[0].strip()
114
def make_img(c, filenm, name):
115
filename = os.path.splitext(filenm)[0]
120
if (c.find('--crop') > -1):
121
#os.system('del %s.png %s.jpg' % (name,name))
122
err = create_pdf(filename)
132
def build_gallery(filelist):
133
#os.chdir(EXAMPLES_DIR)
136
for file in filelist:
141
dirname, filename = os.path.split(file)
143
name = os.path.splitext(filename)[0]
147
command = find_command(data)
150
c = command.replace("dot2tex.py","dot2tex")
152
c = "dot2tex %s > %s.tex" % (file, name)
155
err = make_img(c,filename,'')
157
log.warning('Failed to build %s',filename)
158
failedfiles.append(filename)
164
if __name__ == "__main__":
168
for f in glob.glob("*.dot"):
169
if not f.find('dot2tex-fig') > 0:
170
src = os.path.join(exdir,f)
171
dst = normpath(join(DEST_DIR,basename(src)))
177
failedfiles = build_gallery(filelist)
179
log.warning('Failed files: %s',failedfiles);
182
print "All tests passed!"
185
#filelist=['distances.dot','tikzshapes.dot']