Show More
@@ -81,7 +81,8 b" def unquote_filename(name, win32=(sys.platform=='win32')):" | |||||
81 |
|
81 | |||
82 | def compress_user(path): |
|
82 | def compress_user(path): | |
83 | """Reverse of :func:`os.path.expanduser` |
|
83 | """Reverse of :func:`os.path.expanduser` | |
84 | """ |
|
84 | """ | |
|
85 | path = py3compat.unicode_to_str(path, sys.getfilesystemencoding()) | |||
85 | home = os.path.expanduser('~') |
|
86 | home = os.path.expanduser('~') | |
86 | if path.startswith(home): |
|
87 | if path.startswith(home): | |
87 | path = "~" + path[len(home):] |
|
88 | path = "~" + path[len(home):] | |
@@ -174,13 +175,13 b' def get_home_dir(require_writable=False):' | |||||
174 | """Return the 'home' directory, as a unicode string. |
|
175 | """Return the 'home' directory, as a unicode string. | |
175 |
|
176 | |||
176 | Uses os.path.expanduser('~'), and checks for writability. |
|
177 | Uses os.path.expanduser('~'), and checks for writability. | |
177 |
|
178 | |||
178 | See stdlib docs for how this is determined. |
|
179 | See stdlib docs for how this is determined. | |
179 | $HOME is first priority on *ALL* platforms. |
|
180 | $HOME is first priority on *ALL* platforms. | |
180 |
|
181 | |||
181 | Parameters |
|
182 | Parameters | |
182 | ---------- |
|
183 | ---------- | |
183 |
|
184 | |||
184 | require_writable : bool [default: False] |
|
185 | require_writable : bool [default: False] | |
185 | if True: |
|
186 | if True: | |
186 | guarantees the return value is a writable directory, otherwise |
|
187 | guarantees the return value is a writable directory, otherwise | |
@@ -193,7 +194,7 b' def get_home_dir(require_writable=False):' | |||||
193 | # Next line will make things work even when /home/ is a symlink to |
|
194 | # Next line will make things work even when /home/ is a symlink to | |
194 | # /usr/home as it is on FreeBSD, for example |
|
195 | # /usr/home as it is on FreeBSD, for example | |
195 | homedir = os.path.realpath(homedir) |
|
196 | homedir = os.path.realpath(homedir) | |
196 |
|
197 | |||
197 | if not _writable_dir(homedir) and os.name == 'nt': |
|
198 | if not _writable_dir(homedir) and os.name == 'nt': | |
198 | # expanduser failed, use the registry to get the 'My Documents' folder. |
|
199 | # expanduser failed, use the registry to get the 'My Documents' folder. | |
199 | try: |
|
200 | try: | |
@@ -209,7 +210,7 b' def get_home_dir(require_writable=False):' | |||||
209 | key.Close() |
|
210 | key.Close() | |
210 | except: |
|
211 | except: | |
211 | pass |
|
212 | pass | |
212 |
|
213 | |||
213 | if (not require_writable) or _writable_dir(homedir): |
|
214 | if (not require_writable) or _writable_dir(homedir): | |
214 | return py3compat.cast_unicode(homedir, fs_encoding) |
|
215 | return py3compat.cast_unicode(homedir, fs_encoding) | |
215 | else: |
|
216 | else: | |
@@ -430,10 +431,10 b' def link_or_copy(src, dst):' | |||||
430 |
|
431 | |||
431 | def ensure_dir_exists(path, mode=0o755): |
|
432 | def ensure_dir_exists(path, mode=0o755): | |
432 | """ensure that a directory exists |
|
433 | """ensure that a directory exists | |
433 |
|
434 | |||
434 | If it doesn't exist, try to create it and protect against a race condition |
|
435 | If it doesn't exist, try to create it and protect against a race condition | |
435 | if another process is doing the same. |
|
436 | if another process is doing the same. | |
436 |
|
437 | |||
437 | The default permissions are 755, which differ from os.makedirs default of 777. |
|
438 | The default permissions are 755, which differ from os.makedirs default of 777. | |
438 | """ |
|
439 | """ | |
439 | if not os.path.exists(path): |
|
440 | if not os.path.exists(path): |
General Comments 0
You need to be logged in to leave comments.
Login now