OLD | NEW |
(Empty) | |
| 1 .. image:: https://secure.travis-ci.org/ActiveState/appdirs.png |
| 2 :target: http://travis-ci.org/ActiveState/appdirs |
| 3 |
| 4 the problem |
| 5 =========== |
| 6 |
| 7 What directory should your app use for storing user data? If running on Mac OS X
, you |
| 8 should use:: |
| 9 |
| 10 ~/Library/Application Support/<AppName> |
| 11 |
| 12 If on Windows (at least English Win XP) that should be:: |
| 13 |
| 14 C:\Documents and Settings\<User>\Application Data\Local Settings\<AppAuthor>
\<AppName> |
| 15 |
| 16 or possibly:: |
| 17 |
| 18 C:\Documents and Settings\<User>\Application Data\<AppAuthor>\<AppName> |
| 19 |
| 20 for `roaming profiles <http://bit.ly/9yl3b6>`_ but that is another story. |
| 21 |
| 22 On Linux (and other Unices) the dir, according to the `XDG |
| 23 spec <http://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html>`_,
is:: |
| 24 |
| 25 ~/.local/share/<AppName> |
| 26 |
| 27 |
| 28 ``appdirs`` to the rescue |
| 29 ========================= |
| 30 |
| 31 This kind of thing is what the ``appdirs`` module is for. ``appdirs`` will |
| 32 help you choose an appropriate: |
| 33 |
| 34 - user data dir (``user_data_dir``) |
| 35 - user config dir (``user_config_dir``) |
| 36 - user cache dir (``user_cache_dir``) |
| 37 - site data dir (``site_data_dir``) |
| 38 - site config dir (``site_config_dir``) |
| 39 - user log dir (``user_log_dir``) |
| 40 |
| 41 and also: |
| 42 |
| 43 - is a single module so other Python packages can include their own private copy |
| 44 - is slightly opinionated on the directory names used. Look for "OPINION" in |
| 45 documentation and code for when an opinion is being applied. |
| 46 |
| 47 |
| 48 some example output |
| 49 =================== |
| 50 |
| 51 On Mac OS X:: |
| 52 |
| 53 >>> from appdirs import * |
| 54 >>> appname = "SuperApp" |
| 55 >>> appauthor = "Acme" |
| 56 >>> user_data_dir(appname, appauthor) |
| 57 '/Users/trentm/Library/Application Support/SuperApp' |
| 58 >>> site_data_dir(appname, appauthor) |
| 59 '/Library/Application Support/SuperApp' |
| 60 >>> user_cache_dir(appname, appauthor) |
| 61 '/Users/trentm/Library/Caches/SuperApp' |
| 62 >>> user_log_dir(appname, appauthor) |
| 63 '/Users/trentm/Library/Logs/SuperApp' |
| 64 |
| 65 On Windows 7:: |
| 66 |
| 67 >>> from appdirs import * |
| 68 >>> appname = "SuperApp" |
| 69 >>> appauthor = "Acme" |
| 70 >>> user_data_dir(appname, appauthor) |
| 71 'C:\\Users\\trentm\\AppData\\Local\\Acme\\SuperApp' |
| 72 >>> user_data_dir(appname, appauthor, roaming=True) |
| 73 'C:\\Users\\trentm\\AppData\\Roaming\\Acme\\SuperApp' |
| 74 >>> user_cache_dir(appname, appauthor) |
| 75 'C:\\Users\\trentm\\AppData\\Local\\Acme\\SuperApp\\Cache' |
| 76 >>> user_log_dir(appname, appauthor) |
| 77 'C:\\Users\\trentm\\AppData\\Local\\Acme\\SuperApp\\Logs' |
| 78 |
| 79 On Linux:: |
| 80 |
| 81 >>> from appdirs import * |
| 82 >>> appname = "SuperApp" |
| 83 >>> appauthor = "Acme" |
| 84 >>> user_data_dir(appname, appauthor) |
| 85 '/home/trentm/.local/share/SuperApp |
| 86 >>> site_data_dir(appname, appauthor) |
| 87 '/usr/local/share/SuperApp' |
| 88 >>> site_data_dir(appname, appauthor, multipath=True) |
| 89 '/usr/local/share/SuperApp:/usr/share/SuperApp' |
| 90 >>> user_cache_dir(appname, appauthor) |
| 91 '/home/trentm/.cache/SuperApp' |
| 92 >>> user_log_dir(appname, appauthor) |
| 93 '/home/trentm/.cache/SuperApp/log' |
| 94 >>> user_config_dir(appname) |
| 95 '/home/trentm/.config/SuperApp' |
| 96 >>> site_config_dir(appname) |
| 97 '/etc/xdg/SuperApp' |
| 98 >>> os.environ['XDG_CONFIG_DIRS'] = '/etc:/usr/local/etc' |
| 99 >>> site_config_dir(appname, multipath=True) |
| 100 '/etc/SuperApp:/usr/local/etc/SuperApp' |
| 101 |
| 102 |
| 103 ``AppDirs`` for convenience |
| 104 =========================== |
| 105 |
| 106 :: |
| 107 |
| 108 >>> from appdirs import AppDirs |
| 109 >>> dirs = AppDirs("SuperApp", "Acme") |
| 110 >>> dirs.user_data_dir |
| 111 '/Users/trentm/Library/Application Support/SuperApp' |
| 112 >>> dirs.site_data_dir |
| 113 '/Library/Application Support/SuperApp' |
| 114 >>> dirs.user_cache_dir |
| 115 '/Users/trentm/Library/Caches/SuperApp' |
| 116 >>> dirs.user_log_dir |
| 117 '/Users/trentm/Library/Logs/SuperApp' |
| 118 |
| 119 |
| 120 |
| 121 Per-version isolation |
| 122 ===================== |
| 123 |
| 124 If you have multiple versions of your app in use that you want to be |
| 125 able to run side-by-side, then you may want version-isolation for these |
| 126 dirs:: |
| 127 |
| 128 >>> from appdirs import AppDirs |
| 129 >>> dirs = AppDirs("SuperApp", "Acme", version="1.0") |
| 130 >>> dirs.user_data_dir |
| 131 '/Users/trentm/Library/Application Support/SuperApp/1.0' |
| 132 >>> dirs.site_data_dir |
| 133 '/Library/Application Support/SuperApp/1.0' |
| 134 >>> dirs.user_cache_dir |
| 135 '/Users/trentm/Library/Caches/SuperApp/1.0' |
| 136 >>> dirs.user_log_dir |
| 137 '/Users/trentm/Library/Logs/SuperApp/1.0' |
| 138 |
| 139 |
| 140 |
| 141 appdirs Changelog |
| 142 ================= |
| 143 |
| 144 appdirs 1.4.0 |
| 145 ------------- |
| 146 - [PR #42] AppAuthor is now optional on Windows |
| 147 - [issue 41] Support Jython on Windows, Mac, and Unix-like platforms. Windows |
| 148 support requires `JNA <https://github.com/twall/jna>`_. |
| 149 - [PR #44] Fix incorrect behaviour of the site_config_dir method |
| 150 |
| 151 appdirs 1.3.0 |
| 152 ------------- |
| 153 - [Unix, issue 16] Conform to XDG standard, instead of breaking it for |
| 154 everybody |
| 155 - [Unix] Removes gratuitous case mangling of the case, since \*nix-es are |
| 156 usually case sensitive, so mangling is not wise |
| 157 - [Unix] Fixes the uterly wrong behaviour in ``site_data_dir``, return result |
| 158 based on XDG_DATA_DIRS and make room for respecting the standard which |
| 159 specifies XDG_DATA_DIRS is a multiple-value variable |
| 160 - [Issue 6] Add ``*_config_dir`` which are distinct on nix-es, according to |
| 161 XDG specs; on Windows and Mac return the corresponding ``*_data_dir`` |
| 162 |
| 163 appdirs 1.2.0 |
| 164 ------------- |
| 165 |
| 166 - [Unix] Put ``user_log_dir`` under the *cache* dir on Unix. Seems to be more |
| 167 typical. |
| 168 - [issue 9] Make ``unicode`` work on py3k. |
| 169 |
| 170 appdirs 1.1.0 |
| 171 ------------- |
| 172 |
| 173 - [issue 4] Add ``AppDirs.user_log_dir``. |
| 174 - [Unix, issue 2, issue 7] appdirs now conforms to `XDG base directory spec |
| 175 <http://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html>`_. |
| 176 - [Mac, issue 5] Fix ``site_data_dir()`` on Mac. |
| 177 - [Mac] Drop use of 'Carbon' module in favour of hardcoded paths; supports |
| 178 Python3 now. |
| 179 - [Windows] Append "Cache" to ``user_cache_dir`` on Windows by default. Use |
| 180 ``opinion=False`` option to disable this. |
| 181 - Add ``appdirs.AppDirs`` convenience class. Usage: |
| 182 |
| 183 >>> dirs = AppDirs("SuperApp", "Acme", version="1.0") |
| 184 >>> dirs.user_data_dir |
| 185 '/Users/trentm/Library/Application Support/SuperApp/1.0' |
| 186 |
| 187 - [Windows] Cherry-pick Komodo's change to downgrade paths to the Windows short |
| 188 paths if there are high bit chars. |
| 189 - [Linux] Change default ``user_cache_dir()`` on Linux to be singular, e.g. |
| 190 "~/.superapp/cache". |
| 191 - [Windows] Add ``roaming`` option to ``user_data_dir()`` (for use on Windows on
ly) |
| 192 and change the default ``user_data_dir`` behaviour to use a *non*-roaming |
| 193 profile dir (``CSIDL_LOCAL_APPDATA`` instead of ``CSIDL_APPDATA``). Why? Becau
se |
| 194 a large roaming profile can cause login speed issues. The "only syncs on |
| 195 logout" behaviour can cause surprises in appdata info. |
| 196 |
| 197 |
| 198 appdirs 1.0.1 (never released) |
| 199 ------------------------------ |
| 200 |
| 201 Started this changelog 27 July 2010. Before that this module originated in the |
| 202 `Komodo <http://www.activestate.com/komodo>`_ product as ``applib.py`` and then |
| 203 as `applib/location.py |
| 204 <http://github.com/ActiveState/applib/blob/master/applib/location.py>`_ (used by |
| 205 `PyPM <http://code.activestate.com/pypm/>`_ in `ActivePython |
| 206 <http://www.activestate.com/activepython>`_). This is basically a fork of |
| 207 applib.py 1.0.1 and applib/location.py 1.0.1. |
| 208 |
| 209 |
| 210 |
OLD | NEW |