27
26
lazy_import(globals(), """
28
27
from datetime import datetime
30
from ntpath import (abspath as _nt_abspath,
32
normpath as _nt_normpath,
33
realpath as _nt_realpath,
34
splitdrive as _nt_splitdrive,
31
# We need to import both shutil and rmtree as we export the later on posix
32
# and need the former on windows
34
from shutil import rmtree
37
# We need to import both tempfile and mkdtemp as we export the later on posix
38
# and need the former on windows
44
from tempfile import (
40
from tempfile import mkdtemp
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:\\
307
drive, path = _nt_splitdrive(path)
301
drive, path = ntpath.splitdrive(path)
308
302
return drive.upper() + path
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('\\', '/'))
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]
339
333
path = cwd + '\\' + path
340
return _win32_fixdrive(_nt_normpath(path).replace('\\', '/'))
334
return _win32_fixdrive(ntpath.normpath(path).replace('\\', '/'))
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('\\', '/'))
348
342
def _win32_pathjoin(*args):
349
return _nt_join(*args).replace('\\', '/')
343
return ntpath.join(*args).replace('\\', '/')
352
346
def _win32_normpath(path):
353
return _win32_fixdrive(_nt_normpath(unicode(path)).replace('\\', '/'))
347
return _win32_fixdrive(ntpath.normpath(unicode(path)).replace('\\', '/'))
356
350
def _win32_getcwd():
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
518
512
"""True if f is a regular file."""
520
return S_ISREG(os.lstat(f)[ST_MODE])
514
return stat.S_ISREG(os.lstat(f)[stat.ST_MODE])
525
519
"""True if f is a symlink."""
527
return S_ISLNK(os.lstat(f)[ST_MODE])
521
return stat.S_ISLNK(os.lstat(f)[stat.ST_MODE])
2071
2065
report_activity(sent, 'write')
2068
def connect_socket(address):
2069
# Slight variation of the socket.create_connection() function (provided by
2070
# python-2.6) that can fail if getaddrinfo returns an empty list. We also
2071
# provide it for previous python versions. Also, we don't use the timeout
2072
# parameter (provided by the python implementation) so we don't implement
2074
err = socket.error('getaddrinfo returns an empty list')
2075
host, port = address
2076
for res in socket.getaddrinfo(host, port, 0, socket.SOCK_STREAM):
2077
af, socktype, proto, canonname, sa = res
2080
sock = socket.socket(af, socktype, proto)
2084
except socket.error, err:
2085
# 'err' is now the most recent error
2086
if sock is not None:
2074
2091
def dereference_path(path):
2075
2092
"""Determine the real path to a file.
2189
@deprecated_function(deprecated_in((2, 2, 0)))
2172
2190
def re_compile_checked(re_string, flags=0, where=""):
2173
2191
"""Return a compiled re, or raise a sensible error.
2184
2202
re_obj = re.compile(re_string, flags)
2185
2203
re_obj.search("")
2205
except errors.InvalidPattern, e:
2189
2207
where = ' in ' + where
2190
2208
# despite the name 'error' is a type
2191
raise errors.BzrCommandError('Invalid regular expression%s: %r: %s'
2192
% (where, re_string, e))
2209
raise errors.BzrCommandError('Invalid regular expression%s: %s'
2195
2213
if sys.platform == "win32":