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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
|
# Copyright 2009 Canonical Ltd.
#
# This file is part of Tarmac.
#
# Tarmac is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 3 as
# published by the Free Software Foundation.
#
# Tarmac is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Tarmac. If not, see <http://www.gnu.org/licenses/>.
'''XDG BaseDirectory abstraction for non-Linux platforms.'''
__all__ = [
'xdg_cache_home',
'xdg_config_home',
]
import os
import sys
# XXX This function should be merged into bzrlib.win32utils
def get_temp_location():
'''Return temporary (cache) directory'''
if sys.platform == 'win32':
# Doing good
temp = os.environ.get('TEMP')
if temp:
return temp
# Not on Vista/XP/2000
windir = os.environ.get('windir')
if windir:
temp = os.path.join(windir, 'Temp')
if os.path.isdir(temp):
return temp
# Not on win32 or nothing found
return None
try:
import xdg.BaseDirectory
except ImportError:
if sys.platform == 'win32':
from bzrlib import win32utils as win
xdg_config_home = win.get_appdata_location_unicode()
xdg_cache_home = get_temp_location()
else:
home = os.environ.get('HOME')
xdg_config_home = os.path.join(home, '.config/')
xdg_cache_home = os.path.join(home, '.cache/')
else:
xdg_config_home = xdg.BaseDirectory.xdg_config_home
xdg_cache_home = xdg.BaseDirectory.xdg_cache_home
|