From 3f6a3e25f1040ce0f9155d9a3aed5f2e85aa6cce Mon Sep 17 00:00:00 2001 From: Bill Ferguson Date: Thu, 16 Mar 2023 20:59:10 -0400 Subject: [PATCH 1/3] added global variable script+_manager_running_script to convey the script name to the darktable shortcut system --- tools/script_manager.lua | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tools/script_manager.lua b/tools/script_manager.lua index eb2db04..a0a0220 100644 --- a/tools/script_manager.lua +++ b/tools/script_manager.lua @@ -325,8 +325,10 @@ local function activate(script) local err = nil -- error message returned if module doesn't start log.msg(log.info, "activating " .. script.name) if script.running == false then + script_manager_running_script = script.name status, err = du.prequire(script.path) log.msg(log.debug, "prequire returned " .. tostring(status) .. " and for err " .. tostring(err)) + script_manager_running_script = nil if status then pref_write(script.script_name, "bool", true) log.msg(log.screen, _("Loaded ") .. script.script_name) From 05d555eae53f35656831306ad81aa316b874ae8a Mon Sep 17 00:00:00 2001 From: Bill Ferguson Date: Sat, 25 Mar 2023 12:46:59 -0400 Subject: [PATCH 2/3] tools/script_manager - let the shortcut system know that script_manager widgets belong to script_manager --- tools/script_manager.lua | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/tools/script_manager.lua b/tools/script_manager.lua index a0a0220..4ae6657 100644 --- a/tools/script_manager.lua +++ b/tools/script_manager.lua @@ -865,6 +865,10 @@ local current_branch = get_current_repo_branch(LUA_DIR) local clean = is_repo_clean(repo_data) local repo = LUA_DIR +-- ensure shortcuts module knows widgets belong to script_manager + +script_manager_running_script = "script_manager" + if current_branch then if sm.executables.git and clean and (current_branch == "master" or string.match(current_branch, "^API%-")) then -- only make changes to clean branches @@ -1137,7 +1141,7 @@ sm.widgets.main_box = dt.new_widget("box"){ sm.widgets.main_stack } - +script_manager_running_script = nil -- - - - - - - - - - - - - - - - - - - - - - - - -- D A R K T A B L E I N T E G R A T I O N -- - - - - - - - - - - - - - - - - - - - - - - - From 21d7e72b0c0d81f0fd91c22cea130055d65243c5 Mon Sep 17 00:00:00 2001 From: Bill Ferguson Date: Sat, 25 Mar 2023 13:01:40 -0400 Subject: [PATCH 3/3] tools/script_manager - resolved conflicts --- tools/script_manager.lua | 119 ++++++++++++++++++++++----------------- 1 file changed, 66 insertions(+), 53 deletions(-) diff --git a/tools/script_manager.lua b/tools/script_manager.lua index 4ae6657..3494bd6 100644 --- a/tools/script_manager.lua +++ b/tools/script_manager.lua @@ -95,6 +95,17 @@ local LUA_SCRIPT_REPO = "https://github.com/darktable-org/lua-scripts.git" local LUA_API_VER = "API-" .. dt.configuration.api_version_string +-- - - - - - - - - - - - - - - - - - - - - - - - +-- P R E F E R E N C E S +-- - - - - - - - - - - - - - - - - - - - - - - - + +dt.preferences.register(MODULE, "check_update", "bool", + "check for updated scripts on start up", + "automatically update scripts to correct version", + true) + +local check_for_updates = dt.preferences.read(MODULE, "check_update", "bool") + -- - - - - - - - - - - - - - - - - - - - - - - - -- L O G L E V E L -- - - - - - - - - - - - - - - - - - - - - - - - @@ -860,66 +871,69 @@ end -- - - - - - - - - - - - - - - - - - - - - - - - -- M A I N P R O G R A M -- - - - - - - - - - - - - - - - - - - - - - - - -local repo_data = get_repo_status(LUA_DIR) -local current_branch = get_current_repo_branch(LUA_DIR) -local clean = is_repo_clean(repo_data) -local repo = LUA_DIR -- ensure shortcuts module knows widgets belong to script_manager script_manager_running_script = "script_manager" -if current_branch then - if sm.executables.git and clean and - (current_branch == "master" or string.match(current_branch, "^API%-")) then -- only make changes to clean branches - local branches = get_repo_branches(LUA_DIR) - if current_branch ~= LUA_API_VER and current_branch ~= "master" then - -- probably upgraded from an earlier api version so get back to master - -- to use the latest version of script_manager to get the proper API - checkout_repo_branch(repo, "master") - log.msg(log.screen, "lua API version reset, please restart darktable") - elseif LUA_API_VER == current_branch then - -- do nothing, we are fine - log.msg(log.debug, "took equal branch, doing nothing") - elseif string.match(LUA_API_VER, "dev") then - -- we are on a dev API version, so checkout the dev - -- api version or checkout/stay on master - log.msg(log.debug, "took the dev branch") - local match = false - for _, branch in ipairs(branches) do - log.msg(log.debug, "checking branch " .. branch .. " against API " .. LUA_API_VER) - if LUA_API_VER == branch then - match = true - log.msg(log.info, "checking out repo development branch " .. branch) - checkout_repo_branch(repo, branch) +if check_for_updates then + local repo_data = get_repo_status(LUA_DIR) + local current_branch = get_current_repo_branch(LUA_DIR) + local clean = is_repo_clean(repo_data) + local repo = LUA_DIR + + if current_branch then + if sm.executables.git and clean and + (current_branch == "master" or string.match(current_branch, "^API%-")) then -- only make changes to clean branches + local branches = get_repo_branches(LUA_DIR) + if current_branch ~= LUA_API_VER and current_branch ~= "master" then + -- probably upgraded from an earlier api version so get back to master + -- to use the latest version of script_manager to get the proper API + checkout_repo_branch(repo, "master") + log.msg(log.screen, "lua API version reset, please restart darktable") + elseif LUA_API_VER == current_branch then + -- do nothing, we are fine + log.msg(log.debug, "took equal branch, doing nothing") + elseif string.match(LUA_API_VER, "dev") then + -- we are on a dev API version, so checkout the dev + -- api version or checkout/stay on master + log.msg(log.debug, "took the dev branch") + local match = false + for _, branch in ipairs(branches) do + log.msg(log.debug, "checking branch " .. branch .. " against API " .. LUA_API_VER) + if LUA_API_VER == branch then + match = true + log.msg(log.info, "checking out repo development branch " .. branch) + checkout_repo_branch(repo, branch) + end end - end - if not match then - if current_branch == "master" then - log.msg(log.info, "staying on master, no dev branch yet") - else - log.msg(log.info, "no dev branch available, checking out master") - checkout_repo_branch(repo, "master") + if not match then + if current_branch == "master" then + log.msg(log.info, "staying on master, no dev branch yet") + else + log.msg(log.info, "no dev branch available, checking out master") + checkout_repo_branch(repo, "master") + end end - end - elseif #branches > 0 and LUA_API_VER > branches[#branches] then - log.msg(log.info, "no newer branches, staying on master") - -- stay on master - else - -- checkout the appropriate branch for API version if it exists - log.msg(log.info, "checking out the appropriate API branch") - local match = false - for _, branch in ipairs(branches) do - log.msg(log.debug, "checking branch " .. branch .. " against API " .. LUA_API_VER) - if LUA_API_VER == branch then - match = true - log.msg(log.info, "checking out repo branch " .. branch) - checkout_repo_branch(repo, branch) - log.msg(log.screen, "you must restart darktable to use the correct version of the lua") + elseif #branches > 0 and LUA_API_VER > branches[#branches] then + log.msg(log.info, "no newer branches, staying on master") + -- stay on master + else + -- checkout the appropriate branch for API version if it exists + log.msg(log.info, "checking out the appropriate API branch") + local match = false + for _, branch in ipairs(branches) do + log.msg(log.debug, "checking branch " .. branch .. " against API " .. LUA_API_VER) + if LUA_API_VER == branch then + match = true + log.msg(log.info, "checking out repo branch " .. branch) + checkout_repo_branch(repo, branch) + log.msg(log.screen, "you must restart darktable to use the correct version of the lua") + end + end + if not match then + log.msg(log.warn, "no matching branch found for " .. LUA_API_VER) end - end - if not match then - log.msg(log.warn, "no matching branch found for " .. LUA_API_VER) end end end @@ -929,7 +943,6 @@ scan_scripts(LUA_DIR) log.msg(log.debug, "finished processing scripts") - -- - - - - - - - - - - - - - - - - - - - - - - - -- U S E R I N T E R F A C E -- - - - - - - - - - - - - - - - - - - - - - - -