summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJasper St. Pierre <[email protected]>2012-05-01 17:19:24 -0400
committerAlexei Sorokin <[email protected]>2016-08-22 23:03:32 +0300
commitb9f9932db7d6583933c4c5c28e2f945b77c9548a (patch)
tree51d9b66e65c592a79297175a21dd2ae91db4aa99
parentd8f69da64b0b4f2ea74f9688f65de6fdb1fb67ac (diff)
downloadmozo-b9f9932db7d6583933c4c5c28e2f945b77c9548a.tar.bz2
mozo-b9f9932db7d6583933c4c5c28e2f945b77c9548a.tar.xz
util: use GLib for xdg basedir spec stuff
-rw-r--r--Mozo/MenuEditor.py4
-rw-r--r--Mozo/util.py75
2 files changed, 24 insertions, 55 deletions
diff --git a/Mozo/MenuEditor.py b/Mozo/MenuEditor.py
index 80ef2dd..71a76eb 100644
--- a/Mozo/MenuEditor.py
+++ b/Mozo/MenuEditor.py
@@ -180,7 +180,7 @@ class MenuEditor:
def canRevert(self, item):
if item.get_type() == matemenu.TYPE_ENTRY:
- if util.getItemPath(item.get_desktop_file_id()):
+ if util.getItemPath(item.get_desktop_file_id()) is not None:
path = util.getUserItemPath()
if os.path.isfile(os.path.join(path, item.get_desktop_file_id())):
return True
@@ -189,7 +189,7 @@ class MenuEditor:
file_id = os.path.split(item.get_desktop_file_path())[1]
else:
file_id = item.get_menu_id() + '.directory'
- if util.getDirectoryPath(file_id):
+ if util.getDirectoryPath(file_id) is not None:
path = util.getUserDirectoryPath()
if os.path.isfile(os.path.join(path, file_id)):
return True
diff --git a/Mozo/util.py b/Mozo/util.py
index 3ea68d7..cc7db83 100644
--- a/Mozo/util.py
+++ b/Mozo/util.py
@@ -82,75 +82,44 @@ def getUniqueUndoFile(filepath):
append += 1
return new_filepath
-def getUserMenuPath():
- menu_dir = None
- if os.environ.has_key('XDG_CONFIG_HOME'):
- menu_dir = os.path.join(os.environ['XDG_CONFIG_HOME'], 'menus')
- else:
- menu_dir = os.path.join(os.environ['HOME'], '.config', 'menus')
- #move .config out of the way if it's not a dir, it shouldn't be there
- if os.path.isfile(os.path.split(menu_dir)[0]):
- os.rename(os.path.split(menu_dir)[0], os.path.split(menu_dir)[0] + '.old')
- if not os.path.isdir(menu_dir):
- os.makedirs(menu_dir)
- return menu_dir
-
def getItemPath(file_id):
- if os.environ.has_key('XDG_DATA_DIRS'):
- for system_path in os.environ['XDG_DATA_DIRS'].split(':'):
- file_path = os.path.join(system_path, 'applications', file_id)
- if os.path.isfile(file_path):
- return file_path
- file_path = os.path.join('/', 'usr', 'share', 'applications', file_id)
+ for path in GLib.get_system_data_dirs():
+ file_path = os.path.join(path, 'applications', file_id)
if os.path.isfile(file_path):
return file_path
- return False
+ return None
def getUserItemPath():
- item_dir = None
- if os.environ.has_key('XDG_DATA_HOME'):
- item_dir = os.path.join(os.environ['XDG_DATA_HOME'], 'applications')
- else:
- item_dir = os.path.join(os.environ['HOME'], '.local', 'share', 'applications')
+ item_dir = os.path.join(GLib.get_user_data_dir(), 'applications')
if not os.path.isdir(item_dir):
os.makedirs(item_dir)
return item_dir
def getDirectoryPath(file_id):
- home = getUserDirectoryPath()
- file_path = os.path.join(home, file_id)
- if os.path.isfile(file_path):
- return file_path
- if os.environ.has_key('XDG_DATA_DIRS'):
- for system_path in os.environ['XDG_DATA_DIRS'].split(':'):
- file_path = os.path.join(system_path, 'desktop-directories', file_id)
- if os.path.isfile(file_path):
- return file_path
- file_path = os.path.join('/', 'usr', 'share', 'desktop-directories', file_id)
- if os.path.isfile(file_path):
- return file_path
- return False
+ for path in GLib.get_system_data_dirs():
+ file_path = os.path.join(path, 'desktop-directories', file_id)
+ if os.path.isfile(file_path):
+ return file_path
+ return None
def getUserDirectoryPath():
- menu_dir = None
- if os.environ.has_key('XDG_DATA_HOME'):
- menu_dir = os.path.join(os.environ['XDG_DATA_HOME'], 'desktop-directories')
- else:
- menu_dir = os.path.join(os.environ['HOME'], '.local', 'share', 'desktop-directories')
+ menu_dir = os.path.join(GLib.get_user_data_dir(), 'desktop-directories')
if not os.path.isdir(menu_dir):
os.makedirs(menu_dir)
return menu_dir
-def getSystemMenuPath(file_name):
- if os.environ.has_key('XDG_CONFIG_DIRS'):
- for system_path in os.environ['XDG_CONFIG_DIRS'].split(':'):
- file_path = os.path.join(system_path, 'menus', file_name)
- if os.path.isfile(file_path):
- return file_path
- file_path = os.path.join('/', 'etc', 'xdg', 'menus', file_name)
- if os.path.isfile(file_path):
- return file_path
- return False
+def getUserMenuPath():
+ menu_dir = os.path.join(GLib.get_user_config_dir(), 'menus')
+ if not os.path.isdir(menu_dir):
+ os.makedirs(menu_dir)
+ return menu_dir
+
+def getSystemMenuPath(file_id):
+ for path in GLib.get_system_config_dirs():
+ file_path = os.path.join(path, 'menus', file_id)
+ if os.path.isfile(file_path):
+ return file_path
+ return None
def getUserMenuXml(tree):
system_file = getSystemMenuPath(tree.get_menu_file())