/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: 2020-05-24 00:39:50 UTC
  • mto: This revision was merged to the branch mainline in revision 7504.
  • Revision ID: jelmer@jelmer.uk-20200524003950-bbc545r76vc5yajg
Add github action.

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
 
86
90
def make_readonly(filename):
87
91
    """Make a filename read-only."""
88
92
    mod = os.lstat(filename).st_mode
307
311
    return path
308
312
 
309
313
 
 
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
 
310
323
def _posix_get_home_dir():
311
324
    """Get the home directory of the current user as a unicode path"""
312
325
    path = posixpath.expanduser("~")
417
430
realpath = _posix_realpath
418
431
pathjoin = os.path.join
419
432
normpath = _posix_normpath
 
433
path_from_environ = _posix_path_from_environ
420
434
_get_home_dir = _posix_get_home_dir
421
435
getuser_unicode = _posix_getuser_unicode
422
436
getcwd = _getcwd
474
488
        """Replacer for shutil.rmtree: could remove readonly dirs/files"""
475
489
        return shutil.rmtree(path, ignore_errors, onerror)
476
490
 
 
491
    get_unicode_argv = getattr(win32utils, 'get_unicode_argv', get_unicode_argv)
 
492
    path_from_environ = win32utils.get_environ_unicode
477
493
    _get_home_dir = win32utils.get_home_location
478
494
    getuser_unicode = win32utils.get_user_name
479
495
 
1362
1378
    return unicode_or_utf8_string.encode('utf-8')
1363
1379
 
1364
1380
 
 
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
 
1365
1413
_platform_normalizes_filenames = False
1366
1414
if sys.platform == 'darwin':
1367
1415
    _platform_normalizes_filenames = True
2537
2585
            raise exception_class(path)
2538
2586
 
2539
2587
 
 
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
 
2540
2601
def read_mtab(path):
2541
2602
    """Read an fstab-style file and extract mountpoint+filesystem information.
2542
2603