/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/osutils.py

  • Committer: Vincent Ladeuil
  • Date: 2011-11-24 15:48:29 UTC
  • mfrom: (6289 +trunk)
  • mto: This revision was merged to the branch mainline in revision 6337.
  • Revision ID: v.ladeuil+lp@free.fr-20111124154829-avowjpsxdl8yp2vz
merge trunk resolving conflicts

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):
939
941
    rps = []
940
942
    for f in ps:
941
943
        if f == '..':
942
 
            raise errors.BzrError("sorry, %r not allowed in path" % f)
 
944
            raise errors.BzrError(gettext("sorry, %r not allowed in path") % f)
943
945
        elif (f == '.') or (f == ''):
944
946
            pass
945
947
        else:
950
952
def joinpath(p):
951
953
    for f in p:
952
954
        if (f == '..') or (f is None) or (f == ''):
953
 
            raise errors.BzrError("sorry, %r not allowed in path" % f)
 
955
            raise errors.BzrError(gettext("sorry, %r not allowed in path") % f)
954
956
    return pathjoin(*p)
955
957
 
956
958
 
1000
1002
def report_extension_load_failures():
1001
1003
    if not _extension_load_failures:
1002
1004
        return
1003
 
    from bzrlib.config import GlobalConfig
1004
 
    if GlobalConfig().get_user_option_as_bool('ignore_missing_extensions'):
 
1005
    if config.GlobalStack().get('ignore_missing_extensions'):
1005
1006
        return
1006
1007
    # the warnings framework should by default show this only once
1007
1008
    from bzrlib.trace import warning
1169
1170
 
1170
1171
    if len(base) < MIN_ABS_PATHLENGTH:
1171
1172
        # must have space for e.g. a drive letter
1172
 
        raise ValueError('%r is too short to calculate a relative path'
 
1173
        raise ValueError(gettext('%r is too short to calculate a relative path')
1173
1174
            % (base,))
1174
1175
 
1175
1176
    rp = abspath(path)
2193
2194
    return file_kind_from_stat_mode(mode)
2194
2195
file_kind_from_stat_mode = file_kind_from_stat_mode_thunk
2195
2196
 
2196
 
 
2197
 
def file_kind(f, _lstat=os.lstat):
 
2197
def file_stat(f, _lstat=os.lstat):
2198
2198
    try:
2199
 
        return file_kind_from_stat_mode(_lstat(f).st_mode)
 
2199
        # XXX cache?
 
2200
        return _lstat(f)
2200
2201
    except OSError, e:
2201
2202
        if getattr(e, 'errno', None) in (errno.ENOENT, errno.ENOTDIR):
2202
2203
            raise errors.NoSuchFile(f)
2203
2204
        raise
2204
2205
 
 
2206
def file_kind(f, _lstat=os.lstat):
 
2207
    stat_value = file_stat(f, _lstat)
 
2208
    return file_kind_from_stat_mode(stat_value.st_mode)
2205
2209
 
2206
2210
def until_no_eintr(f, *a, **kw):
2207
2211
    """Run f(*a, **kw), retrying if an EINTR error occurs.
2267
2271
            termios.tcsetattr(fd, termios.TCSADRAIN, settings)
2268
2272
        return ch
2269
2273
 
2270
 
if sys.platform == 'linux2':
 
2274
if sys.platform.startswith('linux'):
2271
2275
    def _local_concurrency():
2272
2276
        try:
2273
2277
            return os.sysconf('SC_NPROCESSORS_ONLN')
2312
2316
    if concurrency is None:
2313
2317
        try:
2314
2318
            import multiprocessing
2315
 
        except ImportError:
 
2319
            concurrency = multiprocessing.cpu_count()
 
2320
        except (ImportError, NotImplementedError):
2316
2321
            # multiprocessing is only available on Python >= 2.6
 
2322
            # and multiprocessing.cpu_count() isn't implemented on all
 
2323
            # platforms
2317
2324
            try:
2318
2325
                concurrency = _local_concurrency()
2319
2326
            except (OSError, IOError):
2320
2327
                pass
2321
 
        else:
2322
 
            concurrency = multiprocessing.cpu_count()
2323
2328
    try:
2324
2329
        concurrency = int(concurrency)
2325
2330
    except (TypeError, ValueError):