summaryrefslogtreecommitdiff
path: root/Mozo/util.py
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 /Mozo/util.py
parentd8f69da64b0b4f2ea74f9688f65de6fdb1fb67ac (diff)
downloadmozo-b9f9932db7d6583933c4c5c28e2f945b77c9548a.tar.bz2
mozo-b9f9932db7d6583933c4c5c28e2f945b77c9548a.tar.xz
util: use GLib for xdg basedir spec stuff
Diffstat (limited to 'Mozo/util.py')
-rw-r--r--Mozo/util.py75
1 files changed, 22 insertions, 53 deletions
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())