/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 breezy/osutils.py

  • Committer: Jelmer Vernooij
  • Date: 2017-05-21 18:10:28 UTC
  • mto: This revision was merged to the branch mainline in revision 6623.
  • Revision ID: jelmer@jelmer.uk-20170521181028-zn04pdfw0od9hfj3
Rename brzlib => breezy.

Show diffs side-by-side

added added

removed removed

Lines of Context:
24
24
import time
25
25
import codecs
26
26
 
27
 
from brzlib.lazy_import import lazy_import
 
27
from breezy.lazy_import import lazy_import
28
28
lazy_import(globals(), """
29
29
from datetime import datetime
30
30
from datetime import timedelta
45
45
from tempfile import mkdtemp
46
46
import unicodedata
47
47
 
48
 
from brzlib import (
 
48
from breezy import (
49
49
    cache_utf8,
50
50
    config,
51
51
    errors,
52
52
    trace,
53
53
    win32utils,
54
54
    )
55
 
from brzlib.i18n import gettext
 
55
from breezy.i18n import gettext
56
56
""")
57
57
 
58
 
from brzlib.symbol_versioning import (
 
58
from breezy.symbol_versioning import (
59
59
    DEPRECATED_PARAMETER,
60
60
    deprecated_function,
61
61
    deprecated_in,
69
69
    )
70
70
 
71
71
 
72
 
import brzlib
73
 
from brzlib import symbol_versioning, _fs_enc
 
72
import breezy
 
73
from breezy import symbol_versioning, _fs_enc
74
74
 
75
75
 
76
76
# Cross platform wall-clock time functionality with decent resolution.
513
513
    mkdtemp = _win32_mkdtemp
514
514
    rename = _rename_wrap_exception(_win32_rename)
515
515
    try:
516
 
        from brzlib import _walkdirs_win32
 
516
        from breezy import _walkdirs_win32
517
517
    except ImportError:
518
518
        pass
519
519
    else:
566
566
 
567
567
    :param trace: If True trace the selected encoding via mutter().
568
568
    """
569
 
    from brzlib.trace import mutter
 
569
    from breezy.trace import mutter
570
570
    output_encoding = getattr(sys.stdout, 'encoding', None)
571
571
    if not output_encoding:
572
572
        input_encoding = getattr(sys.stdin, 'encoding', None)
1077
1077
    implementation should be loaded instead::
1078
1078
 
1079
1079
    >>> try:
1080
 
    >>>     import brzlib._fictional_extension_pyx
 
1080
    >>>     import breezy._fictional_extension_pyx
1081
1081
    >>> except ImportError, e:
1082
 
    >>>     brzlib.osutils.failed_to_load_extension(e)
1083
 
    >>>     import brzlib._fictional_extension_py
 
1082
    >>>     breezy.osutils.failed_to_load_extension(e)
 
1083
    >>>     import breezy._fictional_extension_py
1084
1084
    """
1085
1085
    # NB: This docstring is just an example, not a doctest, because doctest
1086
1086
    # currently can't cope with the use of lazy imports in this namespace --
1102
1102
    if config.GlobalStack().get('ignore_missing_extensions'):
1103
1103
        return
1104
1104
    # the warnings framework should by default show this only once
1105
 
    from brzlib.trace import warning
 
1105
    from breezy.trace import warning
1106
1106
    warning(
1107
1107
        "brz: warning: some compiled extensions could not be loaded; "
1108
1108
        "see <https://answers.launchpad.net/bzr/+faq/703>")
1112
1112
 
1113
1113
 
1114
1114
try:
1115
 
    from brzlib._chunks_to_lines_pyx import chunks_to_lines
 
1115
    from breezy._chunks_to_lines_pyx import chunks_to_lines
1116
1116
except ImportError, e:
1117
1117
    failed_to_load_extension(e)
1118
 
    from brzlib._chunks_to_lines_py import chunks_to_lines
 
1118
    from breezy._chunks_to_lines_py import chunks_to_lines
1119
1119
 
1120
1120
 
1121
1121
def split_lines(s):
1855
1855
            #       but that gets a bit tricky, and requires custom compiling
1856
1856
            #       for win98 anyway.
1857
1857
            try:
1858
 
                from brzlib._walkdirs_win32 import Win32ReadDir
 
1858
                from breezy._walkdirs_win32 import Win32ReadDir
1859
1859
                _selected_dir_reader = Win32ReadDir()
1860
1860
            except ImportError:
1861
1861
                pass
1862
1862
        elif _fs_enc in ('utf-8', 'ascii'):
1863
1863
            try:
1864
 
                from brzlib._readdir_pyx import UTF8DirReader
 
1864
                from breezy._readdir_pyx import UTF8DirReader
1865
1865
                _selected_dir_reader = UTF8DirReader()
1866
1866
            except ImportError, e:
1867
1867
                failed_to_load_extension(e)
2229
2229
def resource_string(package, resource_name):
2230
2230
    """Load a resource from a package and return it as a string.
2231
2231
 
2232
 
    Note: Only packages that start with brzlib are currently supported.
 
2232
    Note: Only packages that start with breezy are currently supported.
2233
2233
 
2234
2234
    This is designed to be a lightweight implementation of resource
2235
2235
    loading in a way which is API compatible with the same API from
2238
2238
    If and when pkg_resources becomes a standard library, this routine
2239
2239
    can delegate to it.
2240
2240
    """
2241
 
    # Check package name is within brzlib
2242
 
    if package == "brzlib":
 
2241
    # Check package name is within breezy
 
2242
    if package == "breezy":
2243
2243
        resource_relpath = resource_name
2244
 
    elif package.startswith("brzlib."):
2245
 
        package = package[len("brzlib."):].replace('.', os.sep)
 
2244
    elif package.startswith("breezy."):
 
2245
        package = package[len("breezy."):].replace('.', os.sep)
2246
2246
        resource_relpath = pathjoin(package, resource_name)
2247
2247
    else:
2248
 
        raise errors.BzrError('resource package %s not in brzlib' % package)
 
2248
        raise errors.BzrError('resource package %s not in breezy' % package)
2249
2249
 
2250
2250
    # Map the resource to a file and read its contents
2251
 
    base = dirname(brzlib.__file__)
 
2251
    base = dirname(breezy.__file__)
2252
2252
    if getattr(sys, 'frozen', None):    # bzr.exe
2253
2253
        base = abspath(pathjoin(base, '..', '..'))
2254
2254
    f = file(pathjoin(base, resource_relpath), "rU")
2261
2261
    global file_kind_from_stat_mode
2262
2262
    if file_kind_from_stat_mode is file_kind_from_stat_mode_thunk:
2263
2263
        try:
2264
 
            from brzlib._readdir_pyx import UTF8DirReader
 
2264
            from breezy._readdir_pyx import UTF8DirReader
2265
2265
            file_kind_from_stat_mode = UTF8DirReader().kind_from_mode
2266
2266
        except ImportError, e:
2267
2267
            # This is one time where we won't warn that an extension failed to
2268
2268
            # load. The extension is never available on Windows anyway.
2269
 
            from brzlib._readdir_py import (
 
2269
            from breezy._readdir_py import (
2270
2270
                _kind_from_mode as file_kind_from_stat_mode
2271
2271
                )
2272
2272
    return file_kind_from_stat_mode(mode)
2295
2295
    Keep in mind that this is not a complete solution to EINTR.  There is
2296
2296
    probably code in the Python standard library and other dependencies that
2297
2297
    may encounter EINTR if a signal arrives (and there is signal handler for
2298
 
    that signal).  So this function can reduce the impact for IO that brzlib
 
2298
    that signal).  So this function can reduce the impact for IO that breezy
2299
2299
    directly controls, but it is not a complete solution.
2300
2300
    """
2301
2301
    # Borrowed from Twisted's twisted.python.util.untilConcludes function.