Changed check_min_api_version() to print error messages and throw an error if the minimum api is not satisfied. Updated the scripts to reflect the changed check_min_api_version().

This commit is contained in:
Bill Ferguson
2019-02-20 00:22:05 -05:00
parent 451c7fb956
commit 8b714edb67
47 changed files with 64 additions and 185 deletions

View File

@@ -50,10 +50,7 @@
local darktable = require("darktable")
local du = require "lib/dtutils"
if not du.check_min_api_version("3.0.0") then
darktable.print("ERROR:LabelsToTags failed to load. Lua API version 3.0.0 or later required.")
return
end
du.check_min_api_version("3.0.0", "LabelsToTags")
-- Lua 5.3 no longer has "unpack" but "table.unpack"
unpack = unpack or table.unpack

View File

@@ -38,10 +38,7 @@ local du = require "lib/dtutils"
local dsys = require "lib/dtutils.system"
--Check API version
if not du.check_min_api_version("5.0.0") then
dt.print("ERROR:OpenInExplorer failed to load. Lua API version 5.0.0 or greater required.")
return
end
du.check_min_api_version("5.0.0", "OpenInExplorer")
--Detect OS and modify accordingly--
local proper_install = false

View File

@@ -44,10 +44,7 @@ local filelib = require "lib/dtutils.file"
local autostyle_apply_one_image,autostyle_apply_one_image_event,autostyle_apply,exiftool_attribute,capture
-- Tested it with darktable 1.6.1 and darktable git from 2014-01-25
if not du.check_min_api_version("2.0.2") then
darktable.print("ERROR:autostyle failed to load. Lua API version 2.0.2 or later required.")
return
end
du.check_min_api_version("2.0.2", "autostyle")
-- Receive the event triggered
function autostyle_apply_one_image_event(event,image)

View File

@@ -43,10 +43,7 @@ local gettext = dt.gettext
-- not a number
local NaN = 0/0
if not du.check_min_api_version("3.0.0") then
dt.print("ERROR:clear_GPS failed to load. Lua API version 3.0.0 or later required.")
return
end
du.check_min_api_version("3.0.0", "clear_GPS")
-- Tell gettext where to find the .mo file translating messages for a particular domain

View File

@@ -42,10 +42,7 @@ local debug = require "darktable.debug"
local gettext = dt.gettext
if not du.check_min_api_version("3.0.0") then
dt.print("ERROR:copy_attach_detach_tags failed to load. Lua API version 3.0.0 or later required.")
return
end
du.check_min_api_version("3.0.0", "copy_attach_detach_tags")
-- Tell gettext where to find the .mo file translating messages for a particular domain
gettext.bindtextdomain("copy_attach_detach_tags",dt.configuration.config_dir.."/lua/locale/")

View File

@@ -36,10 +36,7 @@ local darktable = require "darktable"
local du = require "lib/dtutils"
-- Tested with darktable 2.0.1
if not du.check_min_api_version("2.0.0") then
darktable.print("ERROR:cr2hdr failed to load. Lua API version 2.0.0 or later required.")
return
end
du.check_min_api_version("2.0.0", "cr2hdr")
local queue = {}
local processed_files = {}

View File

@@ -67,10 +67,7 @@ local gettext = dt.gettext
local preferences_version = 1 --When releasing an update increment this number by one if changes have been made to the preferences structure that would require a re-initialization
-- works with LUA API version 5.0.0
if not du.check_min_api_version("5.0.0") then
dt.print("ERROR:enfuseAdvanced failed to load. Lua API version 5.0.0 or later required.")
return
end
du.check_min_api_version("5.0.0", "enfuseAdvanced")
-- Tell gettext where to find the .mo file translating messages for a particular domain
gettext.bindtextdomain("enfuseAdvanced",dt.configuration.config_dir.."/lua/")

View File

@@ -28,10 +28,7 @@ local du = require "lib/dtutils"
local df = require "lib/dtutils.file"
local gettext = dt.gettext
if not du.check_min_api_version("4.0.0") then
dt.print("ERROR:fujifilm_ratings failed to load. Lua API version 4.0.0 or later required.")
return
end
du.check_min_api_version("4.0.0", "fujifilm_ratings")
gettext.bindtextdomain("fujifilm_ratings", dt.configuration.config_dir.."/lua/locale/")

View File

@@ -38,10 +38,7 @@ local df = require "lib/dtutils.file"
require "official/yield"
local gettext = dt.gettext
if not du.check_min_api_version("3.0.0") then
dt.print("ERROR:geoJSON_export failed to load. Lua API version 3.0.0 or later required.")
return
end
du.check_min_api_version("3.0.0", "geoJSON_export")
-- Tell gettext where to find the .mo file translating messages for a particular domain
gettext.bindtextdomain("geoJSON_export",dt.configuration.config_dir.."/lua/locale/")

View File

@@ -31,10 +31,7 @@ local df = require "lib/dtutils.file"
require "official/yield"
local gettext = dt.gettext
if not du.check_min_api_version("3.0.0") then
dt.print("ERROR:geoToolbox failed to load. Lua API version 3.0.0 or later required.")
return
end
du.check_min_api_version("3.0.0", "geoToolbox")
-- Tell gettext where to find the .mo file translating messages for a particular domain
gettext.bindtextdomain("geoToolbox",dt.configuration.config_dir.."/lua/locale/")

View File

@@ -70,10 +70,7 @@ local dtsys = require "lib/dtutils.system"
local gettext = dt.gettext
local gimp_widget = nil
if not du.check_min_api_version("5.0.0") then
dt.print("ERROR:gimp failed to load. Lua API version 5.0.0 or greater required.")
return
end
du.check_min_api_version("5.0.0", "gimp")
-- Tell gettext where to find the .mo file translating messages for a particular domain
gettext.bindtextdomain("gimp",dt.configuration.config_dir.."/lua/locale/")

View File

@@ -27,10 +27,7 @@ local df = require "lib/dtutils.file"
local dl = require "lib/dtutils"
local gettext = dt.gettext
if not dl.check_min_api_version("3.0.0") then
dt.print("ERROR:gpx-export failed to load. Lua API version 3.0.0 or later required.")
return
end
dl.check_min_api_version("3.0.0", "gpx-export")
-- Tell gettext where to find the .mo file translating messages for a particular domain
gettext.bindtextdomain("gpx_export",dt.configuration.config_dir.."/lua/locale/")

View File

@@ -55,10 +55,7 @@ local executable_table = {"hugin", "hugin_executor", "pto_gen"}
local PQ = dt.configuration.running_os == "windows" and '"' or "'"
-- works with darktable API version from 5.0.0 on
if not du.check_min_api_version("5.0.0") then
dt.print("ERROR:hugin failed to load. Lua API version 5.0.0 or greater required.")
return
end
du.check_min_api_version("5.0.0", "hugin")
-- Tell gettext where to find the .mo file translating messages for a particular domain
gettext.bindtextdomain("hugin",dt.configuration.config_dir.."/lua/locale/")

View File

@@ -71,10 +71,7 @@ local job = nil
local PS = dt.configuration.running_os == "windows" and "\\" or "/"
-- works with LUA API version 5.0.0
if not du.check_min_api_version("5.0.0") then
dt.print("ERROR:image_stack failed to load. Lua API version 5.0.0 or greater required.")
return
end
du.check_min_api_version("5.0.0", "image_stack")
-- Tell gettext where to find the .mo file translating messages for a particular domain
gettext.bindtextdomain("image_stack",dt.configuration.config_dir.."/lua/locale/")

View File

@@ -42,10 +42,7 @@ local df = require "lib/dtutils.file"
require "official/yield"
local gettext = dt.gettext
if not du.check_min_api_version("3.0.0") then
dt.print("ERROR:kml_export failed to load. Lua API version 3.0.0 or later required.")
return
end
du.check_min_api_version("3.0.0", kml_export)
-- Tell gettext where to find the .mo file translating messages for a particular domain
gettext.bindtextdomain("kml_export",dt.configuration.config_dir.."/lua/locale/")

View File

@@ -39,10 +39,7 @@ local dt = require "darktable"
local du = require "lib/dtutils"
local gettext = dt.gettext
if not du.check_min_api_version("2.0.0") then
dt.print("ERROR:passport_guide failed to load. Lua API version 2.0.0 or later required.")
return
end
du.check_min_api_version("2.0.0", "passport_guide")
-- Tell gettext where to find the .mo file translating messages for a particular domain
gettext.bindtextdomain("passport_guide",dt.configuration.config_dir.."/lua/locale/")

View File

@@ -57,10 +57,7 @@ if not df.check_if_bin_exists("pdflatex") then
return
end
if not du.check_min_api_version("4.0.0") then
dt.print("ERROR:pdf_slideshow failed to load. Lua API version 4.0.0 or greater required.")
return
end
du.check_min_api_version("4.0.0", "pdf_slideshow")
dt.preferences.register
("pdf_slideshow","open with","string",

View File

@@ -50,10 +50,7 @@ local debug = require "darktable.debug"
local gettext = dt.gettext
if not du.check_min_api_version("3.0.0") then
dt.print("ERROR:quicktag failed to load. Lua API version 3.0.0 or later required.")
return
end
du.check_min_api_version("3.0.0", "quicktag")
-- Tell gettext where to find the .mo file translating messages for a particular domain
gettext.bindtextdomain("quicktag",dt.configuration.config_dir.."/lua/locale/")

View File

@@ -42,10 +42,7 @@ local dt = require "darktable"
local du = require "lib/dtutils"
-- added version check
if not du.check_min_api_version("3.0.0") then
dt.print("ERROR:rate_group failed to load. Lua API version 3.0.0 or later required.")
return
end
du.check_min_api_version("3.0.0", "rate_group")
local function apply_rating(rating)
local images = dt.gui.action_images

View File

@@ -33,10 +33,7 @@ local du = require "lib/dtutils"
local debug = require "darktable.debug"
-- check API version
if not du.check_min_api_version("3.0.0") then
darktable.print("ERROR:rename_tags failed to load. Lua API version 3.0.0 or later required.")
return
end
du.check_min_api_version("3.0.0", "rename-tags")
-- GUI entries
local old_tag = darktable.new_widget("entry") { tooltip = "Enter old tag" }

View File

@@ -22,10 +22,7 @@ local dt = require "darktable"
local du = require "lib/dtutils"
local gettext = dt.gettext
if not du.check_min_api_version("3.0.0") then
dt.print("ERROR:select_untagged failed to load. Lua API version 3.0.0 or later required.")
return
end
du.check_min_api_version("3.0.0", "select_untagged")
-- Tell gettext where to find the .mo file translating messages for a particular domain
gettext.bindtextdomain("select_untagged",dt.configuration.config_dir.."/lua/locale/")

View File

@@ -30,10 +30,7 @@ local df = require "lib/dtutils.file"
require "official/yield"
local gettext = dt.gettext
if not du.check_min_api_version("2.0.2") then
dt.print("ERROR:slideshowMusic failed to load. Lua API version 2.0.2 or greater required.")
return
end
du.check_min_api_version("2.0.2", "slideshowMusic")
-- Tell gettext where to find the .mo file translating messages for a particular domain
gettext.bindtextdomain("slideshowMusic",dt.configuration.config_dir.."/lua/locale/")

View File

@@ -36,10 +36,7 @@ local df = require "lib/dtutils.file"
require "official/yield"
local gettext = dt.gettext
if not du.check_min_api_version("2.0.1") then
dt.print("ERROR:video_mencoder failed to load. Lua API version 2.0.1 or later required.")
return
end
du.check_min_api_version("2.0.1", "video_mencoder")
-- Tell gettext where to find the .mo file translating messages for a particular domain
gettext.bindtextdomain("video_mencoder",dt.configuration.config_dir.."/lua/locale/")

View File

@@ -56,10 +56,7 @@ local dt = require "darktable"
local du = require "lib/dtutils"
--check API version
if not du.check_min_api_version("3.0.0") then
dt.print("ERROR:gettextExample failed to load. Lua API version 3.0.0 or greater required.")
return
end
du.check_min_api_version("3.0.0", "gettextExample")
-- Not translated Text
dt.print_error("Hello World!")

View File

@@ -29,10 +29,7 @@ USAGE
local dt = require "darktable"
local du = require "lib/dtutils"
if not du.check_min_api_version("2.0.0") then
dt.print("ERROR:hello_world failed to load. Lua API version 2.0.0 or greater required.")
return
end
du.check_min_api_version("2.0.0", "hello_world")
dt.print("hello, world")

View File

@@ -33,10 +33,7 @@ https://www.darktable.org/lua-api/index.html.php#darktable_new_widget
local dt = require "darktable"
local du = require "lib/dtutils"
if not du.check_min_api_version("3.0.0") then
dt.print("ERROR:moduleExample failed to load. Lua API version 3.0.0 or greater required.")
return
end
du.check_min_api_version("3.0.0", "moduleExample")
-- add a new lib
local check_button = dt.new_widget("check_button"){label = "MyCheck_button", value = true}

View File

@@ -86,10 +86,7 @@ end
screen stating that you couldn't load because the minimum api version wasn't met.
]]
if not du.check_min_api_version("5.0.0") then
dt.print("ERROR:mulit_os failed to load: Lua API version 5.0.0 or greater required.")
return
end
du.check_min_api_version("5.0.0", "multi_os")
--[[
copy_image_attributes is a local subroutine to copy image attributes in the database from the raw image

View File

@@ -24,10 +24,7 @@ USAGE
local dt = require "darktable"
local du = require "lib/dtutils"
if not du.check_min_api_version("2.0.1") then
dt.print("ERROR:preferenceExamples failed to load. Lua API version 2.0.1 or greater required.")
return
end
du.check_min_api_version("2.0.1", "preferenceExamples")
dt.preferences.register("preferenceExamples", -- script: This is a string used to avoid name collision in preferences (i.e namespace). Set it to something unique, usually the name of the script handling the preference.
"preferenceExamplesString", -- name

View File

@@ -22,10 +22,7 @@ USAGE
local dt = require "darktable"
local du = require "lib/dtutils"
if not du.check_min_api_version("5.0.0") then
dt.print("ERROR:printExamples failed to load. Lua API version 5.0.0 or greater required.")
return
end
du.check_min_api_version("5.0.0", "printExamples")
-- Will print a string to the darktable control log (the long
-- overlayed window that appears over the main panel).

View File

@@ -28,10 +28,7 @@ prints the operating system
local dt = require "darktable"
local du = require "lib/dtutils"
if not du.check_min_api_version("5.0.0") then
dt.print("ERROR:running_os not loaded. Lua API version 5.0.0 or greater required.")
return
end
du.check_min_api_version("5.0.0", "running_os")
dt.print("You are running: "..dt.configuration.running_os)

View File

@@ -37,33 +37,35 @@ dtutils.libdoc.functions["check_min_api_version"] = {
Synopsis = [[check the minimum required api version against the current api version]],
Usage = [[local du = require "lib/dtutils"
local result = du.check_min_api_version(min_api)
min_api - string - the api version that the application was written for (example: "5.0.0")]],
local result = du.check_min_api_version(min_api, script_name)
min_api - string - the api version that the application was written for (example: "5.0.0")
script_name - string - the name of the script]],
Description = [[check_min_api_version compares the minimum api required for the appllication to
run against the current api version. The minimum api version is typically the api version that
was current when the application was created. If the minimum api version is not met, then an
error message is printed to the log.
run against the current api version. The minimum api version is typically the api version that
was current when the application was created. If the minimum api version is not met, then an
error message is printed saying the script_name failed to load, then an error is thrown causing the
program to stop executing.
This function is intended to replace darktable.configuration.check_version(). The application code
This function is intended to replace darktable.configuration.check_version(). The application code
won't have to be updated each time the api changes because this only checks the minimum version required.]],
Return_Value = [[result - true if the minimum api version is available, false if not.]],
Limitations = [[]],
Example = [[check_min_api_version("5.0.0") returns true if the api is greater or equal to 5.0.0 otherwise an
error message is printed to the log and false is returned.]],
Limitations = [[When using the default handler on a script being executed from the luarc file, the error thrown
will stop the luarc file from executing any remaining statements. This limitation does not apply to script_manger.]],
Example = [[check_min_api_version("5.0.0") does nothing if the api is greater or equal to 5.0.0 otherwise an
error message is printed and an error is thrown stopping execution of the script.]],
See_Also = [[]],
Reference = [[]],
License = [[]],
Copyright = [[]],
}
function dtutils.check_min_api_version(min_api)
function dtutils.check_min_api_version(min_api, script_name)
local current_api = dt.configuration.api_version_string
if min_api <= current_api then
return true
else
if min_api > current_api then
dt.print_error("This application is written for lua api version " .. min_api .. " or later.")
dt.print_error("The current lua api version is " .. current_api)
return false
dt.print("ERROR:" .. script_name .. " failed to load. Lua API version " .. min_api .. " or later required.")
error("Minimum API " .. min_api .. " not met for " .. script_name .. ".", 0)
end
end

View File

@@ -25,9 +25,7 @@ dtutils_file.libdoc = {
local gettext = dt.gettext
if not du.check_min_api_version("5.0.0") then
return
end
du.check_min_api_version("5.0.0", "dtutils.file")
-- Tell gettext where to find the .mo file translating messages for a particular domain
gettext.bindtextdomain("dtutils.file",dt.configuration.config_dir.."/lua/locale/")

View File

@@ -32,10 +32,7 @@ local du = require "lib/dtutils"
local https = require "ssl.https"
local cjson = require "cjson"
if not du.check_min_api_version("2.0.0") then
dt.print("ERROR:check_for_updates not loaded. Lua API version 2.0.0 or greater required.")
return
end
du.check_min_api_version("2.0.0", "check_for_updates")
-- compare two version strings of the form "major.minor.patch"
-- returns -1, 0, 1 if the first version is smaller, equal, greater than the second version,

View File

@@ -28,10 +28,7 @@ USAGE
local dt = require "darktable"
local du = require "lib/dtutils"
if not du.check_min_api_version("3.0.0") then
dt.print("ERROR:copy_paste_metadata not loaded. Lua API version 3.0.0 or greater required.")
return
end
du.check_min_api_version("3.0.0", "copy_paste_metadata")
-- set this to "false" if you don't want to overwrite metadata fields
-- (title, description, creator, publisher and rights) that are already set

View File

@@ -31,10 +31,7 @@ all tags longer than the given length will be automatically deleted at every res
local dt = require "darktable"
local du = require "lib/dtutils"
if not du.check_min_api_version("2.0.0") then
dt.print("ERROR:delete_long_tags not loaded. Lua API version 2.0.0 or greater required.")
return
end
du.check_min_api_version("2.0.0", "delete_long_tags")
dt.preferences.register("delete_long_tags", "length", "integer",
"maximum length of tags to keep",

View File

@@ -29,10 +29,7 @@ all tags that are not used will be automatically deleted at every restart
local dt = require "darktable"
local du = require "lib/dtutils"
if not du.check_min_api_version("5.0.0") then
dt.print("ERROR:delete_unused_tags not loaded. Lua API version 5.0.0 or greater required.")
return
end
du.check_min_api_version("5.0.0", "delete_unused_tags")
-- deleting while iterating the tags list seems to break the iterator!
local unused_tags = {}

View File

@@ -38,10 +38,7 @@ local df = require "lib/dtutils.file"
require "official/yield"
local gettext = dt.gettext
if not du.check_min_api_version("3.0.0") then
dt.print("ERROR:enfuse not loaded. Lua API version 3.0.0 or greater required.")
return
end
du.check_min_api_version("3.0.0", "enfuse")
-- Tell gettext where to find the .mo file translating messages for a particular domain
gettext.bindtextdomain("enfuse",dt.configuration.config_dir.."/lua/locale/")

View File

@@ -39,10 +39,7 @@ local du = require "lib/dtutils"
require "darktable.debug"
require "official/yield"
if not du.check_min_api_version("2.1.0") then
dt.print("ERROR:generate_image_txt not loaded. Lua API version 2.1.0 or greater required.")
return
end
du.check_min_api_version("2.1.0", "generate_image_txt")
dt.preferences.register("generate_image_txt",
"enabled",

View File

@@ -31,10 +31,7 @@ This plugin will add a widget at the bottom of the left column in lighttable mod
local dt = require "darktable"
local du = require "lib/dtutils"
if not du.check_min_api_version("2.0.0") then
dt.print("ERROR:image_path_in_ui not loaded. Lua API version 2.0.0 or greater required.")
return
end
du.check_min_api_version("2.0.0", "image_path_in_ui")
local main_label = dt.new_widget("label"){selectable = true, ellipsize = "middle", halign = "start"}

View File

@@ -36,10 +36,7 @@ increase it if you need more temporary selection buffers
local dt = require "darktable"
local du = require "lib/dtutils"
if not du.check_min_api_version("2.0.0") then
dt.print("ERROR:save_selection not loaded. Lua API version 2.0.0 or greater required.")
return
end
du.check_min_api_version("2.0.0", "save_selection")
local buffer_count = 5

View File

@@ -37,10 +37,7 @@ local dt = require "darktable"
local du = require "lib/dtutils"
require "official/yield"
if not du.check_min_api_version("2.0.0") then
dt.print("ERROR:selection_to_pdf not loaded. Lua API version 2.0.0 or greater required.")
return
end
du.check_min_api_version("2.0.0", "selection_to_pdf")
dt.preferences.register
("selection_to_pdf","Open with","string",

View File

@@ -32,6 +32,8 @@ local dt = require "darktable"
local du = require "lib/dtutils"
local df = require "lib/dtutils.file"
du.check_min_api_version("5.0.0", "executable_manager")
local PS = dt.configuration.running_os == "windows" and "\\" or "/"
local gettext = dt.gettext

View File

@@ -30,6 +30,8 @@ local df = require "lib/dtutils.file"
local log = require "lib/dtutils.log"
local dtsys = require "lib/dtutils.system"
du.check_min_api_version("5.0.0", "gen_I18n_mo")
-- figure out the path separator
local PS = dt.configuration.running_os == "windows" and "\\" or "/"

View File

@@ -10,10 +10,7 @@ local df = require "lib/dtutils.file"
local log = require "lib/dtutils.log"
local libname = nil
if not du.check_min_api_version("3.0.0") then
dt.print("ERROR: get_lib_manpages failed to load. Lua API version 3.0.0 or greater required.")
return
end
du.check_min_api_version("3.0.0", "get_lib_manpages")
local keys = {"Name", "Synopsis", "Usage", "Description", "Return_Value", "Limitations",
"Example", "See_Also", "Reference", "License", "Copyright"}

View File

@@ -7,10 +7,7 @@
local dt = require "darktable"
local du = require "lib/dtutils"
if not du.check_min_api_version("3.0.0") then
dt.print("ERROR: get_libdoc failed to load. Lua API version 3.0.0 or greater required.")
return
end
du.check_min_api_version("3.0.0", "get_libdoc")
local keys = {"Name", "Synopsis", "Usage", "Description", "Return_Value", "Limitations",
"Example", "See_Also", "Reference", "License", "Copyright"}

1
tools/plugin_manager.lua Symbolic link
View File

@@ -0,0 +1 @@
/home/bill/src/plugins/lua-scripts/tools/plugin_manager.lua

View File

@@ -455,10 +455,7 @@ end
-- api check
if not du.check_min_api_version("5.0.0") then
dt.print("ERROR:script_manager failed to load. Lua API version 5.0.0 or greater required.")
return
end
du.check_min_api_version("5.0.0")
-- set up tables to contain all the widgets and choices