diff options
author | carlgeorge <carl.george@rackspace.com> | 2015-06-28 19:02:00 -0500 |
---|---|---|
committer | carlgeorge <carl.george@rackspace.com> | 2015-06-28 19:05:29 -0500 |
commit | ea0701d7550fc290384c949b4a8e492a05163bce (patch) | |
tree | 8f65fded97f9da476098a519b57bd2d489db7af7 /appdirs.py | |
parent | dbf3ff1b66054d90f99fe21259f0a609b67055af (diff) | |
download | appdirs-ea0701d7550fc290384c949b4a8e492a05163bce.tar.gz |
support XDG_STATE_HOME
There is a proposal to add another directory type to the XDG Base Directory
Specification.
https://wiki.debian.org/XDGBaseDirectorySpecification#state
To be clear, this is _not_ currently part of the specification. However, I
think it would be a valuable addition to the appdirs module. I wasn't sure if
there was an equivalent for OSX or Windows, so for now those fall back to using
user_data_dir.
Diffstat (limited to 'appdirs.py')
-rw-r--r-- | appdirs.py | 57 |
1 files changed, 54 insertions, 3 deletions
@@ -311,6 +311,48 @@ def user_cache_dir(appname=None, appauthor=None, version=None, opinion=True): return path +def user_state_dir(appname=None, appauthor=None, version=None, roaming=False): + r"""Return full path to the user-specific state dir for this application. + + "appname" is the name of application. + If None, just the system directory is returned. + "appauthor" (only used on Windows) is the name of the + appauthor or distributing body for this application. Typically + it is the owning company name. This falls back to appname. You may + pass False to disable it. + "version" is an optional version path element to append to the + path. You might want to use this if you want multiple versions + of your app to be able to run independently. If used, this + would typically be "<major>.<minor>". + Only applied when appname is present. + "roaming" (boolean, default False) can be set True to use the Windows + roaming appdata directory. That means that for users on a Windows + network setup for roaming profiles, this user data will be + sync'd on login. See + <http://technet.microsoft.com/en-us/library/cc766489(WS.10).aspx> + for a discussion of issues. + + Typical user state directories are: + Mac OS X: same as user_data_dir + Unix: ~/.local/state/<AppName> # or in $XDG_STATE_HOME, if defined + Win *: same as user_data_dir + + For Unix, we follow this Debian proposal <https://wiki.debian.org/XDGBaseDirectorySpecification#state> + to extend the XDG spec and support $XDG_STATE_HOME. + + That means, by default "~/.local/state/<AppName>". + """ + if system in ["win32", "darwin"]: + path = user_data_dir(appname, appauthor, None, roaming) + else: + path = os.getenv('XDG_STATE_HOME', os.path.expanduser("~/.local/state")) + if appname: + path = os.path.join(path, appname) + if appname and version: + path = os.path.join(path, version) + return path + + def user_log_dir(appname=None, appauthor=None, version=None, opinion=True): r"""Return full path to the user-specific log dir for this application. @@ -398,6 +440,11 @@ class AppDirs(object): version=self.version) @property + def user_state_dir(self): + return user_state_dir(self.appname, self.appauthor, + version=self.version) + + @property def user_log_dir(self): return user_log_dir(self.appname, self.appauthor, version=self.version) @@ -530,9 +577,13 @@ if __name__ == "__main__": appname = "MyApp" appauthor = "MyCompany" - props = ("user_data_dir", "site_data_dir", - "user_config_dir", "site_config_dir", - "user_cache_dir", "user_log_dir") + props = ("user_data_dir", + "user_config_dir", + "user_cache_dir", + "user_state_dir", + "user_log_dir", + "site_data_dir", + "site_config_dir") print("-- app dirs %s --" % __version__) |