/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: John Arbash Meinel
  • Date: 2006-06-18 18:56:23 UTC
  • mfrom: (1790 +trunk)
  • mto: (1711.7.2 win32)
  • mto: This revision was merged to the branch mainline in revision 1796.
  • Revision ID: john@arbash-meinel.com-20060618185623-854bdd0fbc4f230f
[merge] bzr.dev 1790

Show diffs side-by-side

added added

removed removed

Lines of Context:
109
109
 
110
110
 
111
111
def file_kind(f, _lstat=os.lstat, _mapper=file_kind_from_stat_mode):
112
 
    return _mapper(_lstat(f).st_mode)
 
112
    try:
 
113
        return _mapper(_lstat(f).st_mode)
 
114
    except OSError, e:
 
115
        if getattr(e, 'errno', None) == errno.ENOENT:
 
116
            raise bzrlib.errors.NoSuchFile(f)
 
117
        raise
113
118
 
114
119
 
115
120
def kind_marker(kind):
832
837
        raise IllegalPath(path)
833
838
 
834
839
 
835
 
def walkdirs(top):
 
840
def walkdirs(top, prefix=""):
836
841
    """Yield data about all the directories in a tree.
837
842
    
838
843
    This yields all the data about the contents of a directory at a time.
842
847
    The data yielded is of the form:
843
848
    [(relpath, basename, kind, lstat, path_from_top), ...]
844
849
 
 
850
    :param prefix: Prefix the relpaths that are yielded with 'prefix'. This 
 
851
        allows one to walk a subtree but get paths that are relative to a tree
 
852
        rooted higher up.
845
853
    :return: an iterator over the dirs.
846
854
    """
847
855
    lstat = os.lstat
848
856
    pending = []
849
857
    _directory = _directory_kind
850
858
    _listdir = listdir
851
 
    pending = [("", "", _directory, None, top)]
 
859
    pending = [(prefix, "", _directory, None, top)]
852
860
    while pending:
853
861
        dirblock = []
854
862
        currentdir = pending.pop()
867
875
        for dir in reversed(dirblock):
868
876
            if dir[2] == _directory:
869
877
                pending.append(dir)
 
878
 
 
879
 
 
880
def path_prefix_key(path):
 
881
    """Generate a prefix-order path key for path.
 
882
 
 
883
    This can be used to sort paths in the same way that walkdirs does.
 
884
    """
 
885
    return (dirname(path) , path)
 
886
 
 
887
 
 
888
def compare_paths_prefix_order(path_a, path_b):
 
889
    """Compare path_a and path_b to generate the same order walkdirs uses."""
 
890
    key_a = path_prefix_key(path_a)
 
891
    key_b = path_prefix_key(path_b)
 
892
    return cmp(key_a, key_b)