@@ -170,27 +170,23 @@ end
170
170
local function py2image (code , filetype )
171
171
172
172
-- Define the temp files:
173
- local outfile = string.format (" ./tmp-python/file.%s" , filetype )
174
- local tmp = " ./tmp-python/file"
175
- local tmpDir = " ./tmp-python/"
173
+ local outfile = os.tmpname ()
174
+ local pyfile = os.tmpname ()
176
175
177
176
-- Replace the desired destination's file type in the Python code:
178
177
local extendedCode = string.gsub (code , " %$FORMAT%$" , filetype )
179
178
180
179
-- Replace the desired destination's path in the Python code:
181
180
extendedCode = string.gsub (extendedCode , " %$DESTINATION%$" , outfile )
182
181
183
- -- Ensure, that the tmp directory exists:
184
- os.execute (" mkdir tmp-python" )
185
-
186
182
-- Write the Python code:
187
- local f = io.open (tmp .. " .py " , ' w' )
183
+ local f = io.open (pyfile , ' w' )
188
184
f :write (extendedCode )
189
185
f :close ()
190
186
191
187
-- Execute Python in the desired environment:
192
188
os.execute (
193
- pythonActivatePath .. " && " .. pythonPath .. " " .. tmp .. " .py "
189
+ pythonActivatePath .. " && " .. pythonPath .. " " .. pyfile
194
190
)
195
191
196
192
-- Try to open the written image:
@@ -204,7 +200,7 @@ local function py2image(code, filetype)
204
200
end
205
201
206
202
-- Delete the tmp files:
207
- os.remove (tmp .. " .py " )
203
+ os.remove (pyfile )
208
204
os.remove (outfile )
209
205
210
206
return imgData
0 commit comments