Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 77d3825

Browse files
committed
fixed bug in backend_ps for usetex, improved usetex, ps.distiller dependency
checking svn path=/trunk/matplotlib/; revision=1964
1 parent 0953a50 commit 77d3825

2 files changed

Lines changed: 109 additions & 60 deletions

File tree

lib/matplotlib/__init__.py

Lines changed: 83 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -430,50 +430,81 @@ def _get_data_path():
430430

431431

432432
def checkdep_dvipng():
433-
stdin, stdout = os.popen4('dvipng -v')
434-
if 'This is dvipng' in stdout.read(): return True
435-
else:
436-
verbose.report('dvipng not found!', 'helpful')
433+
try:
434+
stdin, stdout = os.popen4('dvipng -version')
435+
line = stdout.readlines()[1]
436+
v = line.split()[-1]
437+
float(v)
438+
if v >= '1.5': return True
439+
else:
440+
verbose.report(line+'\ndvipng-1.5 or later not found!', 'helpful')
441+
return False
442+
except IndexError, ValueError:
443+
verbose.report(line+'\ndvipng-1.5 or later not found!', 'helpful')
437444
return False
438445

439446
def checkdep_ghostscript():
440-
flag = False
441-
if sys.platform == 'win32':
442-
stdin, stdout = os.popen4('gswin32c -v')
443-
if 'Ghostscript' in stdout.read(): flag = True
444-
else:
445-
stdin, stdout = os.popen4('gs -v')
446-
if 'Ghostscript' in stdout.read(): flag = True
447-
if flag: return True
448-
else:
449-
verbose.report('Ghostscript not found!\n\
450-
Please install a recent version of ghostscript \n\
451-
(gnu-ghostscript-8.16 or later suggested)\n', 'helpful')
447+
try:
448+
if sys.platform == 'win32':
449+
command = 'gswin32c -v'
450+
else:
451+
command = 'gs -v'
452+
stdin, stdout = os.popen4(command)
453+
line = stdout.readlines()[0]
454+
v = line.split()[2]
455+
float(v)
456+
if v >= '8.16': return True
457+
else:
458+
verbose.report(line+'\nGhostscript-8.16 or later not found!\n', 'helpful')
459+
return False
460+
except IndexError, ValueError:
461+
verbose.report(line+'\nGhostscript-8.16 or later not found!\n', 'helpful')
452462
return False
453463

454464
def checkdep_ps2eps():
455-
stdin, stdout = os.popen4('ps2eps -v')
456-
if 'ps2eps - convert PostScript to EPS' in stdout.read(): return True
457-
else:
458-
verbose.report('ps2eps not found!', 'helpful')
465+
try:
466+
stdin, stdout = os.popen4('ps2eps -v')
467+
line = stdout.readlines()[-1]
468+
v = line.split()[-1]
469+
float(v)
470+
if v >= '1.58': return True
471+
else:
472+
verbose.report(line+'\nps2eps-1.58 or later not found!', 'helpful')
473+
return False
474+
except IndexError, ValueError:
475+
verbose.report(line+'\nps2eps-1.58 or later not found!', 'helpful')
459476
return False
460477

461478
def checkdep_tex():
462-
stdin, stdout = os.popen4('tex -v')
463-
if 'TeX' in stdout.read(): return True
464-
else:
465-
verbose.report('latex not found!\
479+
try:
480+
stdin, stdout = os.popen4('tex -v')
481+
line = stdout.readlines()[0]
482+
v = line.split()[1]
483+
float(v)
484+
if v >= '3.1415': return True
485+
else:
486+
verbose.report(line+'\nTeX not found!\
487+
Please install the appropriate package for your platform.\n', 'helpful')
488+
return False
489+
except IndexError, ValueError:
490+
verbose.report(line+'\nTeX not found!\
466491
Please install the appropriate package for your platform.\n', 'helpful')
467492
return False
468493

469494
def checkdep_xpdf():
470-
stdin, stdout = os.popen4('xpdf -v')
471-
if 'xpdf version' in stdout.read(): return True
472-
else:
473-
verbose.report('xpdf not found!', 'helpful')
495+
try:
496+
stdin, stdout = os.popen4('xpdf -v')
497+
line = stdout.readlines()[0]
498+
v = line.split()[-1]
499+
float(v)
500+
if v >= 3.0: return True
501+
else:
502+
verbose.report(line+'\nxpdf-3.0 or later not found!', 'helpful')
503+
return False
504+
except IndexError, ValueError:
505+
verbose.report(line+'\nxpdf-3.0 or later not found!', 'helpful')
474506
return False
475507

476-
477508
def validate_path_exists(s):
478509
'If s is a path, return s, else False'
479510
if os.path.exists(s): return s
@@ -611,8 +642,6 @@ def validate_verbose_fileo(s):
611642
try: fileo = file(s, 'w')
612643
except IOError:
613644
raise ValueError('Verbose object could not open log file "%s" for writing.\nCheck your matplotlibrc verbose.fileo setting'%s)
614-
615-
616645
else:
617646
verbose.fileo = fileo
618647
return verbose.fileo
@@ -633,27 +662,38 @@ def validate_ps_distiller(s):
633662
return False
634663
elif s == 'ghostscript':
635664
if checkdep_ghostscript(): return s.lower()
636-
else: raise 'DependencyError', 'matplotlibrc ps.usedistiller can not \
637-
be set to ghostscript unless ghostscript is available on your system'
638-
elif s == 'xpdf':
639-
if checkdep_ghostscript() and checkdep_xpdf() and checkdep_ps2eps():
640-
return s.lower()
641665
else:
666+
raise 'DependencyError', 'matplotlibrc ps.usedistiller can not be \
667+
set to ghostscript unless ghostscript-8.16 or later is available on your system'
668+
elif s == 'xpdf':
669+
if not checkdep_ghostscript():
670+
raise 'DependencyError', 'matplotlibrc ps.usedistiller can not \
671+
be set to xpdf unless ghostscript-8.16 or later is available on your system'
672+
if not checkdep_xpdf():
642673
raise 'DependencyError', 'matplotlibrc ps.usedistiller can not \
643-
be set to xpdf unless ghostscript, xpdf and ps2eps are available on your system'
674+
be set to xpdf unless xpdf-3.0 or later is available on your system'
675+
if not checkdep_ps2eps():
676+
raise 'DependencyError', 'matplotlibrc ps.usedistiller can not \
677+
be set to xpdf unless ps2eps-1.58 or later is available on your system'
678+
return s.lower()
644679
else:
645-
raise ValueError('matplotlibrc ps.usedistiller must either be none, ghostscript or xpdf')
680+
raise ValueError('matplotlibrc ps.usedistiller must either be none,ghostscript or xpdf')
646681

647682
validate_tex_engine = ValidateInStrings(['tex', 'latex'], ignorecase=True)
648683

649684
def validate_usetex(s):
650685
bl = validate_bool(s)
651686
if bl:
652-
if checkdep_tex() and checkdep_dvipng() and checkdep_ghostscript():
653-
return bl
654-
else:
655-
raise 'DependencyError', 'matplotlibrc tex.usetex can not be set to \
656-
True unless LaTeX, dvipng and ghostscript are available on your system.'
687+
if not checkdep_tex():
688+
raise 'DependencyError', 'matplotlibrc text.usetex can not \
689+
be set to True unless TeX/LaTeX is available on your system'
690+
if not checkdep_dvipng():
691+
raise 'DependencyError', 'matplotlibrc text.usetex can not \
692+
be set to True unless dvipng-1.5 or later is available on your system'
693+
if not checkdep_ghostscript():
694+
raise 'DependencyError', 'matplotlibrc text.usetex can not \
695+
be set to True unless ghostscript-8.16 or later is available on your system'
696+
return bl
657697
else: return bl
658698

659699
validate_joinstyle = ValidateInStrings(['miter', 'round', 'bevel'], ignorecase=True)

lib/matplotlib/backends/backend_ps.py

Lines changed: 26 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1139,8 +1139,8 @@ def print_figure(self, outfile, dpi=72,
11391139
\end{center}
11401140
\end{figure}
11411141
\end{document}
1142-
"""% (fontpackage, pw, ph, pw-2, ph-2, pw, ph, '\n'.join(renderer.psfrag), epsfile)
1143-
1142+
"""% (fontpackage, pw, ph, pw-2, ph-2, pw, ph, '\n'.join(renderer.psfrag),
1143+
os.path.split(epsfile)[-1])
11441144
latexh.close()
11451145
curdir = os.getcwd()
11461146
os.chdir(tempdir)
@@ -1149,13 +1149,13 @@ def print_figure(self, outfile, dpi=72,
11491149
stdin, stdout, stderr = os.popen3(command)
11501150
verbose.report(stdout.read(), 'debug-annoying')
11511151
verbose.report(stderr.read(), 'helpful')
1152-
os.chdir(curdir)
11531152
command = 'dvips -R -T %fin,%fin -o "%s" "%s"' % (pw, ph, psfile, dvifile)
11541153
verbose.report(command, 'debug-annoying')
11551154
stdin, stdout, stderr = os.popen3(command)
11561155
verbose.report(stdout.read(), 'debug-annoying')
11571156
verbose.report(stderr.read(), 'helpful')
11581157
os.remove(epsfile)
1158+
os.chdir(curdir)
11591159

11601160
if rcParams['ps.usedistiller'] == 'xpdf':
11611161
pdffile = tmpname + '.pdf'
@@ -1194,24 +1194,33 @@ def print_figure(self, outfile, dpi=72,
11941194
verbose.report(stdout.read(), 'debug-annoying')
11951195
verbose.report(stderr.read(), 'helpful')
11961196
shutil.move(epsfile, outfile)
1197-
else: shutil.move(psfile, outfile)
1197+
else: # for standard postscript:
1198+
if rcParams['ps.usedistiller'] == 'ghostscript':
1199+
command = 'ps2ps -dSAFER -r%d "%s" "%s"'% (dpi, psfile, outfile)
1200+
verbose.report(command, 'debug-annoying')
1201+
stdin, stdout, stderr = os.popen3(command)
1202+
verbose.report(stdout.read(), 'debug-annoying')
1203+
verbose.report(stderr.read(), 'helpful')
1204+
else:
1205+
shutil.move(psfile, outfile)
11981206

11991207
for fname in glob.glob(tmpname+'.*'):
12001208
os.remove(fname)
12011209

1202-
if rcParams['ps.usedistiller'] == 'ghostscript':
1203-
dpi = rcParams['ps.distiller.res']
1204-
m = md5.md5(outfile)
1205-
tmpfile = m.hexdigest()
1206-
if ext.startswith('ep'):
1207-
command = 'eps2eps -dSAFER -r%d "%s" "%s"'% (dpi, outfile, tmpfile)
1208-
else:
1209-
command = 'ps2ps -dSAFER -r%d "%s" "%s"'% (dpi, outfile, tmpfile)
1210-
verbose.report(command, 'debug-annoying')
1211-
stdin, stdout, stderr = os.popen3(command)
1212-
verbose.report(stdout.read(), 'debug-annoying')
1213-
verbose.report(stderr.read(), 'helpful')
1214-
shutil.move(tmpfile, outfile)
1210+
elif not rcParams['text.usetex']:
1211+
if rcParams['ps.usedistiller'] == 'ghostscript':
1212+
dpi = rcParams['ps.distiller.res']
1213+
m = md5.md5(outfile)
1214+
tmpfile = m.hexdigest()
1215+
if ext.startswith('ep'):
1216+
command = 'eps2eps -dSAFER -r%d "%s" "%s"'% (dpi, outfile, tmpfile)
1217+
else:
1218+
command = 'ps2ps -dSAFER -r%d "%s" "%s"'% (dpi, outfile, tmpfile)
1219+
verbose.report(command, 'debug-annoying')
1220+
stdin, stdout, stderr = os.popen3(command)
1221+
verbose.report(stdout.read(), 'debug-annoying')
1222+
verbose.report(stderr.read(), 'helpful')
1223+
shutil.move(tmpfile, outfile)
12151224

12161225

12171226
class FigureManagerPS(FigureManagerBase):

0 commit comments

Comments
 (0)