Skip to content

Commit 800cbee

Browse files
authored
Merge pull request #407 from wpferguson/script_manager_check_for_updates_pref
script_manager preference - check for updated scripts
2 parents 030b360 + 574f6a9 commit 800cbee

File tree

1 file changed

+66
-54
lines changed

1 file changed

+66
-54
lines changed

tools/script_manager.lua

Lines changed: 66 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,6 @@ end
7070

7171
du.check_min_api_version("5.0.0", "script_manager")
7272

73-
7473
-- - - - - - - - - - - - - - - - - - - - - - - -
7574
-- C O N S T A N T S
7675
-- - - - - - - - - - - - - - - - - - - - - - - -
@@ -94,6 +93,16 @@ local LUA_SCRIPT_REPO = "https://github.com/darktable-org/lua-scripts.git"
9493

9594
local LUA_API_VER = "API-" .. dt.configuration.api_version_string
9695

96+
-- - - - - - - - - - - - - - - - - - - - - - - -
97+
-- P R E F E R E N C E S
98+
-- - - - - - - - - - - - - - - - - - - - - - - -
99+
100+
dt.preferences.register(MODULE, "check_update", "bool",
101+
"check for updated scripts on start up",
102+
"automatically update scripts to correct version",
103+
true)
104+
105+
local check_for_updates = dt.preferences.read(MODULE, "check_update", "bool")
97106

98107
-- - - - - - - - - - - - - - - - - - - - - - - -
99108
-- L O G L E V E L
@@ -858,62 +867,65 @@ end
858867
-- - - - - - - - - - - - - - - - - - - - - - - -
859868
-- M A I N P R O G R A M
860869
-- - - - - - - - - - - - - - - - - - - - - - - -
861-
local repo_data = get_repo_status(LUA_DIR)
862-
local current_branch = get_current_repo_branch(LUA_DIR)
863-
local clean = is_repo_clean(repo_data)
864-
local repo = LUA_DIR
865-
866-
if current_branch then
867-
if sm.executables.git and clean and
868-
(current_branch == "master" or string.match(current_branch, "^API%-")) then -- only make changes to clean branches
869-
local branches = get_repo_branches(LUA_DIR)
870-
if current_branch ~= LUA_API_VER and current_branch ~= "master" then
871-
-- probably upgraded from an earlier api version so get back to master
872-
-- to use the latest version of script_manager to get the proper API
873-
checkout_repo_branch(repo, "master")
874-
log.msg(log.screen, "lua API version reset, please restart darktable")
875-
elseif LUA_API_VER == current_branch then
876-
-- do nothing, we are fine
877-
log.msg(log.debug, "took equal branch, doing nothing")
878-
elseif string.match(LUA_API_VER, "dev") then
879-
-- we are on a dev API version, so checkout the dev
880-
-- api version or checkout/stay on master
881-
log.msg(log.debug, "took the dev branch")
882-
local match = false
883-
for _, branch in ipairs(branches) do
884-
log.msg(log.debug, "checking branch " .. branch .. " against API " .. LUA_API_VER)
885-
if LUA_API_VER == branch then
886-
match = true
887-
log.msg(log.info, "checking out repo development branch " .. branch)
888-
checkout_repo_branch(repo, branch)
870+
871+
if check_for_updates then
872+
local repo_data = get_repo_status(LUA_DIR)
873+
local current_branch = get_current_repo_branch(LUA_DIR)
874+
local clean = is_repo_clean(repo_data)
875+
local repo = LUA_DIR
876+
877+
if current_branch then
878+
if sm.executables.git and clean and
879+
(current_branch == "master" or string.match(current_branch, "^API%-")) then -- only make changes to clean branches
880+
local branches = get_repo_branches(LUA_DIR)
881+
if current_branch ~= LUA_API_VER and current_branch ~= "master" then
882+
-- probably upgraded from an earlier api version so get back to master
883+
-- to use the latest version of script_manager to get the proper API
884+
checkout_repo_branch(repo, "master")
885+
log.msg(log.screen, "lua API version reset, please restart darktable")
886+
elseif LUA_API_VER == current_branch then
887+
-- do nothing, we are fine
888+
log.msg(log.debug, "took equal branch, doing nothing")
889+
elseif string.match(LUA_API_VER, "dev") then
890+
-- we are on a dev API version, so checkout the dev
891+
-- api version or checkout/stay on master
892+
log.msg(log.debug, "took the dev branch")
893+
local match = false
894+
for _, branch in ipairs(branches) do
895+
log.msg(log.debug, "checking branch " .. branch .. " against API " .. LUA_API_VER)
896+
if LUA_API_VER == branch then
897+
match = true
898+
log.msg(log.info, "checking out repo development branch " .. branch)
899+
checkout_repo_branch(repo, branch)
900+
end
889901
end
890-
end
891-
if not match then
892-
if current_branch == "master" then
893-
log.msg(log.info, "staying on master, no dev branch yet")
894-
else
895-
log.msg(log.info, "no dev branch available, checking out master")
896-
checkout_repo_branch(repo, "master")
902+
if not match then
903+
if current_branch == "master" then
904+
log.msg(log.info, "staying on master, no dev branch yet")
905+
else
906+
log.msg(log.info, "no dev branch available, checking out master")
907+
checkout_repo_branch(repo, "master")
908+
end
897909
end
898-
end
899-
elseif #branches > 0 and LUA_API_VER > branches[#branches] then
900-
log.msg(log.info, "no newer branches, staying on master")
901-
-- stay on master
902-
else
903-
-- checkout the appropriate branch for API version if it exists
904-
log.msg(log.info, "checking out the appropriate API branch")
905-
local match = false
906-
for _, branch in ipairs(branches) do
907-
log.msg(log.debug, "checking branch " .. branch .. " against API " .. LUA_API_VER)
908-
if LUA_API_VER == branch then
909-
match = true
910-
log.msg(log.info, "checking out repo branch " .. branch)
911-
checkout_repo_branch(repo, branch)
912-
log.msg(log.screen, "you must restart darktable to use the correct version of the lua")
910+
elseif #branches > 0 and LUA_API_VER > branches[#branches] then
911+
log.msg(log.info, "no newer branches, staying on master")
912+
-- stay on master
913+
else
914+
-- checkout the appropriate branch for API version if it exists
915+
log.msg(log.info, "checking out the appropriate API branch")
916+
local match = false
917+
for _, branch in ipairs(branches) do
918+
log.msg(log.debug, "checking branch " .. branch .. " against API " .. LUA_API_VER)
919+
if LUA_API_VER == branch then
920+
match = true
921+
log.msg(log.info, "checking out repo branch " .. branch)
922+
checkout_repo_branch(repo, branch)
923+
log.msg(log.screen, "you must restart darktable to use the correct version of the lua")
924+
end
925+
end
926+
if not match then
927+
log.msg(log.warn, "no matching branch found for " .. LUA_API_VER)
913928
end
914-
end
915-
if not match then
916-
log.msg(log.warn, "no matching branch found for " .. LUA_API_VER)
917929
end
918930
end
919931
end

0 commit comments

Comments
 (0)