@@ -83,22 +83,6 @@ def compare_float( expected, actual, relTol = None, absTol = None ):
83
83
# convert files with that extension to png format.
84
84
converter = { }
85
85
86
- def make_external_conversion_command (cmd ):
87
- def convert (* args ):
88
- cmdline = cmd (* args )
89
- oldname , newname = args
90
- pipe = subprocess .Popen (cmdline , stdout = subprocess .PIPE , stderr = subprocess .PIPE )
91
- stdout , stderr = pipe .communicate ()
92
- errcode = pipe .wait ()
93
- if not os .path .exists (newname ) or errcode :
94
- msg = "Conversion command failed:\n %s\n " % ' ' .join (cmd )
95
- if stdout :
96
- msg += "Standard output:\n %s\n " % stdout
97
- if stderr :
98
- msg += "Standard error:\n %s\n " % stderr
99
- raise IOError , msg
100
- return convert
101
-
102
86
if matplotlib .checkdep_ghostscript () is not None :
103
87
# FIXME: make checkdep_ghostscript return the command
104
88
if sys .platform == 'win32' :
@@ -108,49 +92,13 @@ def convert(*args):
108
92
cmd = lambda old , new : \
109
93
[gs , '-q' , '-sDEVICE=png16m' , '-dNOPAUSE' , '-dBATCH' ,
110
94
'-sOutputFile=' + new , old ]
111
- converter ['pdf' ] = make_external_conversion_command ( cmd )
112
- converter ['eps' ] = make_external_conversion_command ( cmd )
95
+ converter ['pdf' ] = cmd
96
+ converter ['eps' ] = cmd
113
97
114
98
if matplotlib .checkdep_inkscape () is not None :
115
- class SVGConverter :
116
- def __init__ (self ):
117
- self ._count = 0
118
- self ._process = None
119
-
120
- def get_process (self ):
121
- # Since Inkscape can leak a little memory, we run X
122
- # conversions and then shut it down and start up a new
123
- # Inkscape.
124
- if self ._count == 0 :
125
- if self ._process is not None :
126
- self ._process .communicate ('quit\n ' )
127
- self ._process = subprocess .Popen (['inkscape' , '-z' , '--shell' ],
128
- stdin = subprocess .PIPE ,
129
- stdout = subprocess .PIPE ,
130
- stderr = subprocess .STDOUT )
131
- self .read_to_end (self ._process .stdout )
132
- self ._count = 10
133
- self ._count -= 1
134
- return self ._process
135
-
136
- def __call__ (self , old , new ):
137
- process = self .get_process ()
138
- process .stdin .write ('%s --export-png=%s\n ' % (old , new ))
139
- process .stdin .flush ()
140
- self .read_to_end (process .stdout )
141
-
142
- def read_to_end (self , buf ):
143
- ret = ''
144
- lastchar = ''
145
- while True :
146
- char = buf .readline (1 )
147
- if char == '>' and lastchar == '\n ' :
148
- break
149
- ret += char
150
- lastchar = char
151
- return ret
152
-
153
- converter ['svg' ] = SVGConverter ()
99
+ cmd = lambda old , new : \
100
+ ['inkscape' , old , '--export-png=' + new ]
101
+ converter ['svg' ] = cmd
154
102
155
103
def comparable_formats ():
156
104
'''Returns the list of file formats that compare_images can compare
@@ -168,7 +116,17 @@ def convert(filename):
168
116
newname = base + '_' + extension + '.png'
169
117
if not os .path .exists (filename ):
170
118
raise IOError , "'%s' does not exist" % filename
171
- converter [extension ](filename , newname )
119
+ cmd = converter [extension ](filename , newname )
120
+ pipe = subprocess .Popen (cmd , stdout = subprocess .PIPE , stderr = subprocess .PIPE )
121
+ stdout , stderr = pipe .communicate ()
122
+ errcode = pipe .wait ()
123
+ if not os .path .exists (newname ) or errcode :
124
+ msg = "Conversion command failed:\n %s\n " % ' ' .join (cmd )
125
+ if stdout :
126
+ msg += "Standard output:\n %s\n " % stdout
127
+ if stderr :
128
+ msg += "Standard error:\n %s\n " % stderr
129
+ raise IOError , msg
172
130
return newname
173
131
174
132
verifiers = { }
0 commit comments