Skip to content
Myr

Added get_app_dir function.

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Armin Ronacher · committed by Armin Ronacher · parent 82973d0 · Browse files · 2 files+57 added−1 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+57 added−1 removed

  • other:+57 added−1 removed

2 files+57 added−1 removed

modified:click/__init__.py+2 added-1 removed
27 unmodified lines
28 FLOAT, BOOL, UUID2930# Utilities31from .utils import echo, get_binary_stream, get_text_stream, \32 format_filename32 format_filename, get_app_dir3334# Terminal functions35from .termui import prompt, confirm, get_terminal_size, echo_via_pager36
23 unmodified lines
60 'FLOAT', 'BOOL', 'UUID',6162 # Utilities63 'echo', 'get_binary_stream', 'get_text_stream', 'format_filename',64 'get_app_dir',6566 # Terminal functions67 'prompt', 'confirm', 'get_terminal_size', 'echo_via_pager',68
10 unmodified lines
modified:click/utils.py+55 added
10 unmodified lines
1112echo_native_types = string_types + (bytes, bytearray)131415def _posixify(name):16 return '-'.join(name.split()).lower()171819def unpack_args(args, nargs_spec):20 """Given an iterable of arguments and an iterable of nargs specifications21 it returns a tuple with all the unpacked arguments at the first index22 and all remaining arguments as the second.
256 unmodified lines
279 """280 if shorten:281 filename = os.path.basename(filename)282 return filename_to_ui(filename)283284285def get_app_dir(app_name, roaming=True, force_posix=False):286 """Returns the config folder for the application. The default behavior287 is to return whatever is most appropriate for the operating system.288289 To give you an idea, for an app called ``"Foo Bar"`` something like290 the following folders could be returned:291292 Mac OS X:293 ``~/Library/Application Support/Foo Bar``294 Mac OS X (posix):295 ``~/.foo-bar``296 Unix:297 ``~/.config/foo-bar``298 Unix (posix):299 ``~/.foo-bar``300 Win XP (roaming):301 ``C:\Documents and Settings\<user>\Local Settings\Application Data\Foo Bar``302 Win XP (not roaming):303 ``C:\Documents and Settings\<user>\Application Data\Foo Bar``304 Win 7 (roaming):305 ``C:\Users\<user>\AppData\Roaming\Foo Bar``306 Win 7 (not roaming):307 ``C:\Users\<user>\AppData\Local\Foo Bar``308309 .. versionadded:: 2.0310311 :param app_name: the application name. This should be properly capitalized312 and can contain whitespace.313 :param roaming: controls if the folder should be roaming or not on windows.314 Has no affect otherwise.315 :param force_posix: if this is set to `True` then on any posix system the316 folder will be stored in the home folder with a leading317 dot instead of the XDG config home or darwin's318 application support folder.319 """320 if sys.platform.startswith('win'):321 key = roaming and 'APPDATA' or 'LOCALAPPDATA'322 folder = os.environ.get(key)323 if folder is None:324 folder = os.path.expanduser('~')325 return os.path.join(folder, app_name)326 if force_posix:327 return os.path.join(os.path.expanduser('~/.' + _posixify(app_name)))328 if sys.platform == 'darwin':329 return os.path.join(os.path.expanduser(330 '~/Library/Application Support'), app_name)331 return os.path.join(332 os.environ.get('XDG_CONFIG_HOME', os.path.expanduser('~/.config')),333 _posixify(app_name))