Skip to content

Commit 038418b

Browse files
committed
contrib/autostyle replaced io.popen functions with wrapper
contrib/color_profile_manager to properly quote windows commands so contrib/fujifilm_dynamic_range that they are sanitized for special contrib/fujifilm_ratings characters and spaces contrib/geoJSON_export contrib/geoToolbox contrib/image_stack contrib/image_time contrib/kml_export official/enfuse tools/executable_manager tools/get_lib_manpages tools/get_libdoc
1 parent fe48d74 commit 038418b

13 files changed

+28
-18
lines changed

contrib/autostyle.lua

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ GPLv2
3939
local darktable = require "darktable"
4040
local du = require "lib/dtutils"
4141
local filelib = require "lib/dtutils.file"
42+
local syslib = require "lib/dtutils.system"
4243

4344
du.check_min_api_version("7.0.0", "autostyle")
4445

@@ -68,7 +69,7 @@ script_data.show = nil -- only required for libs since the destroy_method only h
6869
-- run command and retrieve stdout
6970
local function get_stdout(cmd)
7071
-- Open the command, for reading
71-
local fd = assert(io.popen(cmd, 'r'))
72+
local fd = assert(syslib.io_popen(cmd, 'r'))
7273
darktable.control.read(fd)
7374
-- slurp the whole file
7475
local data = assert(fd:read('*a'))

contrib/color_profile_manager.lua

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
local dt = require "darktable"
4646
local du = require "lib/dtutils"
4747
local df = require "lib/dtutils.file"
48+
local dtsys = require "lib/dtutils.system"
4849

4950
du.check_min_api_version("7.0.0", "color_profile_manager")
5051

@@ -106,7 +107,7 @@ end
106107

107108
local function list_profiles(dir)
108109
local files = {}
109-
local p = io.popen(DIR_CMD .. " " .. dir)
110+
local p = dtsys.io_popen(DIR_CMD .. " " .. dir)
110111
if p then
111112
for line in p:lines() do
112113
table.insert(files, line)

contrib/fujifilm_dynamic_range.lua

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ cameras may behave in other ways.
6060
local dt = require "darktable"
6161
local du = require "lib/dtutils"
6262
local df = require "lib/dtutils.file"
63+
local dtsys = require "lib/dtutils.system"
6364
local gettext = dt.gettext.gettext
6465

6566
du.check_min_api_version("7.0.0", "fujifilm_dynamic_range")
@@ -105,7 +106,7 @@ local function detect_dynamic_range(event, image)
105106
-- without -n flag, exiftool will round to the nearest tenth
106107
command = command .. " -RawExposureBias -n -t " .. RAF_filename
107108
dt.print_log(command)
108-
output = io.popen(command)
109+
output = dtsys.io_popen(command)
109110
local raf_result = output:read("*all")
110111
output:close()
111112
if #raf_result == 0 then

contrib/fujifilm_ratings.lua

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ Dependencies:
2626
local dt = require "darktable"
2727
local du = require "lib/dtutils"
2828
local df = require "lib/dtutils.file"
29+
local dtsys = require "lib/dtutils.system"
2930
local gettext = dt.gettext.gettext
3031

3132
du.check_min_api_version("7.0.0", "fujifilm_ratings")
@@ -61,7 +62,7 @@ local function detect_rating(event, image)
6162
local JPEG_filename = string.gsub(RAF_filename, "%.RAF$", ".JPG")
6263
local command = "exiftool -Rating " .. JPEG_filename
6364
dt.print_error(command)
64-
local output = io.popen(command)
65+
local output = dtsys.io_popen(command)
6566
local jpeg_result = output:read("*all")
6667
output:close()
6768
if string.len(jpeg_result) > 0 then
@@ -72,7 +73,7 @@ local function detect_rating(event, image)
7273
end
7374
command = "exiftool -Rating " .. RAF_filename
7475
dt.print_error(command)
75-
output = io.popen(command)
76+
output = dtsys.io_popen(command)
7677
local raf_result = output:read("*all")
7778
output:close()
7879
if string.len(raf_result) > 0 then

contrib/geoJSON_export.lua

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ USAGE
3535
local dt = require "darktable"
3636
local du = require "lib/dtutils"
3737
local df = require "lib/dtutils.file"
38+
local dtsys = require "lib/dtutils.system"
3839
local gettext = dt.gettext.gettext
3940

4041
du.check_min_api_version("7.0.0", "geoJSON_export")
@@ -330,7 +331,7 @@ dt.preferences.register("geoJSON_export",
330331
_("opens the geoJSON file after the export with the standard program for geoJSON files"),
331332
false )
332333

333-
local handle = io.popen("xdg-user-dir DESKTOP")
334+
local handle = dtsys.io_popen("xdg-user-dir DESKTOP")
334335
local result = handle:read()
335336
handle:close()
336337
if (result == nil) then

contrib/geoToolbox.lua

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ require "geoToolbox"
2828
local dt = require "darktable"
2929
local du = require "lib/dtutils"
3030
local df = require "lib/dtutils.file"
31+
local dtsys = require "lib/dtutils.system"
3132
local gettext = dt.gettext.gettext
3233

3334
du.check_min_api_version("7.0.0", "geoToolbox")
@@ -411,7 +412,7 @@ local function reverse_geocode()
411412
-- jq could be replaced with a Lua JSON parser
412413
startCommand = string.format("curl --silent \"https://api.mapbox.com/geocoding/v5/mapbox.places/%s,%s.json?types=%s&access_token=%s\" | jq '.features | .[0] | '.text''", lon1, lat1, types, tokan)
413414

414-
local handle = io.popen(startCommand)
415+
local handle = dtsys.io_popen(startCommand)
415416
local result = trim12(handle:read("*a"))
416417
handle:close()
417418

contrib/image_stack.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,7 @@ local function list_files(search_string)
348348
search_string = string.gsub(search_string, "/", "\\\\")
349349
end
350350

351-
local f = io.popen(ls .. search_string)
351+
local f = dtsys.io_popen(ls .. search_string)
352352
if f then
353353
local found_file = f:read()
354354
while found_file do

contrib/image_time.lua

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ local dt = require "darktable"
107107
local du = require "lib/dtutils"
108108
local df = require "lib/dtutils.file"
109109
local ds = require "lib/dtutils.string"
110+
local dtsys = require "lib/dtutils.system"
110111
local gettext = dt.gettext.gettext
111112

112113
local img_time = {}
@@ -225,7 +226,7 @@ local function get_image_taken_time(image)
225226

226227
local exiv2 = df.check_if_bin_exists("exiv2")
227228
if exiv2 then
228-
p = io.popen(exiv2 .. " -K Exif.Image.DateTime " .. image.path .. PS .. image.filename)
229+
p = dtsys.io_popen(exiv2 .. " -K Exif.Image.DateTime " .. image.path .. PS .. image.filename)
229230
if p then
230231
for line in p:lines() do
231232
if string.match(line, "Exif.Image.DateTime") then
@@ -243,7 +244,7 @@ end
243244

244245
local function _get_windows_image_file_creation_time(image)
245246
local datetime = nil
246-
local p = io.popen("dir " .. image.path .. PS .. image.filename)
247+
local p = dtsys.io_popen("dir " .. image.path .. PS .. image.filename)
247248
if p then
248249
for line in p:lines() do
249250
if string.match(line, ds.sanitize_lua(image.filename)) then
@@ -264,7 +265,7 @@ end
264265

265266
local function _get_nix_image_file_creation_time(image)
266267
local datetime = nil
267-
local p = io.popen("ls -lL --time-style=full-iso " .. image.path .. PS .. image.filename)
268+
local p = dtsys.io_popen("ls -lL --time-style=full-iso " .. image.path .. PS .. image.filename)
268269
if p then
269270
for line in p:lines() do
270271
if string.match(line, ds.sanitize_lua(image.filename)) then

contrib/kml_export.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,7 @@ if dt.configuration.running_os == "windows" then
343343
elseif dt.configuration.running_os == "macos" then
344344
defaultDir = os.getenv("HOME")
345345
else
346-
local handle = io.popen("xdg-user-dir DESKTOP")
346+
local handle = dsys.io_popen("xdg-user-dir DESKTOP")
347347
defaultDir = handle:read()
348348
handle:close()
349349
end

official/enfuse.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ if enfuse_installed then
116116

117117
local version = nil
118118

119-
local p = io.popen(enfuse_installed .. " --version")
119+
local p = dtsys.io_popen(enfuse_installed .. " --version")
120120
local f = p:read("all")
121121
p:close()
122122
version = string.match(f, "enfuse (%d.%d)")

tools/executable_manager.lua

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
local dt = require "darktable"
3232
local du = require "lib/dtutils"
3333
local df = require "lib/dtutils.file"
34+
local dtsys = require "lib/dtutils.system"
3435

3536
du.check_min_api_version("7.0.0", "executable_manager")
3637

@@ -75,7 +76,7 @@ local function grep(file, pattern)
7576
if dt.configuration.running_os == "windows" then
7677
-- use find to get the matches
7778
local command = "\\windows\\system32\\find.exe " .. "\"" .. pattern .. "\"" .. " " .. file
78-
local f = io.popen(command)
79+
local f = dtsys.io_popen(command)
7980
local output = f:read("all")
8081
f:close()
8182
-- strip out the first line
@@ -84,7 +85,7 @@ local function grep(file, pattern)
8485
else
8586
-- use grep and just return the answers
8687
local command = "grep " .. pattern .. " " .. file
87-
local f = io.popen(command)
88+
local f = dtsys.io_popen(command)
8889
local output = f:read("all")
8990
f:close()
9091
result = du.split(output, "\n")

tools/get_lib_manpages.lua

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
local dt = require "darktable"
88
local du = require "lib/dtutils"
99
local df = require "lib/dtutils.file"
10+
local dtsys = require "lib/dtutils.system"
1011
local log = require "lib/dtutils.log"
1112
local libname = nil
1213

@@ -33,7 +34,7 @@ local function output_man(d)
3334
libname = name
3435
end
3536
local fname = "/tmp/" .. name .. ".3"
36-
local mf = io.open(fname, "w")
37+
local mf = dtsys.io_open(fname, "w")
3738
if mf then
3839
mf:write(".TH " .. string.upper(name) .. " 3 \"\" \"\" \"Darktable " .. libname .. " functions\"\n")
3940
for _,section in ipairs(keys) do
@@ -59,7 +60,7 @@ end
5960

6061
-- find the libraries
6162

62-
local output = io.popen("cd "..dt.configuration.config_dir.."/lua/lib ;find . -name \\*.lua -print | sort")
63+
local output = dtsys.io_popen("cd "..dt.configuration.config_dir.."/lua/lib ;find . -name \\*.lua -print | sort")
6364

6465
-- loop through the libraries
6566

tools/get_libdoc.lua

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
local dt = require "darktable"
88
local du = require "lib/dtutils"
9+
local dtsys = require "lib/dtutils.system"
910

1011
du.check_min_api_version("3.0.0", "get_libdoc")
1112

@@ -36,7 +37,7 @@ end
3637

3738
-- find the libraries
3839

39-
local output = io.popen("cd "..dt.configuration.config_dir.."/lua/lib ;find . -name \\*.lua -print | sort")
40+
local output = dtsys.io_popen("cd "..dt.configuration.config_dir.."/lua/lib ;find . -name \\*.lua -print | sort")
4041

4142
-- loop through the libraries
4243

0 commit comments

Comments
 (0)