~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/osutils.py

  • Committer: INADA Naoki
  • Date: 2011-05-05 09:15:34 UTC
  • mto: (5830.3.3 i18n-msgfmt)
  • mto: This revision was merged to the branch mainline in revision 5873.
  • Revision ID: songofacandy@gmail.com-20110505091534-7sv835xpofwrmpt4
Add update-pot command to Makefile and tools/bzrgettext script that
extracts help text from bzr commands.

Show diffs side-by-side

added added

removed removed

Lines of Context:
42
42
 
43
43
from bzrlib import (
44
44
    cache_utf8,
45
 
    config,
46
45
    errors,
47
46
    trace,
48
47
    win32utils,
54
53
    deprecated_in,
55
54
    )
56
55
 
57
 
from hashlib import (
58
 
    md5,
59
 
    sha1 as sha,
60
 
    )
 
56
# sha and md5 modules are deprecated in python2.6 but hashlib is available as
 
57
# of 2.5
 
58
if sys.version_info < (2, 5):
 
59
    import md5 as _mod_md5
 
60
    md5 = _mod_md5.new
 
61
    import sha as _mod_sha
 
62
    sha = _mod_sha.new
 
63
else:
 
64
    from hashlib import (
 
65
        md5,
 
66
        sha1 as sha,
 
67
        )
61
68
 
62
69
 
63
70
import bzrlib
262
269
            else:
263
270
                rename_func(tmp_name, new)
264
271
    if failure_exc is not None:
265
 
        try:
266
 
            raise failure_exc[0], failure_exc[1], failure_exc[2]
267
 
        finally:
268
 
            del failure_exc
 
272
        raise failure_exc[0], failure_exc[1], failure_exc[2]
269
273
 
270
274
 
271
275
# In Python 2.4.2 and older, os.path.abspath and os.path.realpath
986
990
def report_extension_load_failures():
987
991
    if not _extension_load_failures:
988
992
        return
989
 
    if config.GlobalStack().get('ignore_missing_extensions'):
 
993
    from bzrlib.config import GlobalConfig
 
994
    if GlobalConfig().get_user_option_as_bool('ignore_missing_extensions'):
990
995
        return
991
996
    # the warnings framework should by default show this only once
992
997
    from bzrlib.trace import warning
2381
2386
    except UnicodeDecodeError:
2382
2387
        raise errors.BzrError("Can't decode username as %s." % \
2383
2388
                user_encoding)
2384
 
    except ImportError, e:
2385
 
        if sys.platform != 'win32':
2386
 
            raise
2387
 
        if str(e) != 'No module named pwd':
2388
 
            raise
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
2389
    return username
2397
2390
 
2398
2391
 
2460
2453
            if os.access(f, os.X_OK):
2461
2454
                return f
2462
2455
    return None
2463
 
 
2464
 
 
2465
 
def _posix_is_local_pid_dead(pid):
2466
 
    """True if pid doesn't correspond to live process on this machine"""
2467
 
    try:
2468
 
        # Special meaning of unix kill: just check if it's there.
2469
 
        os.kill(pid, 0)
2470
 
    except OSError, e:
2471
 
        if e.errno == errno.ESRCH:
2472
 
            # On this machine, and really not found: as sure as we can be
2473
 
            # that it's dead.
2474
 
            return True
2475
 
        elif e.errno == errno.EPERM:
2476
 
            # exists, though not ours
2477
 
            return False
2478
 
        else:
2479
 
            mutter("os.kill(%d, 0) failed: %s" % (pid, e))
2480
 
            # Don't really know.
2481
 
            return False
2482
 
    else:
2483
 
        # Exists and our process: not dead.
2484
 
        return False
2485
 
 
2486
 
if sys.platform == "win32":
2487
 
    is_local_pid_dead = win32utils.is_local_pid_dead
2488
 
else:
2489
 
    is_local_pid_dead = _posix_is_local_pid_dead
2490
 
 
2491
 
 
2492
 
def fdatasync(fileno):
2493
 
    """Flush file contents to disk if possible.
2494
 
    
2495
 
    :param fileno: Integer OS file handle.
2496
 
    :raises TransportNotPossible: If flushing to disk is not possible.
2497
 
    """
2498
 
    fn = getattr(os, 'fdatasync', getattr(os, 'fsync', None))
2499
 
    if fn is not None:
2500
 
        fn(fileno)