~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/osutils.py

  • Committer: Martin von Gagern
  • Date: 2011-06-01 12:53:56 UTC
  • mto: This revision was merged to the branch mainline in revision 6009.
  • Revision ID: martin.vgagern@gmx.net-20110601125356-lwozv2vecea6hxfz
Change from no_decorate to classify as name for the argument.

The command line switch remains as --no-classify, to keep backwards
compatibility.  Users are free to include --no-classify in an alias, and
still use --classify to change back.

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,
49
48
    )
50
 
from bzrlib.i18n import gettext
51
49
""")
52
50
 
53
51
from bzrlib.symbol_versioning import (
90
88
        user_encoding = get_user_encoding()
91
89
        return [a.decode(user_encoding) for a in sys.argv[1:]]
92
90
    except UnicodeDecodeError:
93
 
        raise errors.BzrError(gettext("Parameter {0!r} encoding is unsupported by {1} "
94
 
            "application locale.").format(a, user_encoding))
 
91
        raise errors.BzrError("Parameter %r encoding is unsupported by %s "
 
92
            "application locale." % (a, user_encoding))
95
93
 
96
94
 
97
95
def make_readonly(filename):
191
189
            if e.errno == errno.ENOENT:
192
190
                return False;
193
191
            else:
194
 
                raise errors.BzrError(gettext("lstat/stat of ({0!r}): {1!r}").format(f, e))
 
192
                raise errors.BzrError("lstat/stat of (%r): %r" % (f, e))
195
193
 
196
194
 
197
195
def fancy_rename(old, new, rename_func, unlink_func):
926
924
    rps = []
927
925
    for f in ps:
928
926
        if f == '..':
929
 
            raise errors.BzrError(gettext("sorry, %r not allowed in path") % f)
 
927
            raise errors.BzrError("sorry, %r not allowed in path" % f)
930
928
        elif (f == '.') or (f == ''):
931
929
            pass
932
930
        else:
937
935
def joinpath(p):
938
936
    for f in p:
939
937
        if (f == '..') or (f is None) or (f == ''):
940
 
            raise errors.BzrError(gettext("sorry, %r not allowed in path") % f)
 
938
            raise errors.BzrError("sorry, %r not allowed in path" % f)
941
939
    return pathjoin(*p)
942
940
 
943
941
 
987
985
def report_extension_load_failures():
988
986
    if not _extension_load_failures:
989
987
        return
990
 
    if config.GlobalStack().get('ignore_missing_extensions'):
 
988
    from bzrlib.config import GlobalConfig
 
989
    if GlobalConfig().get_user_option_as_bool('ignore_missing_extensions'):
991
990
        return
992
991
    # the warnings framework should by default show this only once
993
992
    from bzrlib.trace import warning
1155
1154
 
1156
1155
    if len(base) < MIN_ABS_PATHLENGTH:
1157
1156
        # must have space for e.g. a drive letter
1158
 
        raise ValueError(gettext('%r is too short to calculate a relative path')
 
1157
        raise ValueError('%r is too short to calculate a relative path'
1159
1158
            % (base,))
1160
1159
 
1161
1160
    rp = abspath(path)
2179
2178
    return file_kind_from_stat_mode(mode)
2180
2179
file_kind_from_stat_mode = file_kind_from_stat_mode_thunk
2181
2180
 
2182
 
def file_stat(f, _lstat=os.lstat):
 
2181
 
 
2182
def file_kind(f, _lstat=os.lstat):
2183
2183
    try:
2184
 
        # XXX cache?
2185
 
        return _lstat(f)
 
2184
        return file_kind_from_stat_mode(_lstat(f).st_mode)
2186
2185
    except OSError, e:
2187
2186
        if getattr(e, 'errno', None) in (errno.ENOENT, errno.ENOTDIR):
2188
2187
            raise errors.NoSuchFile(f)
2189
2188
        raise
2190
2189
 
2191
 
def file_kind(f, _lstat=os.lstat):
2192
 
    stat_value = file_stat(f, _lstat)
2193
 
    return file_kind_from_stat_mode(stat_value.st_mode)
2194
2190
 
2195
2191
def until_no_eintr(f, *a, **kw):
2196
2192
    """Run f(*a, **kw), retrying if an EINTR error occurs.
2256
2252
            termios.tcsetattr(fd, termios.TCSADRAIN, settings)
2257
2253
        return ch
2258
2254
 
2259
 
if sys.platform.startswith('linux'):
 
2255
if sys.platform == 'linux2':
2260
2256
    def _local_concurrency():
2261
2257
        try:
2262
2258
            return os.sysconf('SC_NPROCESSORS_ONLN')
2385
2381
    except UnicodeDecodeError:
2386
2382
        raise errors.BzrError("Can't decode username as %s." % \
2387
2383
                user_encoding)
2388
 
    except ImportError, e:
2389
 
        if sys.platform != 'win32':
2390
 
            raise
2391
 
        if str(e) != 'No module named pwd':
2392
 
            raise
2393
 
        # https://bugs.launchpad.net/bzr/+bug/660174
2394
 
        # getpass.getuser() is unable to return username on Windows
2395
 
        # if there is no USERNAME environment variable set.
2396
 
        # That could be true if bzr is running as a service,
2397
 
        # e.g. running `bzr serve` as a service on Windows.
2398
 
        # We should not fail with traceback in this case.
2399
 
        username = u'UNKNOWN'
2400
2384
    return username
2401
2385
 
2402
2386
 
2464
2448
            if os.access(f, os.X_OK):
2465
2449
                return f
2466
2450
    return None
2467
 
 
2468
 
 
2469
 
def _posix_is_local_pid_dead(pid):
2470
 
    """True if pid doesn't correspond to live process on this machine"""
2471
 
    try:
2472
 
        # Special meaning of unix kill: just check if it's there.
2473
 
        os.kill(pid, 0)
2474
 
    except OSError, e:
2475
 
        if e.errno == errno.ESRCH:
2476
 
            # On this machine, and really not found: as sure as we can be
2477
 
            # that it's dead.
2478
 
            return True
2479
 
        elif e.errno == errno.EPERM:
2480
 
            # exists, though not ours
2481
 
            return False
2482
 
        else:
2483
 
            mutter("os.kill(%d, 0) failed: %s" % (pid, e))
2484
 
            # Don't really know.
2485
 
            return False
2486
 
    else:
2487
 
        # Exists and our process: not dead.
2488
 
        return False
2489
 
 
2490
 
if sys.platform == "win32":
2491
 
    is_local_pid_dead = win32utils.is_local_pid_dead
2492
 
else:
2493
 
    is_local_pid_dead = _posix_is_local_pid_dead
2494
 
 
2495
 
 
2496
 
def fdatasync(fileno):
2497
 
    """Flush file contents to disk if possible.
2498
 
    
2499
 
    :param fileno: Integer OS file handle.
2500
 
    :raises TransportNotPossible: If flushing to disk is not possible.
2501
 
    """
2502
 
    fn = getattr(os, 'fdatasync', getattr(os, 'fsync', None))
2503
 
    if fn is not None:
2504
 
        fn(fileno)