~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/osutils.py

  • Committer: Gordon Tyler
  • Date: 2011-01-21 23:51:15 UTC
  • mto: This revision was merged to the branch mainline in revision 5632.
  • Revision ID: gordon@doxxx.net-20110121235115-9sdqamejot1h0481
Replace usage of format function from python 2.6 with our own very simple formatting function.

Show diffs side-by-side

added added

removed removed

Lines of Context:
96
96
        user_encoding = get_user_encoding()
97
97
        return [a.decode(user_encoding) for a in sys.argv[1:]]
98
98
    except UnicodeDecodeError:
99
 
        raise errors.BzrError("Parameter %r encoding is unsupported by %s "
100
 
            "application locale." % (a, user_encoding))
 
99
        raise errors.BzrError(("Parameter '%r' is unsupported by the current "
 
100
                                                            "encoding." % a))
101
101
 
102
102
 
103
103
def make_readonly(filename):
392
392
# These were already lazily imported into local scope
393
393
# mkdtemp = tempfile.mkdtemp
394
394
# rmtree = shutil.rmtree
395
 
lstat = os.lstat
396
 
fstat = os.fstat
397
 
 
398
 
def wrap_stat(st):
399
 
    return st
400
 
 
401
395
 
402
396
MIN_ABS_PATHLENGTH = 1
403
397
 
413
407
    getcwd = _win32_getcwd
414
408
    mkdtemp = _win32_mkdtemp
415
409
    rename = _win32_rename
416
 
    try:
417
 
        from bzrlib import _walkdirs_win32
418
 
    except ImportError:
419
 
        pass
420
 
    else:
421
 
        lstat = _walkdirs_win32.lstat
422
 
        fstat = _walkdirs_win32.fstat
423
 
        wrap_stat = _walkdirs_win32.wrap_stat
424
410
 
425
411
    MIN_ABS_PATHLENGTH = 3
426
412
 
2257
2243
            termios.tcsetattr(fd, termios.TCSADRAIN, settings)
2258
2244
        return ch
2259
2245
 
 
2246
 
2260
2247
if sys.platform == 'linux2':
2261
2248
    def _local_concurrency():
2262
 
        try:
2263
 
            return os.sysconf('SC_NPROCESSORS_ONLN')
2264
 
        except (ValueError, OSError, AttributeError):
2265
 
            return None
 
2249
        concurrency = None
 
2250
        prefix = 'processor'
 
2251
        for line in file('/proc/cpuinfo', 'rb'):
 
2252
            if line.startswith(prefix):
 
2253
                concurrency = int(line[line.find(':')+1:]) + 1
 
2254
        return concurrency
2266
2255
elif sys.platform == 'darwin':
2267
2256
    def _local_concurrency():
2268
2257
        return subprocess.Popen(['sysctl', '-n', 'hw.availcpu'],
2269
2258
                                stdout=subprocess.PIPE).communicate()[0]
2270
 
elif "bsd" in sys.platform:
 
2259
elif sys.platform[0:7] == 'freebsd':
2271
2260
    def _local_concurrency():
2272
2261
        return subprocess.Popen(['sysctl', '-n', 'hw.ncpu'],
2273
2262
                                stdout=subprocess.PIPE).communicate()[0]
2301
2290
    concurrency = os.environ.get('BZR_CONCURRENCY', None)
2302
2291
    if concurrency is None:
2303
2292
        try:
2304
 
            import multiprocessing
2305
 
        except ImportError:
2306
 
            # multiprocessing is only available on Python >= 2.6
2307
 
            try:
2308
 
                concurrency = _local_concurrency()
2309
 
            except (OSError, IOError):
2310
 
                pass
2311
 
        else:
2312
 
            concurrency = multiprocessing.cpu_count()
 
2293
            concurrency = _local_concurrency()
 
2294
        except (OSError, IOError):
 
2295
            pass
2313
2296
    try:
2314
2297
        concurrency = int(concurrency)
2315
2298
    except (TypeError, ValueError):