Hello,
I am currectly working on a port of a linux application to windows in
which we use the xdg.BaseDirectory module. Attached you can find a small
patch that will add support to xdg.BaseDirectory module on windows in
which the special folders (appdata, home etc...) of the current user are
returned using the wind32 api unless that XDG enviroment variables are set.
I really do not know if this patch will be utterly useful for many
people but it will certainly help those that are currently using the
module and will like to port their applications too.
Kr,
Manuel de la Pena
Index: BaseDirectory.py
===================================================================
RCS file: /cvs/pyxdg/pyxdg/xdg/BaseDirectory.py,v
retrieving revision 1.8
diff -u -r1.8 BaseDirectory.py
--- BaseDirectory.py 2 Mar 2008 13:58:08 -0000 1.8
+++ BaseDirectory.py 23 Aug 2010 22:12:49 -0000
@@ -27,22 +27,75 @@
from __future__ import generators
import os
+import sys
-_home = os.environ.get('HOME', '/')
-xdg_data_home = os.environ.get('XDG_DATA_HOME',
- os.path.join(_home, '.local', 'share'))
+# we must chech which os we are using to ensure that the correct
+# paths are set
+if sys.platform == "win32":
+
+ # use the win32 extensions to allow retrieving the appropiate
+ # path according to the win32 system
+ from win32com.shell import shellcon, shell
+
+ def get_special_folder_path(special_folder):
+ """Returns the path of the given special folder."""
+ return shell.SHGetFolderPath(0, special_folder, 0, 0)
+
+ # The virtual folder that represents the My Documents desktop item.
+ # This is equivalent to CSIDL_MYDOCUMENTS.
+ home_path = get_special_folder_path(shellcon.CSIDL_PERSONAL)
+
+ # The file system directory that serves as a data repository
+ # for local (nonroaming) applications.
+ app_local_data_path = get_special_folder_path(shellcon.CSIDL_LOCAL_APPDATA)
+
+ # The file system directory that contains application data for all users.
+ app_global_data_path = get_special_folder_path(
+ shellcon.CSIDL_COMMON_APPDATA)
+
+ # The file system directory that serves as a common repository for
+ # application-specific data, usually for roaming data
+ app_roaming_data_path = get_special_folder_path(shellcon.CSIDL_APPDATA)
+
+ # use the non romain app data
+ xdg_data_home = os.environ.get('XDG_DATA_HOME',
+ os.path.join(app_local_data_path, 'xdg'))
+
+ # we will use ; as the spearator because is the char used
+ # in the windows env variables
+ xdg_data_dirs = os.environ.get('XDG_DATA_DIRS',
+ '{0};{1};{2}'.format(app_local_data_path,
+ app_global_data_path, app_roaming_data_path)).split(';')
+
+ # we will return the roaming data wich is as close as we get in windows
+ # regarding caching.
+ xdg_cache_home = os.environ.get('XDG_CACHE_HOME',
+ app_roaming_data_path)
+
+ # point to the not roaming app data for the user
+ xdg_config_home = os.environ.get('XDG_CONFIG_HOME',
+ app_local_data_path)
+
+ xdg_config_dirs = [xdg_config_home] + \
+ os.environ.get('XDG_CONFIG_DIRS',
+ os.path.join(app_global_data_path, 'xdg')).split(':')
+
+else:
+ _home = os.environ.get('HOME', '/')
+ xdg_data_home = os.environ.get('XDG_DATA_HOME',
+ os.path.join(_home, '.local', 'share'))
+
+ xdg_data_dirs = [xdg_data_home] + \
+ os.environ.get('XDG_DATA_DIRS',
'/usr/local/share:/usr/share').split(':')
-xdg_data_dirs = [xdg_data_home] + \
- os.environ.get('XDG_DATA_DIRS', '/usr/local/share:/usr/share').split(':')
+ xdg_config_home = os.environ.get('XDG_CONFIG_HOME',
+ os.path.join(_home, '.config'))
-xdg_config_home = os.environ.get('XDG_CONFIG_HOME',
- os.path.join(_home, '.config'))
+ xdg_config_dirs = [xdg_config_home] + \
+ os.environ.get('XDG_CONFIG_DIRS', '/etc/xdg').split(':')
-xdg_config_dirs = [xdg_config_home] + \
- os.environ.get('XDG_CONFIG_DIRS', '/etc/xdg').split(':')
-
-xdg_cache_home = os.environ.get('XDG_CACHE_HOME',
- os.path.join(_home, '.cache'))
+ xdg_cache_home = os.environ.get('XDG_CACHE_HOME',
+ os.path.join(_home, '.cache'))
xdg_data_dirs = filter(lambda x: x, xdg_data_dirs)
xdg_config_dirs = filter(lambda x: x, xdg_config_dirs)
_______________________________________________
xdg mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/xdg