File: platform_.py

package info (click to toggle)
python-keyring 25.6.0-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 560 kB
  • sloc: python: 1,929; sh: 17; makefile: 17
file content (40 lines) | stat: -rw-r--r-- 1,092 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import os
import pathlib
import platform


def _data_root_Windows():
    release, version, csd, ptype = platform.win32_ver()
    root = pathlib.Path(
        os.environ.get('LOCALAPPDATA', os.environ.get('ProgramData', '.'))
    )
    return root / 'Python Keyring'


def _data_root_Linux():
    """
    Use freedesktop.org Base Dir Specification to determine storage
    location.
    """
    fallback = pathlib.Path.home() / '.local/share'
    root = os.environ.get('XDG_DATA_HOME', None) or fallback
    return pathlib.Path(root, 'python_keyring')


_config_root_Windows = _data_root_Windows


def _config_root_Linux():
    """
    Use freedesktop.org Base Dir Specification to determine config
    location.
    """
    fallback = pathlib.Path.home() / '.config'
    key = 'XDG_CONFIG_HOME'
    root = os.environ.get(key, None) or fallback
    return pathlib.Path(root, 'python_keyring')


# by default, use Unix convention
data_root = globals().get('_data_root_' + platform.system(), _data_root_Linux)
config_root = globals().get('_config_root_' + platform.system(), _config_root_Linux)