/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: Gustav Hartvigsson
  • Date: 2021-01-11 20:19:38 UTC
  • mfrom: (7526.3.2 work)
  • Revision ID: gustav.hartvigsson@gmail.com-20210111201938-omr9wjz3qdgyxe8k
MergedĀ lp:brz

Show diffs side-by-side

added added

removed removed

Lines of Context:
83
83
        self.timezone = timezone
84
84
 
85
85
 
86
 
def get_unicode_argv():
87
 
    return sys.argv[1:]
88
 
 
89
 
 
90
86
def make_readonly(filename):
91
87
    """Make a filename read-only."""
92
88
    mod = os.lstat(filename).st_mode
311
307
    return path
312
308
 
313
309
 
314
 
def _posix_path_from_environ(key):
315
 
    """Get unicode path from `key` in environment or None if not present
316
 
 
317
 
    Note that posix systems use arbitrary byte strings for filesystem objects,
318
 
    so a path that raises BadFilenameEncoding here may still be accessible.
319
 
    """
320
 
    return os.environ.get(key, None)
321
 
 
322
 
 
323
310
def _posix_get_home_dir():
324
311
    """Get the home directory of the current user as a unicode path"""
325
312
    path = posixpath.expanduser("~")
430
417
realpath = _posix_realpath
431
418
pathjoin = os.path.join
432
419
normpath = _posix_normpath
433
 
path_from_environ = _posix_path_from_environ
434
420
_get_home_dir = _posix_get_home_dir
435
421
getuser_unicode = _posix_getuser_unicode
436
422
getcwd = _getcwd
488
474
        """Replacer for shutil.rmtree: could remove readonly dirs/files"""
489
475
        return shutil.rmtree(path, ignore_errors, onerror)
490
476
 
491
 
    get_unicode_argv = getattr(win32utils, 'get_unicode_argv', get_unicode_argv)
492
 
    path_from_environ = win32utils.get_environ_unicode
493
477
    _get_home_dir = win32utils.get_home_location
494
478
    getuser_unicode = win32utils.get_user_name
495
479
 
1378
1362
    return unicode_or_utf8_string.encode('utf-8')
1379
1363
 
1380
1364
 
1381
 
def safe_revision_id(unicode_or_utf8_string):
1382
 
    """Revision ids should now be utf8, but at one point they were unicode.
1383
 
 
1384
 
    :param unicode_or_utf8_string: A possibly Unicode revision_id. (can also be
1385
 
        utf8 or None).
1386
 
    :return: None or a utf8 revision id.
1387
 
    """
1388
 
    if (unicode_or_utf8_string is None
1389
 
            or unicode_or_utf8_string.__class__ == bytes):
1390
 
        return unicode_or_utf8_string
1391
 
    raise TypeError('Unicode revision ids are no longer supported. '
1392
 
                    'Revision id generators should be creating utf8 revision '
1393
 
                    'ids.')
1394
 
 
1395
 
 
1396
 
def safe_file_id(unicode_or_utf8_string):
1397
 
    """File ids should now be utf8, but at one point they were unicode.
1398
 
 
1399
 
    This is the same as safe_utf8, except it uses the cached encode functions
1400
 
    to save a little bit of performance.
1401
 
 
1402
 
    :param unicode_or_utf8_string: A possibly Unicode file_id. (can also be
1403
 
        utf8 or None).
1404
 
    :return: None or a utf8 file id.
1405
 
    """
1406
 
    if (unicode_or_utf8_string is None
1407
 
            or unicode_or_utf8_string.__class__ == bytes):
1408
 
        return unicode_or_utf8_string
1409
 
    raise TypeError('Unicode file ids are no longer supported. '
1410
 
                    'File id generators should be creating utf8 file ids.')
1411
 
 
1412
 
 
1413
1365
_platform_normalizes_filenames = False
1414
1366
if sys.platform == 'darwin':
1415
1367
    _platform_normalizes_filenames = True
2585
2537
            raise exception_class(path)
2586
2538
 
2587
2539
 
2588
 
def is_environment_error(evalue):
2589
 
    """True if exception instance is due to a process environment issue
2590
 
 
2591
 
    This includes OSError and IOError, but also other errors that come from
2592
 
    the operating system or core libraries but are not subclasses of those.
2593
 
    """
2594
 
    if isinstance(evalue, (EnvironmentError, select.error)):
2595
 
        return True
2596
 
    if sys.platform == "win32" and win32utils._is_pywintypes_error(evalue):
2597
 
        return True
2598
 
    return False
2599
 
 
2600
 
 
2601
2540
def read_mtab(path):
2602
2541
    """Read an fstab-style file and extract mountpoint+filesystem information.
2603
2542