~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/osutils.py

  • Committer: John Arbash Meinel
  • Date: 2006-06-18 02:21:57 UTC
  • mfrom: (1787 +trunk)
  • mto: This revision was merged to the branch mainline in revision 1794.
  • Revision ID: john@arbash-meinel.com-20060618022157-6e33aa9b67c25e4f
[merge] bzr.dev 1787

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
 
19
19
from cStringIO import StringIO
20
20
import errno
21
 
from ntpath import (abspath as _nt_abspath,
22
 
                    join as _nt_join,
23
 
                    normpath as _nt_normpath,
24
 
                    realpath as _nt_realpath,
25
 
                    )
26
21
import os
27
22
from os import listdir
28
 
import posixpath
29
23
import re
30
24
import sha
31
25
import shutil
39
33
import types
40
34
import tempfile
41
35
import unicodedata
 
36
from ntpath import (abspath as _nt_abspath,
 
37
                    join as _nt_join,
 
38
                    normpath as _nt_normpath,
 
39
                    realpath as _nt_realpath,
 
40
                    )
42
41
 
43
42
import bzrlib
44
43
from bzrlib.errors import (BzrError,
47
46
                           PathNotChild,
48
47
                           IllegalPath,
49
48
                           )
50
 
from bzrlib.symbol_versioning import (deprecated_function, 
51
 
        zero_nine)
 
49
from bzrlib.symbol_versioning import *
52
50
from bzrlib.trace import mutter
 
51
import bzrlib.win32console
53
52
 
54
53
 
55
54
def make_readonly(filename):
204
203
# string.
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)
 
211
    # return path
212
212
 
213
213
 
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)
216
216
 
217
217
 
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('\\', '/')
221
220
 
222
221
 
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('\\', '/')
226
224
 
227
225
 
228
226
def _win32_pathjoin(*args):
230
228
 
231
229
 
232
230
def _win32_normpath(path):
233
 
    return _nt_normpath(unicode(path)).replace('\\', '/')
 
231
    return _nt_normpath(path).replace('\\', '/')
234
232
 
235
233
 
236
234
def _win32_getcwd():
290
288
        return shutil.rmtree(path, ignore_errors, onerror)
291
289
 
292
290
 
293
 
def get_terminal_encoding():
294
 
    """Find the best encoding for printing to the screen.
295
 
 
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
302
 
 
303
 
    On my standard US Windows XP, the preferred encoding is
304
 
    cp1252, but the console is cp437
305
 
    """
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)
312
 
        else:
313
 
            output_encoding = input_encoding
314
 
            mutter('encoding stdout as sys.stdin encoding %r', output_encoding)
315
 
    else:
316
 
        mutter('encoding stdout as sys.stdout encoding %r', output_encoding)
317
 
    return output_encoding
318
 
 
319
 
 
320
291
def normalizepath(f):
321
292
    if hasattr(os.path, 'realpath'):
322
293
        F = realpath