/
Options.py
875 lines (724 loc) · 31.9 KB
/
Options.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-
### BEGIN LICENSE
# Copyright (c) 2012, Peter Levi <peterlevi@peterlevi.com>
# This program is free software: you can redistribute it and/or modify it
# under the terms of the GNU General Public License version 3, as published
# by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranties of
# MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
# PURPOSE. See the GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program. If not, see <http://www.gnu.org/licenses/>.
### END LICENSE
import hashlib
import logging
import os
from configobj import ConfigObj, DuplicateError
from variety.profile import get_profile_path
from variety.Util import Util
from variety_lib import varietyconfig
logger = logging.getLogger("variety")
TRUTH_VALUES = ["enabled", "1", "true", "on", "yes"]
class Options:
OUTDATED_HASHES = {"clock_filter": ["dca6bd2dfa2b8c4e2db8801e39208f7f"]}
SIMPLE_DOWNLOADERS = [] # set by VarietyWindow at start
IMAGE_SOURCES = [] # set by VarietyWindow at start
CONFIGURABLE_IMAGE_SOURCES = [] # set by VarietyWindow at start
CONFIGURABLE_IMAGE_SOURCES_MAP = {} # set by VarietyWindow at start
class SourceType:
# local files and folders
IMAGE = "image"
FOLDER = "folder"
ALBUM_FILENAME = "album (by filename)"
ALBUM_DATE = "album (by date)"
# special local folders
FAVORITES = "favorites"
FETCHED = "fetched"
# predefined configurable sources
FLICKR = "flickr"
WALLHAVEN = "wallhaven"
BUILTIN_SOURCE_TYPES = {
IMAGE,
FOLDER,
ALBUM_FILENAME,
ALBUM_DATE,
FAVORITES,
FETCHED,
FLICKR,
}
LOCAL_PATH_TYPES = {IMAGE, FOLDER, ALBUM_FILENAME, ALBUM_DATE}
LOCAL_TYPES = {IMAGE, FOLDER, ALBUM_FILENAME, ALBUM_DATE, FAVORITES, FETCHED}
DL_TYPES = {FLICKR}
EDITABLE_DL_TYPES = {FLICKR}
REMOVABLE_TYPES = {FOLDER, IMAGE, ALBUM_FILENAME, ALBUM_DATE} | EDITABLE_DL_TYPES
class LightnessMode:
DARK = 0
LIGHT = 1
def __init__(self):
self.configfile = os.path.join(get_profile_path(), "variety.conf")
def read(self):
self.set_defaults()
try:
config = self.read_config()
needs_writing = self.fix_outdated(config)
try:
self.change_enabled = config["change_enabled"].lower() in TRUTH_VALUES
except Exception:
pass
try:
self.change_on_start = config["change_on_start"].lower() in TRUTH_VALUES
except Exception:
pass
try:
self.change_interval = int(config["change_interval"])
if self.change_interval < 5:
self.change_interval = 5
except Exception:
pass
try:
self.internet_enabled = config["internet_enabled"].lower() in TRUTH_VALUES
except Exception:
pass
try:
self.safe_mode = config["safe_mode"].lower() in TRUTH_VALUES
except Exception:
pass
try:
self.set_wallpaper_script = os.path.expanduser(config["set_wallpaper_script"])
except Exception:
pass
try:
self.get_wallpaper_script = os.path.expanduser(config["get_wallpaper_script"])
except Exception:
pass
try:
self.download_folder = os.path.expanduser(config["download_folder"])
except Exception:
pass
try:
self.download_preference_ratio = max(
0, min(1, float(config["download_preference_ratio"]))
)
except Exception:
pass
try:
self.quota_enabled = config["quota_enabled"].lower() in TRUTH_VALUES
except Exception:
pass
try:
self.quota_size = max(50, int(config["quota_size"]))
except Exception:
pass
try:
self.wallhaven_api_key = str(config["wallhaven_api_key"]).strip()
except Exception:
pass
try:
self.favorites_folder = os.path.expanduser(config["favorites_folder"])
except Exception:
pass
try:
favorites_ops_text = config["favorites_operations"]
self.favorites_operations = list(
[x.strip().split(":") for x in favorites_ops_text.split(";") if x]
)
except Exception:
pass
try:
self.wallpaper_auto_rotate = config["wallpaper_auto_rotate"].lower() in TRUTH_VALUES
except Exception:
pass
try:
self.wallpaper_display_mode = str(config["wallpaper_display_mode"]).strip()
except Exception:
pass
try:
self.fetched_folder = os.path.expanduser(config["fetched_folder"])
except Exception:
pass
try:
self.clipboard_enabled = config["clipboard_enabled"].lower() in TRUTH_VALUES
except Exception:
pass
try:
self.clipboard_use_whitelist = (
config["clipboard_use_whitelist"].lower() in TRUTH_VALUES
)
except Exception:
pass
try:
self.clipboard_hosts = config["clipboard_hosts"].lower().split(",")
except Exception:
pass
try:
icon = config["icon"]
if icon in ["Light", "Dark", "Current", "1", "2", "3", "4", "None"] or (
os.access(icon, os.R_OK) and Util.is_image(icon)
):
self.icon = icon
except Exception:
pass
try:
self.desired_color_enabled = config["desired_color_enabled"].lower() in TRUTH_VALUES
except Exception:
pass
try:
self.desired_color = list(map(int, config["desired_color"].split()))
for i, x in enumerate(self.desired_color):
self.desired_color[i] = max(0, min(255, x))
except Exception:
self.desired_color = None
try:
self.min_size_enabled = config["min_size_enabled"].lower() in TRUTH_VALUES
except Exception:
pass
try:
self.min_size = int(config["min_size"])
self.min_size = max(0, min(100, self.min_size))
except Exception:
pass
try:
self.use_landscape_enabled = config["use_landscape_enabled"].lower() in TRUTH_VALUES
except Exception:
pass
try:
self.lightness_enabled = config["lightness_enabled"].lower() in TRUTH_VALUES
except Exception:
pass
try:
self.lightness_mode = int(config["lightness_mode"])
self.lightness_mode = max(0, min(1, self.lightness_mode))
except Exception:
pass
try:
self.min_rating_enabled = config["min_rating_enabled"].lower() in TRUTH_VALUES
except Exception:
pass
try:
self.min_rating = int(config["min_rating"])
self.min_rating = max(1, min(5, self.min_rating))
except Exception:
pass
try:
self.smart_notice_shown = config["smart_notice_shown"].lower() in TRUTH_VALUES
except Exception:
pass
try:
self.smart_register_shown = config["smart_register_shown"].lower() in TRUTH_VALUES
except Exception:
pass
try:
self.stats_notice_shown = config["stats_notice_shown"].lower() in TRUTH_VALUES
except Exception:
pass
try:
self.smart_enabled = config["smart_enabled"].lower() in TRUTH_VALUES
except Exception:
pass
try:
self.sync_enabled = config["sync_enabled"].lower() in TRUTH_VALUES
except Exception:
pass
try:
self.stats_enabled = config["stats_enabled"].lower() in TRUTH_VALUES
except Exception:
pass
try:
self.copyto_enabled = config["copyto_enabled"].lower() in TRUTH_VALUES
except Exception:
pass
try:
self.copyto_folder = os.path.expanduser(config["copyto_folder"])
except Exception:
pass
try:
self.clock_enabled = config["clock_enabled"].lower() in TRUTH_VALUES
except Exception:
pass
try:
self.clock_filter = config["clock_filter"].strip()
except Exception:
pass
try:
self.clock_font = config["clock_font"]
except Exception:
pass
try:
self.clock_date_font = config["clock_date_font"]
except Exception:
pass
try:
self.quotes_enabled = config["quotes_enabled"].lower() in TRUTH_VALUES
except Exception:
pass
try:
self.quotes_font = config["quotes_font"]
except Exception:
pass
try:
self.quotes_text_color = list(map(int, config["quotes_text_color"].split()))
for i, x in enumerate(self.quotes_text_color):
self.quotes_text_color[i] = max(0, min(255, x))
except Exception:
pass
try:
self.quotes_bg_color = list(map(int, config["quotes_bg_color"].split()))
for i, x in enumerate(self.quotes_bg_color):
self.quotes_bg_color[i] = max(0, min(255, x))
except Exception:
pass
try:
self.quotes_bg_opacity = int(float(config["quotes_bg_opacity"]))
self.quotes_bg_opacity = max(0, min(100, self.quotes_bg_opacity))
except Exception:
pass
try:
self.quotes_text_shadow = config["quotes_text_shadow"].lower() in TRUTH_VALUES
except Exception:
pass
try:
self.quotes_text_color = list(map(int, config["quotes_text_color"].split()))
for i, x in enumerate(self.quotes_text_color):
self.quotes_text_color[i] = max(0, min(255, x))
except Exception:
pass
try:
self.quotes_disabled_sources = config["quotes_disabled_sources"].strip().split("|")
except Exception:
pass
try:
self.quotes_tags = config["quotes_tags"]
except Exception:
pass
try:
self.quotes_authors = config["quotes_authors"]
except Exception:
pass
try:
self.quotes_change_enabled = config["quotes_change_enabled"].lower() in TRUTH_VALUES
except Exception:
pass
try:
self.quotes_change_interval = int(config["quotes_change_interval"])
if self.quotes_change_interval < 10:
self.quotes_change_interval = 10
except Exception:
pass
try:
self.quotes_width = int(float(config["quotes_width"]))
self.quotes_width = max(0, min(100, self.quotes_width))
except Exception:
pass
try:
self.quotes_hpos = int(float(config["quotes_hpos"]))
self.quotes_hpos = max(0, min(100, self.quotes_hpos))
except Exception:
pass
try:
self.quotes_vpos = int(float(config["quotes_vpos"]))
self.quotes_vpos = max(0, min(100, self.quotes_vpos))
except Exception:
pass
try:
self.quotes_max_length = int(config["quotes_max_length"])
self.quotes_max_length = max(0, self.quotes_max_length)
except Exception:
pass
try:
self.quotes_favorites_file = os.path.expanduser(config["quotes_favorites_file"])
except Exception:
pass
try:
self.slideshow_sources_enabled = (
config["slideshow_sources_enabled"].lower() in TRUTH_VALUES
)
except Exception:
pass
try:
self.slideshow_favorites_enabled = (
config["slideshow_favorites_enabled"].lower() in TRUTH_VALUES
)
except Exception:
pass
try:
self.slideshow_downloads_enabled = (
config["slideshow_downloads_enabled"].lower() in TRUTH_VALUES
)
except Exception:
pass
try:
self.slideshow_custom_enabled = (
config["slideshow_custom_enabled"].lower() in TRUTH_VALUES
)
except Exception:
pass
try:
custom_path = config["slideshow_custom_folder"]
if custom_path in ("None", "Default") or not os.path.isdir(custom_path):
self.slideshow_custom_folder = Util.get_xdg_pictures_folder()
else:
self.slideshow_custom_folder = custom_path
except Exception:
pass
try:
slideshow_sort_order = config["slideshow_sort_order"]
if slideshow_sort_order in [
"Random",
"Name, asc",
"Name, desc",
"Date, asc",
"Date, desc",
]:
self.slideshow_sort_order = slideshow_sort_order
except Exception:
pass
try:
self.slideshow_monitor = config["slideshow_monitor"]
except Exception:
pass
try:
slideshow_mode = config["slideshow_mode"]
if slideshow_mode in ["Fullscreen", "Desktop", "Maximized", "Window"]:
self.slideshow_mode = slideshow_mode
except Exception:
pass
try:
self.slideshow_seconds = float(config["slideshow_seconds"])
self.slideshow_seconds = max(0.5, self.slideshow_seconds)
except Exception:
pass
try:
self.slideshow_fade = float(config["slideshow_fade"])
self.slideshow_fade = max(0, min(1, self.slideshow_fade))
except Exception:
pass
try:
self.slideshow_zoom = float(config["slideshow_zoom"])
self.slideshow_zoom = max(0, min(1, self.slideshow_zoom))
except Exception:
pass
try:
self.slideshow_pan = float(config["slideshow_pan"])
self.slideshow_pan = max(0, min(0.20, self.slideshow_pan))
except Exception:
pass
self.sources = []
if "sources" in config:
sources = config["sources"]
for v in sources.values():
try:
self.sources.append(Options.parse_source(v))
except Exception:
logger.debug(lambda: "Cannot parse source: " + v, exc_info=True)
logger.info("Ignoring no longer supported source %s", v)
# automatically append sources for all simple downloaders we have
source_types = set(s[1] for s in self.sources)
for downloader in sorted(self.SIMPLE_DOWNLOADERS, key=lambda dl: dl.get_source_type()):
if downloader.get_source_type() not in source_types:
self.sources.append(
[False, downloader.get_source_type(), downloader.get_description()]
)
self.parse_autosources()
if "filters" in config:
self.filters = []
filters = config["filters"]
for v in filters.values():
try:
self.filters.append(Options.parse_filter(v))
except Exception:
logger.exception(lambda: "Cannot parse filter: " + str(v))
self.parse_autofilters()
if needs_writing:
logger.info(lambda: "Some outdated settings were updated, writing the changes")
self.write()
except Exception:
logger.exception(lambda: "Could not read configuration:")
def fix_outdated(self, config):
changed = False
for key, outdated_hashes in Options.OUTDATED_HASHES.items():
if key in config:
current_hash = hashlib.md5(config[key].encode()).hexdigest()
if current_hash in outdated_hashes:
# entry is outdated: delete it and use the default
logger.warning(
lambda: "Option " + key + " has an outdated value, using the new default"
)
changed = True
del config[key]
return changed
def parse_autosources(self):
try:
with open(varietyconfig.get_data_file("config", "sources.txt"), encoding="utf8") as f:
for line in f:
if not line.strip() or line.strip().startswith("#"):
continue
try:
s = Options.parse_source(line.strip())
if s[1] in [src[1] for src in self.sources]:
continue
self.sources.append(s)
except Exception:
logger.exception(lambda: "Cannot parse source in sources.txt: " + line)
except Exception:
logger.exception(lambda: "Cannot open sources.txt")
def parse_autofilters(self):
try:
with open(varietyconfig.get_data_file("config", "filters.txt"), encoding="utf8") as f:
for line in f:
if not line.strip() or line.strip().startswith("#"):
continue
try:
s = Options.parse_filter(line.strip())
for f in self.filters:
if f[1].lower() == s[1].lower():
f[2] = s[2]
break
else:
# not found at all in filters, append it
self.filters.append(s)
except Exception:
logger.exception(lambda: "Cannot parse filter in filters.txt: " + line)
except Exception:
logger.exception(lambda: "Cannot open filters.txt")
@staticmethod
def parse_source(v):
s = v.strip().split("|")
enabled = s[0].lower() in TRUTH_VALUES
return [enabled, s[1], s[2]]
@staticmethod
def parse_filter(v):
s = v.strip().split("|")
enabled = s[0].lower() in TRUTH_VALUES
return [enabled, s[1], s[2]]
@staticmethod
def get_all_supported_source_types():
return Options.SourceType.BUILTIN_SOURCE_TYPES | Options.get_plugin_source_types()
@staticmethod
def get_downloader_source_types():
return Options.SourceType.DL_TYPES | Options.get_plugin_source_types()
@staticmethod
def get_editable_source_types():
return Options.SourceType.EDITABLE_DL_TYPES | Options.get_configurable_plugin_source_types()
@staticmethod
def get_removable_source_types():
return Options.SourceType.REMOVABLE_TYPES | Options.get_editable_source_types()
@staticmethod
def get_plugin_source_types():
return set(dl.get_source_type() for dl in Options.IMAGE_SOURCES)
@staticmethod
def get_configurable_plugin_source_types():
return set(dl.get_source_type() for dl in Options.CONFIGURABLE_IMAGE_SOURCES)
def set_defaults(self):
self.change_enabled = True
self.change_on_start = False
self.change_interval = 300
self.internet_enabled = True
self.safe_mode = False
self.set_wallpaper_script = os.path.join(get_profile_path(), "scripts", "set_wallpaper")
self.get_wallpaper_script = os.path.join(get_profile_path(), "scripts", "get_wallpaper")
self.download_folder = os.path.join(get_profile_path(), "Downloaded")
self.download_preference_ratio = 0.9
self.quota_enabled = True
self.quota_size = 1000
self.wallhaven_api_key = ""
self.favorites_folder = os.path.join(get_profile_path(), "Favorites")
self.favorites_operations = [
["Downloaded", "Copy"],
["Fetched", "Move"],
["Others", "Copy"],
]
self.wallpaper_auto_rotate = True
self.wallpaper_display_mode = "os"
self.fetched_folder = os.path.join(get_profile_path(), "Fetched")
self.clipboard_enabled = False
self.clipboard_use_whitelist = True
self.clipboard_hosts = "wallhaven.cc,ns223506.ovh.net,wallpapers.net,flickr.com,imgur.com,deviantart.com,interfacelift.com,vladstudio.com".split(
","
)
self.icon = "Light"
self.desired_color_enabled = False
self.desired_color = None
self.min_size_enabled = False
self.min_size = 80
self.use_landscape_enabled = True
self.lightness_enabled = False
self.lightness_mode = Options.LightnessMode.DARK
self.min_rating_enabled = False
self.min_rating = 4
self.smart_notice_shown = False
self.smart_register_shown = False
self.stats_notice_shown = False
self.smart_enabled = False
self.sync_enabled = False
self.stats_enabled = False
self.copyto_enabled = False
self.copyto_folder = "Default"
self.clock_enabled = False
self.clock_font = "Serif 70"
self.clock_date_font = "Serif 30"
self.clock_filter = "-density 100 -font `fc-match -f '%{file[0]}' '%CLOCK_FONT_NAME'` -pointsize %CLOCK_FONT_SIZE -gravity SouthEast -fill '#00000044' -annotate 0x0+[%HOFFSET+58]+[%VOFFSET+108] '%H:%M' -fill white -annotate 0x0+[%HOFFSET+60]+[%VOFFSET+110] '%H:%M' -font `fc-match -f '%{file[0]}' '%DATE_FONT_NAME'` -pointsize %DATE_FONT_SIZE -fill '#00000044' -annotate 0x0+[%HOFFSET+58]+[%VOFFSET+58] '%A, %B %d' -fill white -annotate 0x0+[%HOFFSET+60]+[%VOFFSET+60] '%A, %B %d'"
self.quotes_enabled = False
self.quotes_font = "Serif 30"
self.quotes_text_color = (255, 255, 255)
self.quotes_bg_color = (80, 80, 80)
self.quotes_bg_opacity = 55
self.quotes_text_shadow = False
self.quotes_disabled_sources = []
self.quotes_tags = ""
self.quotes_authors = ""
self.quotes_change_enabled = False
self.quotes_change_interval = 300
self.quotes_width = 70
self.quotes_hpos = 100
self.quotes_vpos = 40
self.quotes_max_length = 250
self.quotes_favorites_file = os.path.join(get_profile_path(), "favorite_quotes.txt")
self.slideshow_sources_enabled = True
self.slideshow_favorites_enabled = True
self.slideshow_downloads_enabled = False
self.slideshow_custom_enabled = False
self.slideshow_custom_folder = Util.get_xdg_pictures_folder()
self.slideshow_sort_order = "Random"
self.slideshow_monitor = "All"
self.slideshow_mode = "Fullscreen"
self.slideshow_seconds = 6
self.slideshow_fade = 0.4
self.slideshow_zoom = 0.2
self.slideshow_pan = 0.05
self.sources = [
[True, Options.SourceType.FAVORITES, "The Favorites folder"],
[True, Options.SourceType.FETCHED, "The Fetched folder"],
[True, Options.SourceType.FOLDER, "/usr/share/backgrounds/"],
[
True,
Options.SourceType.FLICKR,
"user:www.flickr.com/photos/peter-levi/;user_id:93647178@N00;",
],
]
self.filters = [
[False, "Keep original", ""],
[False, "Grayscale", "-type Grayscale"],
[False, "Heavy blur", "-blur 120x40"],
[False, "Oil painting", "-paint 6"],
[False, "Charcoal painting", "-charcoal 3"],
[False, "Pointilism", "-spread 10 -noise 3"],
[False, "Pixellate", "-scale 3% -scale 3333%"],
]
def write(self):
try:
config = ConfigObj(self.configfile, encoding="utf8", default_encoding="utf8")
except Exception:
config = ConfigObj(encoding="utf8", default_encoding="utf8")
config.filename = self.configfile
try:
config["change_enabled"] = str(self.change_enabled)
config["change_on_start"] = str(self.change_on_start)
config["change_interval"] = str(self.change_interval)
config["internet_enabled"] = str(self.internet_enabled)
config["safe_mode"] = str(self.safe_mode)
config["set_wallpaper_script"] = Util.collapseuser(self.set_wallpaper_script)
config["get_wallpaper_script"] = Util.collapseuser(self.get_wallpaper_script)
config["download_folder"] = Util.collapseuser(self.download_folder)
config["download_preference_ratio"] = str(self.download_preference_ratio)
config["quota_enabled"] = str(self.quota_enabled)
config["quota_size"] = str(self.quota_size)
config["wallhaven_api_key"] = str(self.wallhaven_api_key)
config["favorites_folder"] = Util.collapseuser(self.favorites_folder)
config["favorites_operations"] = ";".join(
":".join(x) for x in self.favorites_operations
)
config["wallpaper_auto_rotate"] = str(self.wallpaper_auto_rotate)
config["wallpaper_display_mode"] = str(self.wallpaper_display_mode)
config["fetched_folder"] = Util.collapseuser(self.fetched_folder)
config["clipboard_enabled"] = str(self.clipboard_enabled)
config["clipboard_use_whitelist"] = str(self.clipboard_use_whitelist)
config["clipboard_hosts"] = ",".join(self.clipboard_hosts)
config["icon"] = self.icon
config["desired_color_enabled"] = str(self.desired_color_enabled)
config["desired_color"] = (
" ".join(map(str, self.desired_color)) if self.desired_color else "None"
)
config["min_size_enabled"] = str(self.min_size_enabled)
config["min_size"] = str(self.min_size)
config["use_landscape_enabled"] = str(self.use_landscape_enabled)
config["lightness_enabled"] = str(self.lightness_enabled)
config["lightness_mode"] = str(self.lightness_mode)
config["min_rating_enabled"] = str(self.min_rating_enabled)
config["min_rating"] = str(self.min_rating)
config["smart_notice_shown"] = str(self.smart_notice_shown)
config["smart_register_shown"] = str(self.smart_register_shown)
config["stats_notice_shown"] = str(self.stats_notice_shown)
config["smart_enabled"] = str(self.smart_enabled)
config["sync_enabled"] = str(self.sync_enabled)
config["stats_enabled"] = str(self.stats_enabled)
config["copyto_enabled"] = str(self.copyto_enabled)
config["copyto_folder"] = Util.collapseuser(self.copyto_folder)
config["clock_enabled"] = str(self.clock_enabled)
config["clock_filter"] = self.clock_filter
config["clock_font"] = self.clock_font
config["clock_date_font"] = self.clock_date_font
config["quotes_enabled"] = str(self.quotes_enabled)
config["quotes_font"] = self.quotes_font
config["quotes_text_color"] = " ".join(map(str, self.quotes_text_color))
config["quotes_bg_color"] = " ".join(map(str, self.quotes_bg_color))
config["quotes_bg_opacity"] = str(self.quotes_bg_opacity)
config["quotes_text_shadow"] = str(self.quotes_text_shadow)
config["quotes_disabled_sources"] = "|".join(self.quotes_disabled_sources)
config["quotes_tags"] = self.quotes_tags
config["quotes_authors"] = self.quotes_authors
config["quotes_change_enabled"] = str(self.quotes_change_enabled)
config["quotes_change_interval"] = str(self.quotes_change_interval)
config["quotes_width"] = str(self.quotes_width)
config["quotes_hpos"] = str(self.quotes_hpos)
config["quotes_vpos"] = str(self.quotes_vpos)
config["quotes_max_length"] = str(self.quotes_max_length)
config["quotes_favorites_file"] = Util.collapseuser(self.quotes_favorites_file)
config["slideshow_sources_enabled"] = str(self.slideshow_sources_enabled)
config["slideshow_favorites_enabled"] = str(self.slideshow_favorites_enabled)
config["slideshow_downloads_enabled"] = str(self.slideshow_downloads_enabled)
config["slideshow_custom_enabled"] = str(self.slideshow_custom_enabled)
config["slideshow_custom_folder"] = Util.collapseuser(self.slideshow_custom_folder)
config["slideshow_sort_order"] = self.slideshow_sort_order
config["slideshow_monitor"] = self.slideshow_monitor
config["slideshow_mode"] = self.slideshow_mode
config["slideshow_seconds"] = str(self.slideshow_seconds)
config["slideshow_fade"] = str(self.slideshow_fade)
config["slideshow_zoom"] = str(self.slideshow_zoom)
config["slideshow_pan"] = str(self.slideshow_pan)
config["sources"] = {}
for i, s in enumerate(self.sources):
config["sources"]["src" + str(i + 1)] = str(s[0]) + "|" + str(s[1]) + "|" + s[2]
config["filters"] = {}
for i, f in enumerate(self.filters):
config["filters"]["filter" + str(i + 1)] = str(f[0]) + "|" + f[1] + "|" + f[2]
config.write()
except Exception:
logger.exception(lambda: "Could not write configuration:")
@staticmethod
def set_options(opts):
config = Options().read_config()
for key, value in opts:
config[key] = value
config.write()
def read_config(self):
config = ConfigObj(raise_errors=False, encoding="utf8", default_encoding="utf8")
config.filename = self.configfile
try:
config.reload()
except DuplicateError:
logger.warning(lambda: "Duplicate keys in config file, please fix this")
return config
if __name__ == "__main__":
formatter = logging.Formatter("%(levelname)s:%(name)s: %(funcName)s() '%(message)s'")
logger = logging.getLogger("variety")
logger_sh = logging.StreamHandler()
logger_sh.setFormatter(formatter)
logger.addHandler(logger_sh)
o = Options()
o.read()
print(o.sources)
print(o.filters)
o.write()