contrib/select_non_existing - changed the logic to get a list of
files in the filmroll and check the
"known" files against the file list.
This cuts the number of system calls
from 1 per image to 1 per film roll
resulting an incredible speed up on
windows and a good speedup on other
platforms.
This commit is contained in:
@@ -20,14 +20,19 @@ Enable selection of non-existing images in the the currently worked on images, e
|
|||||||
local dt = require "darktable"
|
local dt = require "darktable"
|
||||||
local du = require "lib/dtutils"
|
local du = require "lib/dtutils"
|
||||||
local df = require "lib/dtutils.file"
|
local df = require "lib/dtutils.file"
|
||||||
|
local ds = require "lib/dtutils.string"
|
||||||
|
local log = require "lib/dtutils.log"
|
||||||
|
|
||||||
-- module name
|
-- module name
|
||||||
local MODULE = "select_non_existing"
|
local MODULE <const> = "select_non_existing"
|
||||||
|
|
||||||
du.check_min_api_version("9.1.0", MODULE)
|
du.check_min_api_version("9.1.0", MODULE)
|
||||||
|
|
||||||
-- figure out the path separator
|
-- figure out the path separator
|
||||||
local PS = dt.configuration.running_os == "windows" and "\\" or "/"
|
local PS <const> = dt.configuration.running_os == "windows" and "\\" or "/"
|
||||||
|
local DEFAULT_LOG_LEVEL <const> = log.info
|
||||||
|
|
||||||
|
log.log_level(DEFAULT_LOG_LEVEL)
|
||||||
|
|
||||||
local gettext = dt.gettext.gettext
|
local gettext = dt.gettext.gettext
|
||||||
|
|
||||||
@@ -39,26 +44,61 @@ local function stop_job(job)
|
|||||||
job.valid = false
|
job.valid = false
|
||||||
end
|
end
|
||||||
|
|
||||||
local function select_nonexisting_images(event, images)
|
local function get_file_list(dir)
|
||||||
local selection = {}
|
log.log_level(DEFAULT_LOG_LEVEL)
|
||||||
|
local file_list = {}
|
||||||
|
local cmd = nil
|
||||||
|
log.msg(log.debug, "called get_file_list with " .. dir)
|
||||||
|
|
||||||
local job = dt.gui.create_job(_("select non existing images"), true, stop_job)
|
if dt.configuration.running_os == "windows" then
|
||||||
for key,image in ipairs(images) do
|
cmd = "forfiles /P " .. ds.sanitize(dir) .. " /M * /C \"cmd /c echo @file\""
|
||||||
if(job.valid) then
|
else
|
||||||
job.percent = (key - 1)/#images
|
cmd = "cd " .. ds.sanitize(dir) ..";ls -1"
|
||||||
local filepath = image.path..PS..image.filename
|
end
|
||||||
local file_exists = df.test_file(filepath, "e")
|
log.msg(log.info, "cmd is " .. cmd)
|
||||||
dt.print_log(filepath.." exists? => "..tostring(file_exists))
|
|
||||||
if (not file_exists) then
|
local p = io.popen(cmd)
|
||||||
table.insert(selection, image)
|
if p then
|
||||||
end
|
for line in p:lines() do
|
||||||
else
|
if line:len() > 4 then
|
||||||
break
|
if not string.match(line, "xmp$") and not string.match(line, "XMP$") then
|
||||||
|
line = line:gsub("\"", "")
|
||||||
|
file_list[line] = true
|
||||||
end
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
stop_job(job)
|
p:close()
|
||||||
|
end
|
||||||
|
|
||||||
return selection
|
return file_list
|
||||||
|
end
|
||||||
|
|
||||||
|
local function select_nonexisting_images(event, images)
|
||||||
|
log.log_level(DEFAULT_LOG_LEVEL)
|
||||||
|
local selection = {}
|
||||||
|
local known_files = {}
|
||||||
|
|
||||||
|
local job = dt.gui.create_job(_("select non existing images"), true, stop_job)
|
||||||
|
for key,image in ipairs(images) do
|
||||||
|
if(job.valid) then
|
||||||
|
if not known_files[image.path] then
|
||||||
|
known_files[image.path] = get_file_list(image.path)
|
||||||
|
end
|
||||||
|
if key % 10 == 0 then
|
||||||
|
job.percent = key/#images
|
||||||
|
end
|
||||||
|
local file_exists = known_files[image.path][image.filename]
|
||||||
|
log.msg(log.debug, image.path .. PS .. image.filename .." exists? => "..tostring(file_exists))
|
||||||
|
if (not file_exists) then
|
||||||
|
table.insert(selection, image)
|
||||||
|
end
|
||||||
|
else
|
||||||
|
break
|
||||||
|
end
|
||||||
|
end
|
||||||
|
stop_job(job)
|
||||||
|
|
||||||
|
return selection
|
||||||
end
|
end
|
||||||
|
|
||||||
local function destroy()
|
local function destroy()
|
||||||
|
|||||||
Reference in New Issue
Block a user