Show More
@@ -201,10 +201,25 b' def get_home_dir(require_writable=False):' | |||
|
201 | 201 | return py3compat.cast_unicode(root, fs_encoding) |
|
202 | 202 | |
|
203 | 203 | homedir = os.path.expanduser('~') |
|
204 | ||
|
205 | if not _writable_dir(homedir) and os.name == 'nt': | |
|
206 | # expanduser failed, use the registry to get the 'My Documents' folder. | |
|
207 | try: | |
|
208 | import _winreg as wreg | |
|
209 | key = wreg.OpenKey( | |
|
210 | wreg.HKEY_CURRENT_USER, | |
|
211 | "Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders" | |
|
212 | ) | |
|
213 | homedir = wreg.QueryValueEx(key,'Personal')[0] | |
|
214 | key.Close() | |
|
215 | except: | |
|
216 | pass | |
|
217 | ||
|
204 | 218 | if (not require_writable) or _writable_dir(homedir): |
|
205 | 219 | return py3compat.cast_unicode(homedir, fs_encoding) |
|
206 | 220 | else: |
|
207 |
raise HomeDirError('%s is not a writable dir, |
|
|
221 | raise HomeDirError('%s is not a writable dir, ' | |
|
222 | 'set $HOME environment variable to override' % homedir) | |
|
208 | 223 | |
|
209 | 224 | def get_xdg_dir(): |
|
210 | 225 | """Return the XDG_CONFIG_HOME, if it is defined and exists, else None. |
@@ -166,8 +166,40 b' def test_get_home_dir_4():' | |||
|
166 | 166 | def test_get_home_dir_5(): |
|
167 | 167 | """raise HomeDirError if $HOME is specified, but not a writable dir""" |
|
168 | 168 | env['HOME'] = abspath(HOME_TEST_DIR+'garbage') |
|
169 | # set os.name = posix, to prevent My Documents fallback on Windows | |
|
170 | os.name = 'posix' | |
|
169 | 171 | nt.assert_raises(path.HomeDirError, path.get_home_dir, True) |
|
170 | 172 | |
|
173 | ||
|
174 | # Should we stub wreg fully so we can run the test on all platforms? | |
|
175 | @skip_if_not_win32 | |
|
176 | @with_environment | |
|
177 | def test_get_home_dir_8(): | |
|
178 | """Using registry hack for 'My Documents', os=='nt' | |
|
179 | ||
|
180 | HOMESHARE, HOMEDRIVE, HOMEPATH, USERPROFILE and others are missing. | |
|
181 | """ | |
|
182 | os.name = 'nt' | |
|
183 | # Remove from stub environment all keys that may be set | |
|
184 | for key in ['HOME', 'HOMESHARE', 'HOMEDRIVE', 'HOMEPATH', 'USERPROFILE']: | |
|
185 | env.pop(key, None) | |
|
186 | ||
|
187 | #Stub windows registry functions | |
|
188 | def OpenKey(x, y): | |
|
189 | class key: | |
|
190 | def Close(self): | |
|
191 | pass | |
|
192 | return key() | |
|
193 | def QueryValueEx(x, y): | |
|
194 | return [abspath(HOME_TEST_DIR)] | |
|
195 | ||
|
196 | wreg.OpenKey = OpenKey | |
|
197 | wreg.QueryValueEx = QueryValueEx | |
|
198 | ||
|
199 | home_dir = path.get_home_dir() | |
|
200 | nt.assert_equal(home_dir, abspath(HOME_TEST_DIR)) | |
|
201 | ||
|
202 | ||
|
171 | 203 | @with_environment |
|
172 | 204 | def test_get_ipython_dir_1(): |
|
173 | 205 | """test_get_ipython_dir_1, Testcase to see if we can call get_ipython_dir without Exceptions.""" |
General Comments 0
You need to be logged in to leave comments.
Login now