Skip to content

Commit 376762d

Browse files
committed
diagram-generator: use Lua function to create tmpfile names
1 parent 3fb76d4 commit 376762d

File tree

3 files changed

+10
-10
lines changed

3 files changed

+10
-10
lines changed

diagram-generator/.gitignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
sample.html
1+
sample.html
2+
tmp-latex

diagram-generator/Makefile

+3
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,6 @@ sample.html: sample.md
99
--metadata=title:"README" \
1010
--output=$@ $<
1111

12+
clean:
13+
rm -f sample.html
14+
rmdir tmp-latex || true

diagram-generator/diagram-generator.lua

+5-9
Original file line numberDiff line numberDiff line change
@@ -170,27 +170,23 @@ end
170170
local function py2image(code, filetype)
171171

172172
-- 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()
176175

177176
-- Replace the desired destination's file type in the Python code:
178177
local extendedCode = string.gsub(code, "%$FORMAT%$", filetype)
179178

180179
-- Replace the desired destination's path in the Python code:
181180
extendedCode = string.gsub(extendedCode, "%$DESTINATION%$", outfile)
182181

183-
-- Ensure, that the tmp directory exists:
184-
os.execute("mkdir tmp-python")
185-
186182
-- Write the Python code:
187-
local f = io.open(tmp .. ".py", 'w')
183+
local f = io.open(pyfile, 'w')
188184
f:write(extendedCode)
189185
f:close()
190186

191187
-- Execute Python in the desired environment:
192188
os.execute(
193-
pythonActivatePath .. " && " .. pythonPath .. " " .. tmp .. ".py"
189+
pythonActivatePath .. " && " .. pythonPath .. " " .. pyfile
194190
)
195191

196192
-- Try to open the written image:
@@ -204,7 +200,7 @@ local function py2image(code, filetype)
204200
end
205201

206202
-- Delete the tmp files:
207-
os.remove(tmp .. ".py")
203+
os.remove(pyfile)
208204
os.remove(outfile)
209205

210206
return imgData

0 commit comments

Comments
 (0)