19
19
from cStringIO import StringIO
21
from ntpath import (abspath as _nt_abspath,
23
normpath as _nt_normpath,
24
realpath as _nt_realpath,
27
22
from os import listdir
36
from ntpath import (abspath as _nt_abspath,
38
normpath as _nt_normpath,
39
realpath as _nt_realpath,
44
43
from bzrlib.errors import (BzrError,
50
from bzrlib.symbol_versioning import (deprecated_function,
49
from bzrlib.symbol_versioning import *
52
50
from bzrlib.trace import mutter
51
import bzrlib.win32console
55
54
def make_readonly(filename):
205
204
_fs_enc = sys.getfilesystemencoding()
206
205
def _posix_abspath(path):
207
# jam 20060426 rather than encoding to fsencoding
208
# copy posixpath.abspath, but use os.getcwdu instead
209
if not posixpath.isabs(path):
210
path = posixpath.join(getcwd(), path)
211
return posixpath.normpath(path)
206
return os.path.abspath(path.encode(_fs_enc)).decode(_fs_enc)
207
# jam 20060426 This is another possibility which mimics
208
# os.path.abspath, only uses unicode characters instead
209
# if not os.path.isabs(path):
210
# return os.path.join(os.getcwdu(), path)
214
214
def _posix_realpath(path):
215
return posixpath.realpath(path.encode(_fs_enc)).decode(_fs_enc)
215
return os.path.realpath(path.encode(_fs_enc)).decode(_fs_enc)
218
218
def _win32_abspath(path):
219
# Real _nt_abspath doesn't have a problem with a unicode cwd
220
return _nt_abspath(unicode(path)).replace('\\', '/')
219
return _nt_abspath(path.encode(_fs_enc)).decode(_fs_enc).replace('\\', '/')
223
222
def _win32_realpath(path):
224
# Real _nt_realpath doesn't have a problem with a unicode cwd
225
return _nt_realpath(unicode(path)).replace('\\', '/')
223
return _nt_realpath(path.encode(_fs_enc)).decode(_fs_enc).replace('\\', '/')
228
226
def _win32_pathjoin(*args):
290
288
return shutil.rmtree(path, ignore_errors, onerror)
293
def get_terminal_encoding():
294
"""Find the best encoding for printing to the screen.
296
This attempts to check both sys.stdout and sys.stdin to see
297
what encoding they are in, and if that fails it falls back to
298
bzrlib.user_encoding.
299
The problem is that on Windows, locale.getpreferredencoding()
300
is not the same encoding as that used by the console:
301
http://mail.python.org/pipermail/python-list/2003-May/162357.html
303
On my standard US Windows XP, the preferred encoding is
304
cp1252, but the console is cp437
306
output_encoding = getattr(sys.stdout, 'encoding', None)
307
if not output_encoding:
308
input_encoding = getattr(sys.stdin, 'encoding', None)
309
if not input_encoding:
310
output_encoding = bzrlib.user_encoding
311
mutter('encoding stdout as bzrlib.user_encoding %r', output_encoding)
313
output_encoding = input_encoding
314
mutter('encoding stdout as sys.stdin encoding %r', output_encoding)
316
mutter('encoding stdout as sys.stdout encoding %r', output_encoding)
317
return output_encoding
320
291
def normalizepath(f):
321
292
if hasattr(os.path, 'realpath'):