@@ -130,6 +130,10 @@ sm.event_registered = false
130
130
sm .widgets = {}
131
131
sm .categories = {}
132
132
133
+ -- set log level for functions
134
+
135
+ sm .log_level = DEFAULT_LOG_LEVEL
136
+
133
137
--[[
134
138
135
139
sm.scripts is a table of tables for containing the scripts
@@ -192,33 +196,55 @@ sm.run = false
192
196
-- F U N C T I O N S
193
197
-- - - - - - - - - - - - - - - - - - - - - - - -
194
198
199
+ ---- ---------------
200
+ -- helper functions
201
+ ---- ---------------
202
+
203
+ local function set_log_level (level )
204
+ local old_log_level = log .log_level ()
205
+ log .log_level (level )
206
+ return old_log_level
207
+ end
208
+
209
+ local function restore_log_level (level )
210
+ log .log_level (level )
211
+ end
212
+
195
213
local function pref_read (name , pref_type )
214
+ local old_log_level = set_log_level (sm .log_level )
196
215
log .msg (log .debug , " name is " .. name .. " and type is " .. pref_type )
197
216
local val = dt .preferences .read (MODULE , name , pref_type )
198
- if not string.match (pref_type , " bool" ) then
199
- log .msg (log .debug , " read value " .. tostring (val ))
200
- end
217
+ log .msg (log .debug , " read value " .. tostring (val ))
218
+ restore_log_level (old_log_level )
201
219
return val
202
220
end
203
221
204
222
local function pref_write (name , pref_type , value )
205
- dt .preferences .write (MODULE , name , pref_type , value )
223
+ local old_log_level = set_log_level (sm .log_level )
224
+ log .msg (log .debug , " writing value " .. tostring (value ) .. " for name " .. name )
225
+ dt .preferences .write (MODULE , name , pref_type , value )
226
+ restore_log_level (old_log_level )
206
227
end
207
228
229
+ ---- ------------
208
230
-- git interface
231
+ ---- ------------
209
232
210
233
local function get_repo_status (repo )
234
+ local old_log_level = set_log_level (sm .log_level )
211
235
local p = io.popen (" cd " .. repo .. CS .. " git status" )
212
236
if p then
213
237
local data = p :read (" *a" )
214
238
p :close ()
215
239
return data
216
240
end
217
241
log .msg (log .error , " unable to get status of " .. repo )
242
+ restore_log_level (old_log_level )
218
243
return nil
219
244
end
220
245
221
246
local function get_current_repo_branch (repo )
247
+ local old_log_level = set_log_level (sm .log_level )
222
248
local branch = nil
223
249
local p = io.popen (" cd " .. repo .. CS .. " git branch --all" )
224
250
if p then
@@ -237,10 +263,12 @@ local function get_current_repo_branch(repo)
237
263
if not branch then
238
264
log .msg (log .error , " no current branch detected in repo_data" )
239
265
end
266
+ restore_log_level (old_log_level )
240
267
return nil
241
268
end
242
269
243
270
local function get_repo_branches (repo )
271
+ local old_log_level = set_log_level (sm .log_level )
244
272
local branches = {}
245
273
local p = io.popen (" cd " .. repo .. CS .. " git pull --all" .. CS .. " git branch --all" )
246
274
if p then
@@ -257,26 +285,32 @@ local function get_repo_branches(repo)
257
285
end
258
286
end
259
287
end
288
+ restore_log_level (old_log_level )
260
289
return branches
261
290
end
262
291
263
292
264
293
local function is_repo_clean (repo_data )
294
+ local old_log_level = set_log_level (sm .log_level )
265
295
if string.match (repo_data , " \n %s-%a.-%a:%s-%a%g-\n " ) then
266
296
log .msg (log .info , " repo is dirty" )
267
297
return false
268
298
else
269
299
log .msg (log .info , " repo is clean" )
270
300
return true
271
301
end
302
+ restore_log_level (old_log_level )
272
303
end
273
304
274
305
local function checkout_repo_branch (repo , branch )
306
+ local old_log_level = set_log_level (sm .log_level )
275
307
log .msg (log .info , " checkout out branch " .. branch .. " from repository " .. repo )
276
308
os.execute (" cd " .. repo .. CS .. " git checkout " .. branch )
309
+ restore_log_level (old_log_level )
277
310
end
278
311
279
312
local function update_combobox_choices (combobox , choice_table , selected )
313
+ local old_log_level = set_log_level (sm .log_level )
280
314
local items = # combobox
281
315
local choices = # choice_table
282
316
for i , name in ipairs (choice_table ) do
@@ -292,11 +326,14 @@ local function update_combobox_choices(combobox, choice_table, selected)
292
326
end
293
327
294
328
combobox .value = selected
329
+ restore_log_level (old_log_level )
295
330
end
296
331
297
332
local function string_trim (str )
333
+ local old_log_level = set_log_level (sm .log_level )
298
334
local result = string.gsub (str , " ^%s+" , " " )
299
335
result = string.gsub (result , " %s+$" , " " )
336
+ restore_log_level (old_log_level )
300
337
return result
301
338
end
302
339
@@ -305,14 +342,17 @@ local function string_dequote(str)
305
342
end
306
343
307
344
local function add_script_category (category )
345
+ local old_log_level = set_log_level (sm .log_level )
308
346
if # sm .categories == 0 or not string.match (du .join (sm .categories , " " ), ds .sanitize_lua (category )) then
309
347
table.insert (sm .categories , category )
310
348
sm .scripts [category ] = {}
311
349
log .msg (log .debug , " created category " .. category )
312
350
end
351
+ restore_log_level (old_log_level )
313
352
end
314
353
315
354
local function get_script_doc (script )
355
+ local old_log_level = set_log_level (sm .log_level )
316
356
local description = nil
317
357
f = io.open (LUA_DIR .. PS .. script .. " .lua" )
318
358
if f then
@@ -325,13 +365,16 @@ local function get_script_doc(script)
325
365
log .msg (log .error , _ (" Cant read from " .. script ))
326
366
end
327
367
if description then
368
+ restore_log_level (old_log_level )
328
369
return description
329
370
else
371
+ restore_log_level (old_log_level )
330
372
return " No documentation available"
331
373
end
332
374
end
333
375
334
376
local function activate (script )
377
+ local old_log_level = set_log_level (sm .log_level )
335
378
local status = nil -- status of start function
336
379
local err = nil -- error message returned if module doesn't start
337
380
log .msg (log .info , " activating " .. script .name )
@@ -364,6 +407,7 @@ local function activate(script)
364
407
status = true
365
408
pref_write (script .script_name , " bool" , true )
366
409
end
410
+ restore_log_level (old_log_level )
367
411
return status
368
412
end
369
413
@@ -376,6 +420,7 @@ local function deactivate(script)
376
420
-- and mark them inactive for the next time darktable starts
377
421
378
422
-- deactivate it....
423
+ local old_log_level = set_log_level (sm .log_level )
379
424
pref_write (script .script_name , " bool" , false )
380
425
if script .data then
381
426
script .data .destroy ()
@@ -397,9 +442,11 @@ local function deactivate(script)
397
442
log .msg (log .info , " setting " .. script .script_name .. " to not start" )
398
443
log .msg (log .screen , script .name .. _ (" will not start when darktable is restarted" ))
399
444
end
445
+ restore_log_level (old_log_level )
400
446
end
401
447
402
448
local function add_script_name (name , path , category )
449
+ local old_log_level = set_log_level (sm .log_level )
403
450
log .msg (log .debug , " category is " .. category )
404
451
log .msg (log .debug , " name is " .. name )
405
452
local script = {
@@ -414,9 +461,11 @@ local function add_script_name(name, path, category)
414
461
if pref_read (script .script_name , " bool" ) then
415
462
activate (script )
416
463
end
464
+ restore_log_level (old_log_level )
417
465
end
418
466
419
467
local function process_script_data (script_file )
468
+ local old_log_level = set_log_level (sm .log_level )
420
469
421
470
-- the script file supplied is category/filename.filetype
422
471
-- the following pattern splits the string into category, path, name, fileename, and filetype
@@ -447,9 +496,11 @@ local function process_script_data(script_file)
447
496
if name then
448
497
add_script_name (name , path , category )
449
498
end
499
+ restore_log_level (old_log_level )
450
500
end
451
501
452
502
local function scan_scripts (script_dir )
503
+ local old_log_level = set_log_level (sm .log_level )
453
504
local script_count = 0
454
505
local find_cmd = " find -L " .. script_dir .. " -name \\ *.lua -print | sort"
455
506
if dt .configuration .running_os == " windows" then
@@ -472,10 +523,12 @@ local function scan_scripts(script_dir)
472
523
end
473
524
end
474
525
end
526
+ restore_log_level (old_log_level )
475
527
return script_count
476
528
end
477
529
478
530
local function update_scripts ()
531
+ local old_log_level = set_log_level (sm .log_level )
479
532
local result = false
480
533
481
534
local git = sm .executables .git
@@ -498,10 +551,12 @@ local function update_scripts()
498
551
dt .print (_ (" lua scripts successfully updated" ))
499
552
end
500
553
554
+ restore_log_level (old_log_level )
501
555
return result
502
556
end
503
557
504
558
local function update_script_update_choices ()
559
+ local old_log_level = set_log_level (sm .log_level )
505
560
local installs = {}
506
561
local pref_string = " "
507
562
for i , repo in ipairs (sm .installed_repositories ) do
@@ -511,9 +566,11 @@ local function update_script_update_choices()
511
566
update_combobox_choices (sm .widgets .update_script_choices , installs , 1 )
512
567
log .msg (log .debug , " repo pref string is " .. pref_string )
513
568
pref_write (" installed_repos" , " string" , pref_string )
569
+ restore_log_level (old_log_level )
514
570
end
515
571
516
572
local function scan_repositories ()
573
+ local old_log_level = set_log_level (sm .log_level )
517
574
local script_count = 0
518
575
local find_cmd = " find -L " .. LUA_DIR .. " -name \\ *.git -print | sort"
519
576
if dt .configuration .running_os == " windows" then
@@ -548,15 +605,18 @@ local function scan_repositories()
548
605
end
549
606
end
550
607
update_script_update_choices ()
608
+ restore_log_level (old_log_level )
551
609
end
552
610
553
611
local function install_scripts ()
612
+ local old_log_level = set_log_level (sm .log_level )
554
613
local url = sm .widgets .script_url .text
555
614
local category = sm .widgets .new_category .text
556
615
557
616
if string.match (du .join (sm .categories , " " ), ds .sanitize_lua (category )) then
558
617
log .msg (log .screen , _ (" category " ) .. category .. _ (" is already in use. Please specify a different category name." ))
559
618
log .msg (log .error , " category " .. category .. " already exists, returning..." )
619
+ restore_log_level (old_log_level )
560
620
return
561
621
end
562
622
@@ -566,6 +626,7 @@ local function install_scripts()
566
626
567
627
if not git then
568
628
dt .print (_ (" ERROR: git not found. Install or specify the location of the git executable." ))
629
+ restore_log_level (old_log_level )
569
630
return
570
631
end
571
632
@@ -607,28 +668,34 @@ local function install_scripts()
607
668
dt .print (_ (" failed to download scripts" ))
608
669
end
609
670
671
+ restore_log_level (old_log_level )
610
672
return result
611
673
end
612
674
613
675
local function clear_button (number )
676
+ local old_log_level = set_log_level (sm .log_level )
614
677
local button = sm .widgets .buttons [number ]
615
678
button .label = " "
616
679
button .tooltip = " "
617
680
button .sensitive = false
618
681
-- button.name = ""
682
+ restore_log_level (old_log_level )
619
683
end
620
684
621
685
local function find_script (category , name )
686
+ local old_log_level = set_log_level (sm .log_level )
622
687
log .msg (log .debug , " looking for script " .. name .. " in category " .. category )
623
688
for _ , script in ipairs (sm .scripts [category ]) do
624
689
if string.match (script .name , " ^" .. ds .sanitize_lua (name ) .. " $" ) then
625
690
return script
626
691
end
627
692
end
693
+ restore_log_level (old_log_level )
628
694
return nil
629
695
end
630
696
631
697
local function populate_buttons (category , first , last )
698
+ local old_log_level = set_log_level (sm .log_level )
632
699
log .msg (log .debug , " category is " .. category .. " and first is " .. first .. " and last is " .. last )
633
700
local button_num = 1
634
701
for i = first , last do
@@ -693,9 +760,11 @@ local function populate_buttons(category, first, last)
693
760
clear_button (i )
694
761
end
695
762
end
763
+ restore_log_level (old_log_level )
696
764
end
697
765
698
766
local function paginate (direction )
767
+ local old_log_level = set_log_level (sm .log_level )
699
768
local category = sm .page_status .category
700
769
log .msg (log .debug , " category is " .. category )
701
770
local num_scripts = # sm .scripts [category ]
@@ -747,9 +816,11 @@ local function paginate(direction)
747
816
sm .widgets .page_status .label = _ (" Page " ) .. cur_page .. _ (" of " ) .. max_pages
748
817
749
818
populate_buttons (category , first , last )
819
+ restore_log_level (old_log_level )
750
820
end
751
821
752
822
local function change_category (category )
823
+ local old_log_level = set_log_level (sm .log_level )
753
824
if not category then
754
825
log .msg (log .debug " setting category to selector value " .. sm .widgets .category_selector .value )
755
826
sm .page_status .category = sm .widgets .category_selector .value
@@ -759,9 +830,11 @@ local function change_category(category)
759
830
end
760
831
761
832
paginate (2 )
833
+ restore_log_level (old_log_level )
762
834
end
763
835
764
836
local function change_num_buttons ()
837
+ local old_log_level = set_log_level (sm .log_level )
765
838
cur_buttons = sm .page_status .num_buttons
766
839
new_buttons = sm .widgets .num_buttons .value
767
840
pref_write (" num_buttons" , " integer" , new_buttons )
@@ -792,9 +865,11 @@ local function change_num_buttons()
792
865
log .msg (log .debug , " num_buttons set to " .. sm .page_status .num_buttons )
793
866
paginate (2 ) -- force the buttons to repopulate
794
867
sm .widgets .main_menu .selected = 3 -- jump back to start/stop scripts
868
+ restore_log_level (old_log_level )
795
869
end
796
870
797
871
local function load_preferences ()
872
+ local old_log_level = set_log_level (sm .log_level )
798
873
-- load the prefs and update settings
799
874
-- update_script_choices
800
875
local pref_string = pref_read (" installed_repos" , " string" )
@@ -836,9 +911,11 @@ local function load_preferences()
836
911
log .msg (log .debug , " set main menu to val " .. val .. " which is " .. sm .widgets .main_menu .value )
837
912
838
913
log .msg (log .debug , " set main menu to " .. sm .widgets .main_menu .value )
914
+ restore_log_level (old_log_level )
839
915
end
840
916
841
917
local function install_module ()
918
+ local old_log_level = set_log_level (sm .log_level )
842
919
if not sm .module_installed then
843
920
dt .register_lib (
844
921
" script_manager" , -- Module name
@@ -868,6 +945,7 @@ local function install_module()
868
945
dt.control.sleep(5000)
869
946
dt.print_log("setting sm expanded true")
870
947
dt.gui.libs["script_manager"].expanded = true]]
948
+ restore_log_level (old_log_level )
871
949
end
872
950
873
951
-- - - - - - - - - - - - - - - - - - - - - - - -
0 commit comments