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. Create the directory |
157 |
|
if it doesn't exist. |
158 |
|
|
159 |
|
Under posix systems use the os.expanduser() method. |
160 |
|
Under Win32 try to read the "Explorer/Shell Folders/" value "AppData". |
161 |
|
""" |
162 |
|
|
163 |
|
if os.name == 'posix': |
164 |
|
dir = os.path.expanduser("~/.thuban") |
165 |
|
if not os.path.isdir(dir): |
166 |
|
os.mkdir(dir) |
167 |
|
return dir |
168 |
|
elif os.name == 'nt': |
169 |
|
regkey = 1 |
170 |
|
try: |
171 |
|
import _winreg as wreg |
172 |
|
except ImportError: |
173 |
|
regkey = 0 |
174 |
|
|
175 |
|
if regkey: |
176 |
|
try: |
177 |
|
key = wreg.OpenKey(wreg.HKEY_CURRENT_USER, |
178 |
|
"Software\\Microsoft\\Windows\\CurrentVersion\\"\ |
179 |
|
"Explorer\\Shell Folders") |
180 |
|
dir = wreg.QueryValueEx(key, "AppData")[0] |
181 |
|
dir = os.path.join(dir, "thuban") |
182 |
|
except: |
183 |
|
regkey = 0 |
184 |
|
|
185 |
|
if not regkey: |
186 |
|
# The fallback. This should result in something like the |
187 |
|
# user directory ... |
188 |
|
guess = os.path.dirname( |
189 |
|
os.path.dirname(os.path.dirname(mktemp())) |
190 |
|
) |
191 |
|
dir = os.path.join(guess, "thuban") |
192 |
|
if not os.path.isdir(dir): |
193 |
|
os.mkdir(dir) |
194 |
|
|
195 |
|
return dir |
196 |
|
|
197 |
|
else: |
198 |
|
raise RuntimeError(_("No implementation of get_application_dir" |
199 |
|
" available for platform") + os.name) |
200 |
|
|
201 |
# bind the appropriate version of relative_filename for the platform |
# bind the appropriate version of relative_filename for the platform |
202 |
# we're currently running on. |
# we're currently running on. |