"Fossies" - the Fresh Open Source Software Archive

Member "http-prompt-2.1.0/http_prompt/xdg.py" (5 Mar 2021, 1219 Bytes) of package /linux/www/http-prompt-2.1.0.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Python source code syntax highlighting (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file. For more information about "xdg.py" see the Fossies "Dox" file reference documentation.

    1 """XDG Base Directory Specification.
    2 
    3 See:
    4     https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html
    5     https://github.com/ActiveState/appdirs
    6 """
    7 import os
    8 import sys
    9 
   10 from functools import partial
   11 
   12 
   13 def _get_dir(envvar_name, default_dir, resource_name=None):
   14     base_dir = os.getenv(envvar_name) or default_dir
   15     app_dir = os.path.join(base_dir, 'http-prompt')
   16     if not os.path.exists(app_dir):
   17         os.makedirs(app_dir, mode=0o700)
   18 
   19     if resource_name:
   20         app_dir = os.path.join(app_dir, resource_name)
   21         if not os.path.exists(app_dir):
   22             os.mkdir(app_dir)
   23 
   24     return app_dir
   25 
   26 
   27 if sys.platform == 'win32':  # nocover
   28     # NOTE: LOCALAPPDATA is not available on Windows XP
   29     get_data_dir = partial(_get_dir, 'LOCALAPPDATA',
   30                            os.path.expanduser('~/AppData/Local'))
   31     get_config_dir = partial(_get_dir, 'LOCALAPPDATA',
   32                              os.path.expanduser('~/AppData/Local'))
   33 else:
   34     get_data_dir = partial(_get_dir, 'XDG_DATA_HOME',
   35                            os.path.expanduser('~/.local/share'))
   36     get_config_dir = partial(_get_dir, 'XDG_CONFIG_HOME',
   37                              os.path.expanduser('~/.config'))