/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/osutils.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2008-10-01 07:56:03 UTC
  • mfrom: (3224.5.40 faster-startup)
  • Revision ID: pqm@pqm.ubuntu.com-20081001075603-s9nynw8y85fmrprj
Reduce startup time by a small amount. (Andrew Bennetts)

Show diffs side-by-side

added added

removed removed

Lines of Context:
14
14
# along with this program; if not, write to the Free Software
15
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
16
 
17
 
from cStringIO import StringIO
18
17
import os
19
18
import re
20
19
import stat
68
67
 
69
68
import bzrlib
70
69
from bzrlib import symbol_versioning
71
 
from bzrlib.symbol_versioning import (
72
 
    deprecated_function,
73
 
    )
74
 
from bzrlib.trace import mutter
75
70
 
76
71
 
77
72
# On win32, O_BINARY is used to indicate the file should
184
179
    """
185
180
 
186
181
    # sftp rename doesn't allow overwriting, so play tricks:
187
 
    import random
188
182
    base = os.path.basename(new)
189
183
    dirname = os.path.dirname(new)
190
184
    tmp_name = u'tmp.%s.%.9f.%d.%s' % (base, time.time(), os.getpid(), rand_chars(10))
297
291
        path = cwd + '\\' + path
298
292
    return _win32_fixdrive(_nt_normpath(path).replace('\\', '/'))
299
293
 
300
 
if win32utils.winver == 'Windows 98':
301
 
    _win32_abspath = _win98_abspath
302
 
 
303
294
 
304
295
def _win32_realpath(path):
305
296
    # Real _nt_realpath doesn't have a problem with a unicode cwd
364
355
 
365
356
 
366
357
if sys.platform == 'win32':
367
 
    abspath = _win32_abspath
 
358
    if win32utils.winver == 'Windows 98':
 
359
        abspath = _win98_abspath
 
360
    else:
 
361
        abspath = _win32_abspath
368
362
    realpath = _win32_realpath
369
363
    pathjoin = _win32_pathjoin
370
364
    normpath = _win32_normpath
399
393
 
400
394
    This attempts to check both sys.stdout and sys.stdin to see
401
395
    what encoding they are in, and if that fails it falls back to
402
 
    bzrlib.user_encoding.
 
396
    osutils.get_user_encoding().
403
397
    The problem is that on Windows, locale.getpreferredencoding()
404
398
    is not the same encoding as that used by the console:
405
399
    http://mail.python.org/pipermail/python-list/2003-May/162357.html
407
401
    On my standard US Windows XP, the preferred encoding is
408
402
    cp1252, but the console is cp437
409
403
    """
 
404
    from bzrlib.trace import mutter
410
405
    output_encoding = getattr(sys.stdout, 'encoding', None)
411
406
    if not output_encoding:
412
407
        input_encoding = getattr(sys.stdin, 'encoding', None)
413
408
        if not input_encoding:
414
 
            output_encoding = bzrlib.user_encoding
415
 
            mutter('encoding stdout as bzrlib.user_encoding %r', output_encoding)
 
409
            output_encoding = get_user_encoding()
 
410
            mutter('encoding stdout as osutils.get_user_encoding() %r',
 
411
                   output_encoding)
416
412
        else:
417
413
            output_encoding = input_encoding
418
414
            mutter('encoding stdout as sys.stdin encoding %r', output_encoding)
420
416
        mutter('encoding stdout as sys.stdout encoding %r', output_encoding)
421
417
    if output_encoding == 'cp0':
422
418
        # invalid encoding (cp0 means 'no codepage' on Windows)
423
 
        output_encoding = bzrlib.user_encoding
 
419
        output_encoding = get_user_encoding()
424
420
        mutter('cp0 is invalid encoding.'
425
 
               ' encoding stdout as bzrlib.user_encoding %r', output_encoding)
 
421
               ' encoding stdout as osutils.get_user_encoding() %r',
 
422
               output_encoding)
426
423
    # check encoding
427
424
    try:
428
425
        codecs.lookup(output_encoding)
430
427
        sys.stderr.write('bzr: warning:'
431
428
                         ' unknown terminal encoding %s.\n'
432
429
                         '  Using encoding %s instead.\n'
433
 
                         % (output_encoding, bzrlib.user_encoding)
 
430
                         % (output_encoding, get_user_encoding())
434
431
                        )
435
 
        output_encoding = bzrlib.user_encoding
 
432
        output_encoding = get_user_encoding()
436
433
 
437
434
    return output_encoding
438
435
 
1123
1120
            del os.environ[env_variable]
1124
1121
    else:
1125
1122
        if isinstance(value, unicode):
1126
 
            value = value.encode(bzrlib.user_encoding)
 
1123
            value = value.encode(get_user_encoding())
1127
1124
        os.environ[env_variable] = value
1128
1125
    return orig_val
1129
1126
 
1281
1278
    global _selected_dir_reader
1282
1279
    if _selected_dir_reader is None:
1283
1280
        fs_encoding = _fs_enc.upper()
1284
 
        if win32utils.winver == 'Windows NT':
 
1281
        if sys.platform == "win32" and win32utils.winver == 'Windows NT':
1285
1282
            # Win98 doesn't have unicode apis like FindFirstFileW
1286
1283
            # TODO: We possibly could support Win98 by falling back to the
1287
1284
            #       original FindFirstFile, and using TCHAR instead of WCHAR,