~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/osutils.py

  • Committer: Johan Walles
  • Date: 2009-05-06 05:36:28 UTC
  • mfrom: (4332 +trunk)
  • mto: This revision was merged to the branch mainline in revision 4343.
  • Revision ID: johan.walles@gmail.com-20090506053628-tbf1wz4a0m9t684g
MergeĀ fromĀ upstream.

Show diffs side-by-side

added added

removed removed

Lines of Context:
77
77
O_BINARY = getattr(os, 'O_BINARY', 0)
78
78
 
79
79
 
80
 
def get_unicode_argv():
81
 
    try:
82
 
        user_encoding = get_user_encoding()
83
 
        return [a.decode(user_encoding) for a in sys.argv[1:]]
84
 
    except UnicodeDecodeError:
85
 
        raise errors.BzrError(("Parameter '%r' is unsupported by the current "
86
 
                                                            "encoding." % a))
87
 
 
88
 
 
89
80
def make_readonly(filename):
90
81
    """Make a filename read-only."""
91
82
    mod = os.lstat(filename).st_mode
108
99
    :return: A set of paths sufficient to include everything in paths via
109
100
        is_inside, drawn from the paths parameter.
110
101
    """
111
 
    if len(paths) < 2:
112
 
        return set(paths)
 
102
    search_paths = []
113
103
 
114
104
    def sort_key(path):
115
105
        return path.split('/')
116
106
    sorted_paths = sorted(list(paths), key=sort_key)
117
107
 
118
 
    search_paths = [sorted_paths[0]]
119
 
    for path in sorted_paths[1:]:
 
108
    for path in sorted_paths:
 
109
        if len(search_paths) == 0:
 
110
            # Result is empty, add first path
 
111
            search_paths.append(path)
 
112
            continue
120
113
        if not is_inside(search_paths[-1], path):
121
114
            # This path is unique, add it
122
115
            search_paths.append(path)
123
 
 
 
116
            continue
124
117
    return set(search_paths)
125
118
 
126
119
 
399
392
    def rmtree(path, ignore_errors=False, onerror=_win32_delete_readonly):
400
393
        """Replacer for shutil.rmtree: could remove readonly dirs/files"""
401
394
        return shutil.rmtree(path, ignore_errors, onerror)
402
 
 
403
 
    f = win32utils.get_unicode_argv     # special function or None
404
 
    if f is not None:
405
 
        get_unicode_argv = f
406
 
 
407
395
elif sys.platform == 'darwin':
408
396
    getcwd = _mac_getcwd
409
397
 
867
855
    return pathjoin(*p)
868
856
 
869
857
 
870
 
def parent_directories(filename):
871
 
    """Return the list of parent directories, deepest first.
872
 
    
873
 
    For example, parent_directories("a/b/c") -> ["a/b", "a"].
874
 
    """
875
 
    parents = []
876
 
    parts = splitpath(dirname(filename))
877
 
    while parts:
878
 
        parents.append(joinpath(parts))
879
 
        parts.pop()
880
 
    return parents
881
 
 
882
 
 
883
858
try:
884
859
    from bzrlib._chunks_to_lines_pyx import chunks_to_lines
885
860
except ImportError: