summaryrefslogtreecommitdiff
path: root/appdirs.py
diff options
context:
space:
mode:
authorJeff Rouse <jr@its.to>2016-12-27 21:44:50 -0700
committerGitHub <noreply@github.com>2016-12-27 21:44:50 -0700
commite593ebf272c8fd3f72bcb0f464fd8b2816298667 (patch)
tree0d12eb7b41257bc958f8698d37b37ec1ae186a8b /appdirs.py
parentaa60d2506294e9dffe339c06157075396cddb5ac (diff)
parent1c0063e32f4b3219dc88002ea0680c1e392ce04d (diff)
downloadappdirs-e593ebf272c8fd3f72bcb0f464fd8b2816298667.tar.gz
Merge pull request #53 from carlwgeorge/state_dir
support XDG_STATE_HOME
Diffstat (limited to 'appdirs.py')
-rw-r--r--appdirs.py57
1 files changed, 54 insertions, 3 deletions
diff --git a/appdirs.py b/appdirs.py
index efd97dd..3fd9036 100644
--- a/appdirs.py
+++ b/appdirs.py
@@ -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__)