/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: 2010-06-30 10:12:41 UTC
  • mfrom: (5273.1.11 cleanup)
  • Revision ID: pqm@pqm.ubuntu.com-20100630101241-gj9gnm31gj0ptaj7
(vila) Cleanup tests importing get_transport. (Vincent Ladeuil)

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
import os
19
19
import re
20
20
import stat
21
 
from stat import S_ISREG, S_ISDIR, S_ISLNK, ST_MODE, ST_SIZE
22
21
import sys
23
22
import time
24
23
import codecs
27
26
lazy_import(globals(), """
28
27
from datetime import datetime
29
28
import getpass
30
 
from ntpath import (abspath as _nt_abspath,
31
 
                    join as _nt_join,
32
 
                    normpath as _nt_normpath,
33
 
                    realpath as _nt_realpath,
34
 
                    splitdrive as _nt_splitdrive,
35
 
                    )
 
29
import ntpath
36
30
import posixpath
 
31
# We need to import both shutil and rmtree as we export the later on posix
 
32
# and need the former on windows
37
33
import shutil
38
 
from shutil import (
39
 
    rmtree,
40
 
    )
 
34
from shutil import rmtree
41
35
import socket
42
36
import subprocess
 
37
# We need to import both tempfile and mkdtemp as we export the later on posix
 
38
# and need the former on windows
43
39
import tempfile
44
 
from tempfile import (
45
 
    mkdtemp,
46
 
    )
 
40
from tempfile import mkdtemp
47
41
import unicodedata
48
42
 
49
43
from bzrlib import (
304
298
    running python.exe under cmd.exe return capital C:\\
305
299
    running win32 python inside a cygwin shell returns lowercase c:\\
306
300
    """
307
 
    drive, path = _nt_splitdrive(path)
 
301
    drive, path = ntpath.splitdrive(path)
308
302
    return drive.upper() + path
309
303
 
310
304
 
311
305
def _win32_abspath(path):
312
 
    # Real _nt_abspath doesn't have a problem with a unicode cwd
313
 
    return _win32_fixdrive(_nt_abspath(unicode(path)).replace('\\', '/'))
 
306
    # Real ntpath.abspath doesn't have a problem with a unicode cwd
 
307
    return _win32_fixdrive(ntpath.abspath(unicode(path)).replace('\\', '/'))
314
308
 
315
309
 
316
310
def _win98_abspath(path):
327
321
    #   /path       => C:/path
328
322
    path = unicode(path)
329
323
    # check for absolute path
330
 
    drive = _nt_splitdrive(path)[0]
 
324
    drive = ntpath.splitdrive(path)[0]
331
325
    if drive == '' and path[:2] not in('//','\\\\'):
332
326
        cwd = os.getcwdu()
333
327
        # we cannot simply os.path.join cwd and path
334
328
        # because os.path.join('C:','/path') produce '/path'
335
329
        # and this is incorrect
336
330
        if path[:1] in ('/','\\'):
337
 
            cwd = _nt_splitdrive(cwd)[0]
 
331
            cwd = ntpath.splitdrive(cwd)[0]
338
332
            path = path[1:]
339
333
        path = cwd + '\\' + path
340
 
    return _win32_fixdrive(_nt_normpath(path).replace('\\', '/'))
 
334
    return _win32_fixdrive(ntpath.normpath(path).replace('\\', '/'))
341
335
 
342
336
 
343
337
def _win32_realpath(path):
344
 
    # Real _nt_realpath doesn't have a problem with a unicode cwd
345
 
    return _win32_fixdrive(_nt_realpath(unicode(path)).replace('\\', '/'))
 
338
    # Real ntpath.realpath doesn't have a problem with a unicode cwd
 
339
    return _win32_fixdrive(ntpath.realpath(unicode(path)).replace('\\', '/'))
346
340
 
347
341
 
348
342
def _win32_pathjoin(*args):
349
 
    return _nt_join(*args).replace('\\', '/')
 
343
    return ntpath.join(*args).replace('\\', '/')
350
344
 
351
345
 
352
346
def _win32_normpath(path):
353
 
    return _win32_fixdrive(_nt_normpath(unicode(path)).replace('\\', '/'))
 
347
    return _win32_fixdrive(ntpath.normpath(unicode(path)).replace('\\', '/'))
354
348
 
355
349
 
356
350
def _win32_getcwd():
358
352
 
359
353
 
360
354
def _win32_mkdtemp(*args, **kwargs):
361
 
    return _win32_fixdrive(tempfile.mkdtemp(*args, **kwargs).replace('\\', '/'))
 
355
    return _win32_fixdrive(mkdtemp(*args, **kwargs).replace('\\', '/'))
362
356
 
363
357
 
364
358
def _win32_rename(old, new):
395
389
basename = os.path.basename
396
390
split = os.path.split
397
391
splitext = os.path.splitext
398
 
# These were already imported into local scope
 
392
# These were already lazily imported into local scope
399
393
# mkdtemp = tempfile.mkdtemp
400
394
# rmtree = shutil.rmtree
401
395
 
509
503
def isdir(f):
510
504
    """True if f is an accessible directory."""
511
505
    try:
512
 
        return S_ISDIR(os.lstat(f)[ST_MODE])
 
506
        return stat.S_ISDIR(os.lstat(f)[stat.ST_MODE])
513
507
    except OSError:
514
508
        return False
515
509
 
517
511
def isfile(f):
518
512
    """True if f is a regular file."""
519
513
    try:
520
 
        return S_ISREG(os.lstat(f)[ST_MODE])
 
514
        return stat.S_ISREG(os.lstat(f)[stat.ST_MODE])
521
515
    except OSError:
522
516
        return False
523
517
 
524
518
def islink(f):
525
519
    """True if f is a symlink."""
526
520
    try:
527
 
        return S_ISLNK(os.lstat(f)[ST_MODE])
 
521
        return stat.S_ISLNK(os.lstat(f)[stat.ST_MODE])
528
522
    except OSError:
529
523
        return False
530
524
 
870
864
 
871
865
def filesize(f):
872
866
    """Return size of given open file."""
873
 
    return os.fstat(f.fileno())[ST_SIZE]
 
867
    return os.fstat(f.fileno())[stat.ST_SIZE]
874
868
 
875
869
 
876
870
# Define rand_bytes based on platform.