88
96
user_encoding = get_user_encoding()
89
97
return [a.decode(user_encoding) for a in sys.argv[1:]]
90
98
except UnicodeDecodeError:
91
raise errors.BzrError("Parameter %r encoding is unsupported by %s "
92
"application locale." % (a, user_encoding))
99
raise errors.BzrError(("Parameter '%r' is unsupported by the current "
95
103
def make_readonly(filename):
262
270
rename_func(tmp_name, new)
263
271
if failure_exc is not None:
265
raise failure_exc[0], failure_exc[1], failure_exc[2]
272
raise failure_exc[0], failure_exc[1], failure_exc[2]
270
275
# In Python 2.4.2 and older, os.path.abspath and os.path.realpath
2252
2243
termios.tcsetattr(fd, termios.TCSADRAIN, settings)
2255
2247
if sys.platform == 'linux2':
2256
2248
def _local_concurrency():
2258
return os.sysconf('SC_NPROCESSORS_ONLN')
2259
except (ValueError, OSError, AttributeError):
2250
prefix = 'processor'
2251
for line in file('/proc/cpuinfo', 'rb'):
2252
if line.startswith(prefix):
2253
concurrency = int(line[line.find(':')+1:]) + 1
2261
2255
elif sys.platform == 'darwin':
2262
2256
def _local_concurrency():
2263
2257
return subprocess.Popen(['sysctl', '-n', 'hw.availcpu'],
2264
2258
stdout=subprocess.PIPE).communicate()[0]
2265
elif "bsd" in sys.platform:
2259
elif sys.platform[0:7] == 'freebsd':
2266
2260
def _local_concurrency():
2267
2261
return subprocess.Popen(['sysctl', '-n', 'hw.ncpu'],
2268
2262
stdout=subprocess.PIPE).communicate()[0]
2296
2290
concurrency = os.environ.get('BZR_CONCURRENCY', None)
2297
2291
if concurrency is None:
2299
import multiprocessing
2301
# multiprocessing is only available on Python >= 2.6
2303
concurrency = _local_concurrency()
2304
except (OSError, IOError):
2307
concurrency = multiprocessing.cpu_count()
2293
concurrency = _local_concurrency()
2294
except (OSError, IOError):
2309
2297
concurrency = int(concurrency)
2310
2298
except (TypeError, ValueError):
2381
2369
except UnicodeDecodeError:
2382
2370
raise errors.BzrError("Can't decode username as %s." % \
2384
except ImportError, e:
2385
if sys.platform != 'win32':
2387
if str(e) != 'No module named pwd':
2389
# https://bugs.launchpad.net/bzr/+bug/660174
2390
# getpass.getuser() is unable to return username on Windows
2391
# if there is no USERNAME environment variable set.
2392
# That could be true if bzr is running as a service,
2393
# e.g. running `bzr serve` as a service on Windows.
2394
# We should not fail with traceback in this case.
2395
username = u'UNKNOWN'
2396
2372
return username
2427
2403
except (ImportError, AttributeError):
2428
2404
# Either the fcntl module or specific constants are not present
2432
def find_executable_on_path(name):
2433
"""Finds an executable on the PATH.
2435
On Windows, this will try to append each extension in the PATHEXT
2436
environment variable to the name, if it cannot be found with the name
2439
:param name: The base name of the executable.
2440
:return: The path to the executable found or None.
2442
path = os.environ.get('PATH')
2445
path = path.split(os.pathsep)
2446
if sys.platform == 'win32':
2447
exts = os.environ.get('PATHEXT', '').split(os.pathsep)
2448
exts = [ext.lower() for ext in exts]
2449
base, ext = os.path.splitext(name)
2451
if ext.lower() not in exts:
2459
f = os.path.join(d, name) + ext
2460
if os.access(f, os.X_OK):
2465
def _posix_is_local_pid_dead(pid):
2466
"""True if pid doesn't correspond to live process on this machine"""
2468
# Special meaning of unix kill: just check if it's there.
2471
if e.errno == errno.ESRCH:
2472
# On this machine, and really not found: as sure as we can be
2475
elif e.errno == errno.EPERM:
2476
# exists, though not ours
2479
mutter("os.kill(%d, 0) failed: %s" % (pid, e))
2480
# Don't really know.
2483
# Exists and our process: not dead.
2486
if sys.platform == "win32":
2487
is_local_pid_dead = win32utils.is_local_pid_dead
2489
is_local_pid_dead = _posix_is_local_pid_dead