1
# Copyright (C) 2005-2011 Canonical Ltd
1
# Copyright (C) 2005-2010 Canonical Ltd
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
967
967
# they tend to happen very early in startup when we can't check config
968
968
# files etc, and also we want to report all failures but not spam the user
969
969
# with 10 warnings.
970
from bzrlib import trace
970
971
exception_str = str(exception)
971
972
if exception_str not in _extension_load_failures:
972
973
trace.mutter("failed to load compiled extension: %s" % exception_str)
1461
1462
# a similar effect.
1463
1464
# If BZR_COLUMNS is set, take it, user is always right
1464
# Except if they specified 0 in which case, impose no limit here
1466
width = int(os.environ['BZR_COLUMNS'])
1466
return int(os.environ['BZR_COLUMNS'])
1467
1467
except (KeyError, ValueError):
1469
if width is not None:
1475
1470
isatty = getattr(sys.stdout, 'isatty', None)
1476
1471
if isatty is None or not isatty():
1880
1875
s = os.stat(src)
1881
1876
chown(dst, s.st_uid, s.st_gid)
1882
1877
except OSError, e:
1884
'Unable to copy ownership from "%s" to "%s". '
1885
'You may want to set it manually.', src, dst)
1886
trace.log_exception_quietly()
1878
trace.warning("Unable to copy ownership from '%s' to '%s': IOError: %s." % (src, dst, e))
1889
1881
def path_prefix_key(path):
2001
1993
# data at once.
2002
1994
MAX_SOCKET_CHUNK = 64 * 1024
2004
_end_of_stream_errors = [errno.ECONNRESET]
2005
for _eno in ['WSAECONNRESET', 'WSAECONNABORTED']:
2006
_eno = getattr(errno, _eno, None)
2007
if _eno is not None:
2008
_end_of_stream_errors.append(_eno)
2012
1996
def read_bytes_from_socket(sock, report_activity=None,
2013
1997
max_read_size=MAX_SOCKET_CHUNK):
2014
1998
"""Read up to max_read_size of bytes from sock and notify of progress.
2022
2006
bytes = sock.recv(max_read_size)
2023
2007
except socket.error, e:
2024
2008
eno = e.args[0]
2025
if eno in _end_of_stream_errors:
2009
if eno == getattr(errno, "WSAECONNRESET", errno.ECONNRESET):
2026
2010
# The connection was closed by the other side. Callers expect
2027
2011
# an empty string to signal end-of-stream.
2391
2375
name = "%s.~%d~" % (base, counter)
2395
def set_fd_cloexec(fd):
2396
"""Set a Unix file descriptor's FD_CLOEXEC flag. Do nothing if platform
2397
support for this is not available.
2401
old = fcntl.fcntl(fd, fcntl.F_GETFD)
2402
fcntl.fcntl(fd, fcntl.F_SETFD, old | fcntl.FD_CLOEXEC)
2403
except (ImportError, AttributeError):
2404
# Either the fcntl module or specific constants are not present
2408
def find_executable_on_path(name):
2409
"""Finds an executable on the PATH.
2411
On Windows, this will try to append each extension in the PATHEXT
2412
environment variable to the name, if it cannot be found with the name
2415
:param name: The base name of the executable.
2416
:return: The path to the executable found or None.
2418
path = os.environ.get('PATH')
2421
path = path.split(os.pathsep)
2422
if sys.platform == 'win32':
2423
exts = os.environ.get('PATHEXT', '').split(os.pathsep)
2424
exts = [ext.lower() for ext in exts]
2425
base, ext = os.path.splitext(name)
2427
if ext.lower() not in exts:
2435
f = os.path.join(d, name) + ext
2436
if os.access(f, os.X_OK):