summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorcgtx <carl@cgtx.us>2014-11-04 22:29:37 -0600
committercgtx <carl@cgtx.us>2014-11-04 22:29:37 -0600
commitaba9d73c1e41f58234988bd155fe67ef7cb0fae0 (patch)
tree9c9a8a10c446d6363b13e8f4f0d66c0e729f9d3a
parentbd999c1c3fe7ee5f30ede2cf704cf03e400347b4 (diff)
implement XDG_STATE_HOME
-rw-r--r--xdg/BaseDirectory.py14
1 files changed, 14 insertions, 0 deletions
diff --git a/xdg/BaseDirectory.py b/xdg/BaseDirectory.py
index a7c31b1..3c3afe8 100644
--- a/xdg/BaseDirectory.py
+++ b/xdg/BaseDirectory.py
@@ -43,6 +43,9 @@ xdg_config_dirs = [xdg_config_home] + \
xdg_cache_home = os.environ.get('XDG_CACHE_HOME') or \
os.path.join(_home, '.cache')
+xdg_state_home = os.environ.get('XDG_STATE_HOME') or \
+ os.path.join(_home, '.local', 'state')
+
xdg_data_dirs = [x for x in xdg_data_dirs if x]
xdg_config_dirs = [x for x in xdg_config_dirs if x]
@@ -81,6 +84,17 @@ def save_cache_path(*resource):
os.makedirs(path)
return path
+def save_state_path(*resource):
+ """Ensure ``$XDG_STATE_HOME/<resource>/`` exists, and return its path.
+ 'resource' should normally be the name of your application or a shared
+ resource."""
+ resource = os.path.join(*resource)
+ assert not resource.startswith('/')
+ path = os.path.join(xdg_state_home, resource)
+ if not os.path.isdir(path):
+ os.makedirs(path)
+ return path
+
def load_config_paths(*resource):
"""Returns an iterator which gives each directory named 'resource' in the
configuration search path. Information provided by earlier directories should