~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/osutils.py

  • Committer: Jelmer Vernooij
  • Date: 2011-10-04 22:20:49 UTC
  • mto: This revision was merged to the branch mainline in revision 6190.
  • Revision ID: jelmer@samba.org-20111004222049-d9glniyleu0pppzd
Add a load_plugin_translations method.

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,
45
46
    errors,
46
47
    trace,
47
48
    win32utils,
48
49
    )
 
50
from bzrlib.i18n import gettext
49
51
""")
50
52
 
51
53
from bzrlib.symbol_versioning import (
88
90
        user_encoding = get_user_encoding()
89
91
        return [a.decode(user_encoding) for a in sys.argv[1:]]
90
92
    except UnicodeDecodeError:
91
 
        raise errors.BzrError("Parameter %r encoding is unsupported by %s "
92
 
            "application locale." % (a, user_encoding))
 
93
        raise errors.BzrError(gettext("Parameter {0!r} encoding is unsupported by {1} "
 
94
            "application locale.").format(a, user_encoding))
93
95
 
94
96
 
95
97
def make_readonly(filename):
189
191
            if e.errno == errno.ENOENT:
190
192
                return False;
191
193
            else:
192
 
                raise errors.BzrError("lstat/stat of (%r): %r" % (f, e))
 
194
                raise errors.BzrError(gettext("lstat/stat of ({0!r}): {1!r}").format(f, e))
193
195
 
194
196
 
195
197
def fancy_rename(old, new, rename_func, unlink_func):
924
926
    rps = []
925
927
    for f in ps:
926
928
        if f == '..':
927
 
            raise errors.BzrError("sorry, %r not allowed in path" % f)
 
929
            raise errors.BzrError(gettext("sorry, %r not allowed in path") % f)
928
930
        elif (f == '.') or (f == ''):
929
931
            pass
930
932
        else:
935
937
def joinpath(p):
936
938
    for f in p:
937
939
        if (f == '..') or (f is None) or (f == ''):
938
 
            raise errors.BzrError("sorry, %r not allowed in path" % f)
 
940
            raise errors.BzrError(gettext("sorry, %r not allowed in path") % f)
939
941
    return pathjoin(*p)
940
942
 
941
943
 
985
987
def report_extension_load_failures():
986
988
    if not _extension_load_failures:
987
989
        return
988
 
    from bzrlib.config import GlobalConfig
989
 
    if GlobalConfig().get_user_option_as_bool('ignore_missing_extensions'):
 
990
    if config.GlobalStack().get('ignore_missing_extensions'):
990
991
        return
991
992
    # the warnings framework should by default show this only once
992
993
    from bzrlib.trace import warning
1154
1155
 
1155
1156
    if len(base) < MIN_ABS_PATHLENGTH:
1156
1157
        # must have space for e.g. a drive letter
1157
 
        raise ValueError('%r is too short to calculate a relative path'
 
1158
        raise ValueError(gettext('%r is too short to calculate a relative path')
1158
1159
            % (base,))
1159
1160
 
1160
1161
    rp = abspath(path)
2178
2179
    return file_kind_from_stat_mode(mode)
2179
2180
file_kind_from_stat_mode = file_kind_from_stat_mode_thunk
2180
2181
 
2181
 
 
2182
 
def file_kind(f, _lstat=os.lstat):
 
2182
def file_stat(f, _lstat=os.lstat):
2183
2183
    try:
2184
 
        return file_kind_from_stat_mode(_lstat(f).st_mode)
 
2184
        # XXX cache?
 
2185
        return _lstat(f)
2185
2186
    except OSError, e:
2186
2187
        if getattr(e, 'errno', None) in (errno.ENOENT, errno.ENOTDIR):
2187
2188
            raise errors.NoSuchFile(f)
2188
2189
        raise
2189
2190
 
 
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)
2190
2194
 
2191
2195
def until_no_eintr(f, *a, **kw):
2192
2196
    """Run f(*a, **kw), retrying if an EINTR error occurs.
2252
2256
            termios.tcsetattr(fd, termios.TCSADRAIN, settings)
2253
2257
        return ch
2254
2258
 
2255
 
if sys.platform == 'linux2':
 
2259
if sys.platform.startswith('linux'):
2256
2260
    def _local_concurrency():
2257
2261
        try:
2258
2262
            return os.sysconf('SC_NPROCESSORS_ONLN')
2487
2491
    is_local_pid_dead = win32utils.is_local_pid_dead
2488
2492
else:
2489
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)