Commit 819dddcf authored by John Stowers's avatar John Stowers

Dont crash on missing directories

parent 22f007d7
3.0.3
* Autostart nautilus at login if it is configured to show
desktop icons (bug 648087)
* Improved robustness for missing theme/icon
directories (bug 648735)
3.0.2
* Really tweak window theme - both the fallback and the
......
......@@ -20,6 +20,7 @@ import os.path
from gi.repository import Gtk
import gtweak
from gtweak.utils import walk_directories
from gtweak.tweakmodel import TweakGroup
from gtweak.widgets import GSettingsSwitchTweak, GSettingsComboTweak, build_horizontal_sizegroup
......@@ -33,14 +34,11 @@ class GtkThemeSwitcher(GSettingsComboTweak):
def _get_valid_themes(self):
""" Only shows themes that have variations for gtk+-3 and gtk+-2 """
valid = []
dirs = ( os.path.join(gtweak.DATA_DIR, "themes"),
os.path.join(os.path.expanduser("~"), ".themes"))
for thdir in dirs:
for t in os.listdir(thdir):
if os.path.exists(os.path.join(thdir, t, "gtk-2.0")) and \
os.path.exists(os.path.join(thdir, t, "gtk-3.0")):
valid.append(t)
valid = walk_directories(dirs, lambda d:
os.path.exists(os.path.join(d, "gtk-2.0")) and \
os.path.exists(os.path.join(d, "gtk-3.0")))
return valid
class IconThemeSwitcher(GSettingsComboTweak):
......@@ -52,14 +50,11 @@ class IconThemeSwitcher(GSettingsComboTweak):
**options)
def _get_valid_icon_themes(self):
valid = []
dirs = ( os.path.join(gtweak.DATA_DIR, "icons"),
os.path.join(os.path.expanduser("~"), ".icons"))
for thdir in dirs:
for t in os.listdir(thdir):
if os.path.isdir(os.path.join(thdir, t)) and \
not os.path.exists(os.path.join(thdir, t, "cursors")):
valid.append(t)
valid = walk_directories(dirs, lambda d:
os.path.isdir(d) and \
not os.path.exists(os.path.join(d, "cursors")))
return valid
class CursorThemeSwitcher(GSettingsComboTweak):
......@@ -71,14 +66,11 @@ class CursorThemeSwitcher(GSettingsComboTweak):
**options)
def _get_valid_cursor_themes(self):
valid = []
dirs = ( os.path.join(gtweak.DATA_DIR, "icons"),
os.path.join(os.path.expanduser("~"), ".icons"))
for thdir in dirs:
for t in os.listdir(thdir):
if os.path.isdir(os.path.join(thdir, t)) and \
os.path.exists(os.path.join(thdir, t, "cursors")):
valid.append(t)
valid = walk_directories(dirs, lambda d:
os.path.isdir(d) and \
os.path.exists(os.path.join(d, "cursors")))
return valid
sg = build_horizontal_sizegroup()
......
......@@ -18,6 +18,7 @@
import os.path
import gtweak
from gtweak.utils import walk_directories
from gtweak.tweakmodel import TweakGroup
from gtweak.widgets import GConfComboTweak, build_horizontal_sizegroup
from gtweak.gconf import GConfSetting
......@@ -45,14 +46,12 @@ class WindowThemeSwitcher(GConfComboTweak):
#also need to change the fallback (metacity) window theme
self.gconf_metacity = GConfSetting("/apps/metacity/general/theme", str)
def _get_valid_themes(self):
valid = []
dirs = ( os.path.join(gtweak.DATA_DIR, "themes"),
os.path.join(os.path.expanduser("~"), ".themes"))
for thdir in dirs:
for t in os.listdir(thdir):
if os.path.exists(os.path.join(thdir, t, "metacity-1")):
valid.append(t)
valid = walk_directories(dirs, lambda d:
os.path.exists(os.path.join(d, "metacity-1")))
return valid
def _on_combo_changed(self, combo):
......
......@@ -20,6 +20,18 @@ import logging
from gi.repository import GLib
def walk_directories(dirs, filter_func):
valid = []
try:
for thdir in dirs:
if os.path.isdir(thdir):
for t in os.listdir(thdir):
if filter_func(os.path.join(thdir, t)):
valid.append(t)
except:
logging.critical("Error parsing directories", exc_info=True)
return valid
class AutostartManager:
def __init__(self, DATA_DIR, desktop_filename, exec_cmd="", extra_exec_args=""):
self._desktop_file = os.path.join(DATA_DIR, "applications", desktop_filename)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment