Skip to content

Commit faa3302

Browse files
authored
Merge pull request #566 from sercxanto/fix_dbmaint_log
Fix dbmaint.lua
2 parents 115dbbe + 9bf7efe commit faa3302

File tree

1 file changed

+25
-3
lines changed

1 file changed

+25
-3
lines changed

contrib/dbmaint.lua

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,20 @@ local namespace = dbmaint
115115
-- F U N C T I O N S
116116
-- - - - - - - - - - - - - - - - - - - - - - - -
117117

118+
-------------------
119+
-- helper functions
120+
-------------------
121+
122+
local function set_log_level(level)
123+
local old_log_level = log.log_level()
124+
log.log_level(level)
125+
return old_log_level
126+
end
127+
128+
local function restore_log_level(level)
129+
log.log_level(level)
130+
end
131+
118132
local function scan_film_rolls()
119133
local missing_films = {}
120134

@@ -128,19 +142,21 @@ local function scan_film_rolls()
128142
end
129143

130144
local function scan_images(film)
145+
local old_log_level = set_log_level(DEFAULT_LOG_LEVEL)
131146
local missing_images = {}
132147

133148
if film then
134149
for i = 1, #film do
135150
local image = film[i]
136-
log.log_msg(log.debug, "checking " .. image.filename)
151+
log.msg(log.debug, "checking " .. image.filename)
137152
if not df.check_if_file_exists(image.path .. PS .. image.filename) then
138-
log.log_msg(log.info, image.filename .. " not found")
153+
log.msg(log.info, image.filename .. " not found")
139154
table.insert(missing_images, image)
140155
end
141156
end
142157
end
143158

159+
restore_log_level(old_log_level)
144160
return missing_images
145161
end
146162

@@ -207,6 +223,8 @@ dbmaint.scan_button = dt.new_widget("button"){
207223
clicked_callback = function(this)
208224
local found = nil
209225
local found_text = ""
226+
local old_log_level = set_log_level(DEFAULT_LOG_LEVEL)
227+
log.msg(log.debug, "Button clicked")
210228
if dbmaint.chooser.selected == 1 then -- film rolls
211229
found = scan_film_rolls()
212230
if #found > 0 then
@@ -216,7 +234,7 @@ dbmaint.scan_button = dt.new_widget("button"){
216234
end
217235
end
218236
else
219-
log.log_msg(log.debug, "checking path " .. dt.collection[1].path .. " for missing files")
237+
log.msg(log.debug, "checking path " .. dt.collection[1].path .. " for missing files")
220238
found = scan_images(dt.collection[1].film)
221239
if #found > 0 then
222240
for _, image in ipairs(found) do
@@ -225,10 +243,14 @@ dbmaint.scan_button = dt.new_widget("button"){
225243
end
226244
end
227245
if #found > 0 then
246+
log.msg(log.debug, "found " .. #found .. " missing items")
228247
dbmaint.list_widget.text = found_text
229248
dbmaint.found = found
230249
dbmaint.remove_button.sensitive = true
250+
else
251+
log.msg(log.debug, "no missing items found")
231252
end
253+
restore_log_level(old_log_level)
232254
end,
233255
reset_callback = function(this)
234256
dbmaint.found = nil

0 commit comments

Comments
 (0)