move function to create temp files to dtutils/file.lua

This commit is contained in:
Tobias Scheck
2020-06-15 11:16:14 +02:00
parent ed3e141601
commit 87502fb17f
2 changed files with 45 additions and 30 deletions

View File

@@ -227,24 +227,8 @@ function PHOTILS.attach_tags()
dt.print(_("Tags successfully attached to image"))
end
function PHOTILS.get_tmp_file()
local tmp_file = os.tmpname()
if dt.configuration.running_os == "windows" then
tmp_file = dt.configuration.tmp_dir .. tmp_file -- windows os.tmpname() defaults to root directory
end
local f = io.open(tmp_file, "w")
if not f then
dt.print_log(string.format(_("Error writing to `%s`"), tmp_file))
os.remove(tmp_file)
return nil
end
return tmp_file
end
function PHOTILS.get_tags(image, with_export)
local tmp_file = PHOTILS.get_tmp_file()
local tmp_file = df.create_tmp_file()
local in_arg = df.sanitize_filename(tostring(image))
local out_arg = df.sanitize_filename(tmp_file)
local executable = photils_installed
@@ -255,7 +239,7 @@ function PHOTILS.get_tags(image, with_export)
if with_export then
dt.print_log("use export to for prediction")
local export_file = PHOTILS.get_tmp_file()
local export_file = df.create_tmp_file()
exporter:write_image(image, export_file)
in_arg = df.sanitize_filename(tostring(export_file))
end