11 |
|
|
12 |
__version__ = "$Revision$" |
__version__ = "$Revision$" |
13 |
|
|
14 |
|
import os |
15 |
import os.path |
import os.path |
16 |
|
from tempfile import mktemp |
17 |
|
|
18 |
from string import split, join |
from string import split, join |
19 |
|
|
20 |
from Thuban import _ |
from Thuban import _ |
152 |
# relative name |
# relative name |
153 |
return relative_filename_common(dir_rest, absname_rest, "\\") |
return relative_filename_common(dir_rest, absname_rest, "\\") |
154 |
|
|
155 |
|
def get_application_dir(): |
156 |
|
"""Determine the path to the .thuban directory. |
157 |
|
|
158 |
|
Under posix systems use the os.expanduser() method. |
159 |
|
Under Win32 try to read the "Explorer/Shell Folders/" value "AppData". |
160 |
|
""" |
161 |
|
|
162 |
|
if os.name == 'posix': |
163 |
|
return os.path.expanduser("~/.thuban") |
164 |
|
elif os.name == 'nt': |
165 |
|
regkey = 1 |
166 |
|
try: |
167 |
|
import _winreg as wreg |
168 |
|
except ImportError: |
169 |
|
regkey = 0 |
170 |
|
|
171 |
|
if regkey: |
172 |
|
try: |
173 |
|
key = wreg.OpenKey(wreg.HKEY_CURRENT_USER, |
174 |
|
"Software\\Microsoft\\Windows\\CurrentVersion\\"\ |
175 |
|
"Explorer\\Shell Folders") |
176 |
|
dir = wreg.QueryValueEx(key, "AppData")[0] |
177 |
|
dir = os.path.join(dir, "thuban") |
178 |
|
except: |
179 |
|
regkey = 0 |
180 |
|
|
181 |
|
if not regkey: |
182 |
|
# The fallback. This should result in something like the |
183 |
|
# user directory ... |
184 |
|
guess = os.path.dirname( |
185 |
|
os.path.dirname(os.path.dirname(mktemp())) |
186 |
|
) |
187 |
|
dir = os.path.join(guess, "thuban") |
188 |
|
if not os.path.isdir(dir): |
189 |
|
os.mkdir(dir) |
190 |
|
|
191 |
|
return dir |
192 |
|
|
193 |
|
else: |
194 |
|
raise RuntimeError(_("No implementation of get_application_dir" |
195 |
|
" available for platform") + os.name) |
196 |
|
|
197 |
# bind the appropriate version of relative_filename for the platform |
# bind the appropriate version of relative_filename for the platform |
198 |
# we're currently running on. |
# we're currently running on. |