[go: up one dir, main page]

File: portability.py

package info (click to toggle)
comix 4.0.4-3
  • links: PTS
  • area: main
  • in suites: stretch
  • size: 2,088 kB
  • sloc: python: 5,996; makefile: 40; xml: 20
file content (47 lines) | stat: -rw-r--r-- 1,608 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
41
42
43
44
45
46
47
"""Portability functions for Comix."""

import os
import sys


def get_home_directory():
    """On UNIX-like systems, this method will return the path of the home
    directory, e.g. /home/username. On Windows, it will return a Comix
    sub-directory of <Documents and Settings/Username>.
    """
    if sys.platform == 'win32':
        return os.path.join(os.path.expanduser('~'), 'Comix')
    else:
        return os.path.expanduser('~')


def get_config_directory():
    """Return the path to the Comix config directory. On UNIX, this will
    be $XDG_CONFIG_HOME/comix, on Windows it will be the same directory as
    get_home_directory().
    
    See http://standards.freedesktop.org/basedir-spec/latest/ for more
    information on the $XDG_CONFIG_HOME environmental variable.
    """
    if sys.platform == 'win32':
        return get_home_directory()
    else:
        base_path = os.getenv('XDG_CONFIG_HOME',
            os.path.join(get_home_directory(), '.config'))
        return os.path.join(base_path, 'comix')


def get_data_directory():
    """Return the path to the Comix data directory. On UNIX, this will
    be $XDG_DATA_HOME/comix, on Windows it will be the same directory as
    get_home_directory().
    
    See http://standards.freedesktop.org/basedir-spec/latest/ for more
    information on the $XDG_DATA_HOME environmental variable.
    """
    if sys.platform == 'win32':
        return get_home_directory()
    else:
        base_path = os.getenv('XDG_DATA_HOME',
            os.path.join(get_home_directory(), '.local/share'))
        return os.path.join(base_path, 'comix')