def get_sanitized_config(parent): options = parent.options config = dict(options.__dict__) del config['configfile'] # remove all references to local folders and files: config['favorites_folder'] = \ 'Default' if options.favorites_folder == os.path.expanduser(u"~/.config/variety/Favorites") else 'Changed' config['download_folder'] = \ 'Default' if options.download_folder == os.path.expanduser(u"~/.config/variety/Downloaded") else 'Changed' config['fetched_folder'] = \ 'Default' if options.fetched_folder == os.path.expanduser(u"~/.config/variety/Fetched") else 'Changed' config['copyto_folder'] = \ 'Default' if options.copyto_folder == 'Default' else 'Changed' config['quotes_favorites_file'] = \ 'Default' if options.quotes_favorites_file == os.path.expanduser(u"~/.config/variety/favorite_quotes.txt") else 'Changed' config['slideshow_custom_folder'] = \ 'Default' if options.slideshow_custom_folder == Util.get_xdg_pictures_folder() else 'Changed' config['sources'] = [s for s in options.sources if s[1] not in (Options.SourceType.FOLDER, Options.SourceType.IMAGE)] config['favorites_operations'] = [ ("custom_folder" if place not in ["/", "Downloaded", "Fetched", "Others"] else place, op) for (place, op) in options.favorites_operations] # add some general OS and desktop environment information config["platform"] = str(platform.platform()) distro = platform.linux_distribution() config["linux_distribution"] = distro config["linux_distribution_distname"] = str(distro[0]) config["linux_distribution_version"] = str(distro[1]) config["linux_distribution_id"] = str(distro[2]) config["desktop_session"] = str(os.getenv('DESKTOP_SESSION')) # add screen info - resolution, monitor count, etc. config["total_screen_width"] = Gdk.Screen.get_default().get_width() config["total_screen_height"] = Gdk.Screen.get_default().get_height() config["monitor_count"] = Gdk.Screen.get_default().get_n_monitors() try: rect = Gdk.Screen.get_default().get_monitor_geometry(Gdk.Screen.get_default().get_primary_monitor()) config['primary_monitor_width'] = rect.width config['primary_monitor_height'] = rect.height except: pass # add some other Variety-specifics things: config["variety_version"] = varietyconfig.get_version() config["image_count"] = parent.image_count with open(os.path.join(parent.config_folder, ".firstrun"), 'r') as f: config["first_run_timestamp"] = f.read() # add a timestamp config["report_timestamp"] = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) return config
def test_get_xdg_pictures_folder(self): self.assertEqual(os.path.expanduser("~/Pictures"), Util.get_xdg_pictures_folder())
def set_defaults(self): self.change_enabled = True self.change_on_start = False self.change_interval = 300 self.safe_mode = False 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.favorites_folder = os.path.join(get_profile_path(), "Favorites") self.favorites_operations = [ ["Downloaded", "Copy"], ["Fetched", "Move"], ["Others", "Copy"], ] 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 = "Ubuntu Condensed, 70" self.clock_date_font = "Ubuntu Condensed, 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 = "Bitstream Charter 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 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.safe_mode = config["safe_mode"].lower() in TRUTH_VALUES 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.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.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([ True, 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 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.safe_mode = config["safe_mode"].lower() in TRUTH_VALUES except Exception: pass try: self.download_enabled = config["download_enabled"].lower() in TRUTH_VALUES except Exception: pass try: self.download_interval = int(config["download_interval"]) if self.download_interval < 60: self.download_interval = 60 except Exception: pass try: self.download_folder = os.path.expanduser(config["download_folder"]) except Exception: pass try: self.quota_enabled = config["quota_enabled"].lower() in TRUTH_VALUES except Exception: pass try: self.quota_size = int(config["quota_size"]) if self.quota_size < 50: self.quota_size = 50 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.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", "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 = 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.facebook_show_dialog = config["facebook_show_dialog"].lower() in TRUTH_VALUES except Exception: pass try: self.facebook_message = config["facebook_message"].strip() 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 = 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 = 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 = 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_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(): 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 if "sources" in config: self.sources = [] sources = config["sources"] for v in sources.values(): try: self.sources.append(Options.parse_source(v)) except Exception: logger.exception(lambda: "Cannot parse source: " + v) self.parse_autosources() for s in self.sources: if s[1] in (Options.SourceType.RECOMMENDED,) and not self.smart_enabled: s[0] = False 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 set_defaults(self): self.change_enabled = True self.change_on_start = False self.change_interval = 300 self.safe_mode = False self.download_enabled = True self.download_interval = 600 self.download_folder = os.path.expanduser(u"~/.config/variety/Downloaded") self.quota_enabled = True self.quota_size = 500 self.favorites_folder = os.path.expanduser(u"~/.config/variety/Favorites") self.favorites_operations = [["Downloaded", "Copy"], ["Fetched", "Move"], ["Others", "Copy"]] self.fetched_folder = os.path.expanduser(u"~/.config/variety/Fetched") self.clipboard_enabled = False self.clipboard_use_whitelist = True self.clipboard_hosts = "alpha.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 = True self.sync_enabled = True self.stats_enabled = True self.facebook_show_dialog = True self.facebook_message = "" self.copyto_enabled = False self.copyto_folder = "Default" self.clock_enabled = False self.clock_font = "Ubuntu Condensed, 70" self.clock_date_font = "Ubuntu Condensed, 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 = "Bitstream Charter 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_favorites_file = os.path.expanduser(u"~/.config/variety/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.DESKTOPPR, "Random wallpapers from Desktoppr.co"], [True, Options.SourceType.BING, "Bing Photo of the Day"], [True, Options.SourceType.UNSPLASH, "High-resolution photos from Unsplash.com"], [False, Options.SourceType.APOD, "NASA's Astronomy Picture of the Day"], [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, "Pencil sketch", """-colorspace gray \( +clone -tile ~/.config/variety/pencil_tile.png -draw "color 0,0 reset" +clone +swap -compose color_dodge -composite \) -fx 'u*.2+v*.8'"""], [False, "Pointilism", "-spread 10 -noise 3"], [False, "Pixellate", "-scale 3% -scale 3333%"] ]
def set_defaults(self): self.change_enabled = True self.change_on_start = False self.change_interval = 300 self.safe_mode = False self.download_enabled = True self.download_interval = 600 self.download_folder = os.path.expanduser( "~/.config/variety/Downloaded") self.quota_enabled = True self.quota_size = 500 self.favorites_folder = os.path.expanduser( "~/.config/variety/Favorites") self.favorites_operations = [["Downloaded", "Copy"], ["Fetched", "Move"], ["Others", "Copy"]] self.fetched_folder = os.path.expanduser("~/.config/variety/Fetched") self.clipboard_enabled = False self.clipboard_use_whitelist = True self.clipboard_hosts = "alpha.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 = "Ubuntu Condensed, 70" self.clock_date_font = "Ubuntu Condensed, 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 = "Bitstream Charter 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_favorites_file = os.path.expanduser( "~/.config/variety/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.DESKTOPPR, "Random wallpapers from Desktoppr.co" ], [True, Options.SourceType.BING, "Bing Photo of the Day"], [ True, Options.SourceType.UNSPLASH, "High-resolution photos from Unsplash.com" ], [ False, Options.SourceType.APOD, "NASA's Astronomy Picture of the Day" ], [ 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, "Pencil sketch", """-colorspace gray \( +clone -tile ~/.config/variety/pencil_tile.png -draw "color 0,0 reset" +clone +swap -compose color_dodge -composite \) -fx 'u*.2+v*.8'""" ], [False, "Pointilism", "-spread 10 -noise 3"], [False, "Pixellate", "-scale 3% -scale 3333%"] ]
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.safe_mode = config["safe_mode"].lower() in TRUTH_VALUES except Exception: pass try: self.download_enabled = config["download_enabled"].lower( ) in TRUTH_VALUES except Exception: pass try: self.download_interval = int(config["download_interval"]) if self.download_interval < 60: self.download_interval = 60 except Exception: pass try: self.download_folder = os.path.expanduser( config["download_folder"]) except Exception: pass try: self.quota_enabled = config["quota_enabled"].lower( ) in TRUTH_VALUES except Exception: pass try: self.quota_size = int(config["quota_size"]) if self.quota_size < 50: self.quota_size = 50 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.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", "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 = 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.facebook_show_dialog = config[ "facebook_show_dialog"].lower() in TRUTH_VALUES except Exception: pass try: self.facebook_message = config["facebook_message"].strip() 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 = 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 = 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 = 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_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(): 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 if "sources" in config: self.sources = [] sources = config["sources"] for v in sources.values(): try: self.sources.append(Options.parse_source(v)) except Exception: logger.exception(lambda: "Cannot parse source: " + v) self.parse_autosources() for s in self.sources: if s[1] in (Options.SourceType.RECOMMENDED, ) and not self.smart_enabled: s[0] = False 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 test_get_xdg_pictures_folder(self): self.assertEquals(os.path.expanduser('~/Pictures'), Util.get_xdg_pictures_folder())