/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

Merge from bzr.dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Bazaar-NG -- distributed version control
 
1
# Bazaar -- distributed version control
2
2
#
3
3
# Copyright (C) 2005 by Canonical Ltd
4
4
#
264
264
    try:
265
265
        fancy_rename(old, new, rename_func=os.rename, unlink_func=os.unlink)
266
266
    except OSError, e:
267
 
        if e.errno in (errno.EPERM, errno.EACCES, errno.EBUSY):
268
 
            # If we try to rename a non-existant file onto cwd, we get EPERM
269
 
            # instead of ENOENT, this will raise ENOENT if the old path
270
 
            # doesn't exist
 
267
        if e.errno in (errno.EPERM, errno.EACCES, errno.EBUSY, errno.EINVAL):
 
268
            # If we try to rename a non-existant file onto cwd, we get 
 
269
            # EPERM or EACCES instead of ENOENT, this will raise ENOENT 
 
270
            # if the old path doesn't exist, sometimes we get EACCES
 
271
            # On Linux, we seem to get EBUSY, on Mac we get EINVAL
271
272
            os.lstat(old)
272
273
        raise
273
274
 
274
275
 
 
276
def _mac_getcwd():
 
277
    return unicodedata.normalize('NFKC', os.getcwdu())
 
278
 
 
279
 
275
280
# Default is to just use the python builtins, but these can be rebound on
276
281
# particular platforms.
277
282
abspath = _posix_abspath
315
320
    def rmtree(path, ignore_errors=False, onerror=_win32_delete_readonly):
316
321
        """Replacer for shutil.rmtree: could remove readonly dirs/files"""
317
322
        return shutil.rmtree(path, ignore_errors, onerror)
 
323
elif sys.platform == 'darwin':
 
324
    getcwd = _mac_getcwd
318
325
 
319
326
 
320
327
def get_terminal_encoding():
788
795
    return _platform_normalizes_filenames
789
796
 
790
797
 
 
798
def _accessible_normalized_filename(path):
 
799
    """Get the unicode normalized path, and if you can access the file.
 
800
 
 
801
    On platforms where the system normalizes filenames (Mac OSX),
 
802
    you can access a file by any path which will normalize correctly.
 
803
    On platforms where the system does not normalize filenames 
 
804
    (Windows, Linux), you have to access a file by its exact path.
 
805
 
 
806
    Internally, bzr only supports NFC/NFKC normalization, since that is 
 
807
    the standard for XML documents.
 
808
 
 
809
    So return the normalized path, and a flag indicating if the file
 
810
    can be accessed by that path.
 
811
    """
 
812
 
 
813
    return unicodedata.normalize('NFKC', unicode(path)), True
 
814
 
 
815
 
 
816
def _inaccessible_normalized_filename(path):
 
817
    __doc__ = _accessible_normalized_filename.__doc__
 
818
 
 
819
    normalized = unicodedata.normalize('NFKC', unicode(path))
 
820
    return normalized, normalized == path
 
821
 
 
822
 
791
823
if _platform_normalizes_filenames:
792
 
    def unicode_filename(path):
793
 
        """Make sure 'path' is a properly normalized filename.
794
 
 
795
 
        On platforms where the system normalizes filenames (Mac OSX),
796
 
        you can access a file by any path which will normalize
797
 
        correctly.
798
 
        Internally, bzr only supports NFC/NFKC normalization, since
799
 
        that is the standard for XML documents.
800
 
        So we return an normalized path, and indicate this has been
801
 
        properly normalized.
802
 
 
803
 
        :return: (path, is_normalized) Return a path which can
804
 
                access the file, and whether or not this path is
805
 
                normalized.
806
 
        """
807
 
        return unicodedata.normalize('NFKC', path), True
 
824
    normalized_filename = _accessible_normalized_filename
808
825
else:
809
 
    def unicode_filename(path):
810
 
        """Make sure 'path' is a properly normalized filename.
811
 
 
812
 
        On platforms where the system does not normalize filenames 
813
 
        (Windows, Linux), you have to access a file by its exact path.
814
 
        Internally, bzr only supports NFC/NFKC normalization, since
815
 
        that is the standard for XML documents.
816
 
        So we return the original path, and indicate if this is
817
 
        properly normalized.
818
 
 
819
 
        :return: (path, is_normalized) Return a path which can
820
 
                access the file, and whether or not this path is
821
 
                normalized.
822
 
        """
823
 
        return path, unicodedata.normalize('NFKC', path) == path
 
826
    normalized_filename = _inaccessible_normalized_filename
824
827
 
825
828
 
826
829
def terminal_width():
872
875
    to exclude some directories, they are then not descended into.
873
876
    
874
877
    The data yielded is of the form:
875
 
    [(relpath, basename, kind, lstat, path_from_top), ...]
 
878
    ((directory-relpath, directory-path-from-top),
 
879
    [(relpath, basename, kind, lstat), ...]),
 
880
     - directory-relpath is the relative path of the directory being returned
 
881
       with respect to top. prefix is prepended to this.
 
882
     - directory-path-from-root is the path including top for this directory. 
 
883
       It is suitable for use with os functions.
 
884
     - relpath is the relative path within the subtree being walked.
 
885
     - basename is the basename of the path
 
886
     - kind is the kind of the file now. If unknown then the file is not
 
887
       present within the tree - but it may be recorded as versioned. See
 
888
       versioned_kind.
 
889
     - lstat is the stat data *if* the file was statted.
 
890
     - planned, not implemented: 
 
891
       path_from_tree_root is the path from the root of the tree.
876
892
 
877
893
    :param prefix: Prefix the relpaths that are yielded with 'prefix'. This 
878
894
        allows one to walk a subtree but get paths that are relative to a tree
879
895
        rooted higher up.
880
896
    :return: an iterator over the dirs.
881
897
    """
 
898
    #TODO there is a bit of a smell where the results of the directory-
 
899
    # summary in this, and the path from the root, may not agree 
 
900
    # depending on top and prefix - i.e. ./foo and foo as a pair leads to
 
901
    # potentially confusing output. We should make this more robust - but
 
902
    # not at a speed cost. RBC 20060731
882
903
    lstat = os.lstat
883
904
    pending = []
884
905
    _directory = _directory_kind
896
917
        for name in sorted(_listdir(top)):
897
918
            abspath = top + '/' + name
898
919
            statvalue = lstat(abspath)
899
 
            dirblock.append ((relroot + name, name, file_kind_from_stat_mode(statvalue.st_mode), statvalue, abspath))
900
 
        yield dirblock
 
920
            dirblock.append((relroot + name, name,
 
921
                file_kind_from_stat_mode(statvalue.st_mode),
 
922
                statvalue, abspath))
 
923
        yield (currentdir[0], top), dirblock
901
924
        # push the user specified dirs from dirblock
902
925
        for dir in reversed(dirblock):
903
926
            if dir[2] == _directory: