diff --git a/tools/script_manager.lua b/tools/script_manager.lua index becb3d0..80cdbab 100644 --- a/tools/script_manager.lua +++ b/tools/script_manager.lua @@ -54,7 +54,7 @@ local df = require "lib/dtutils.file" local ds = require "lib/dtutils.string" local dtsys = require "lib/dtutils.system" local log = require "lib/dtutils.log" -local debug = require "darktable.debug" +local dtdebug = require "darktable.debug" local gettext = dt.gettext.gettext @@ -62,6 +62,21 @@ local function _(msgid) return gettext(msgid) end +-- figure out where we are running from + +local info = debug.getinfo(1, "S") +local scripts_path = info.source:sub(2) + +dt.print_log("scripts path is " .. scripts_path) + +-- assume user based +local system_based = false + +if string.match(scripts_path, dt.configuration.data_dir) then + dt.print_log("script_manager using system based scripts") + system_based = true +end + -- api check -- du.check_min_api_version("9.3.0", "script_manager") @@ -71,7 +86,7 @@ end -- - - - - - - - - - - - - - - - - - - - - - - - -- script_manager required API version -local SM_API_VER_REQD = "9.3.0" +local SM_API_VER_REQD = "9.7.0" -- path separator local PS = dt.configuration.running_os == "windows" and "\\" or "/" @@ -87,15 +102,29 @@ local DEFAULT_BUTTONS_PER_PAGE = 10 local DEFAULT_LOG_LEVEL = log.warn -local LUA_DIR = dt.configuration.config_dir .. PS .. "lua" +local USER_LUA_DIR = dt.configuration.config_dir .. PS .. "lua" +local SYSTEM_LUA_DIR = dt.configuration.data_dir .. PS .. "lua-scripts" + local LUA_SCRIPT_REPO = "https://github.com/darktable-org/lua-scripts.git" local LUA_API_VER = "API-" .. dt.configuration.api_version_string -- local POWER_ICON = dt.configuration.config_dir .. "/lua/data/data/icons/power.png" -local POWER_ICON = dt.configuration.config_dir .. "/lua/data/icons/path20.png" -local BLANK_ICON = dt.configuration.config_dir .. "/lua/data/icons/blank20.png" +local USER_POWER_ICON = dt.configuration.config_dir .. "/lua/data/icons/path20.png" +local USER_BLANK_ICON = dt.configuration.config_dir .. "/lua/data/icons/blank20.png" +local SYSTEM_POWER_ICON = dt.configuration.data_dir .. "/lua-scripts/data/icons/path20.png" +local SYSTEM_BLANK_ICON = dt.configuration.data_dir .. "/lua-scripts/data/icons/blank20.png" + +local LUA_DIR = USER_LUA_DIR +local POWER_ICON = USER_POWER_ICON +local BLANK_ICON = USER_BLANK_ICON + +if system_based then + LUA_DIR = SYSTEM_LUA_DIR + POWER_ICON = SYSTEM_POWER_ICON + BLANK_ICON = SYSTEM_BLANK_ICON +end -- - - - - - - - - - - - - - - - - - - - - - - - -- P R E F E R E N C E S -- - - - - - - - - - - - - - - - - - - - - - - - @@ -1243,7 +1272,7 @@ end script_manager_running_script = "script_manager" -if check_for_updates or SM_API_VER_REQD > dt.configuration.api_version_string then +if (check_for_updates or SM_API_VER_REQD > dt.configuration.api_version_string) and not system_based 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) @@ -1325,6 +1354,25 @@ end scan_scripts(LUA_DIR) log.msg(log.debug, "finished processing scripts") +if system_based then + -- exec user luarc file if it exists + local luarc = loadfile(USER_LUA_DIR .. "rc") + if luarc then + luarc() + end + + if df.test_file(USER_LUA_DIR, "d") then + LUA_DIR = USER_LUA_DIR + scan_scripts(LUA_DIR) + LUA_DIR = SYSTEM_LUA_DIR + end + + dt.configuration["lua_dir"] = LUA_DIR + + dt.print_log("lua dir is " .. dt.configuration.lua_dir) + -- scan_script(USER_LUA_DIR) +end + -- - - - - - - - - - - - - - - - - - - - - - - - -- U S E R I N T E R F A C E