1106
1106
pending.append(dir)
1109
def _walkdirs_utf8(top, prefix=""):
1110
"""Yield data about all the directories in a tree.
1112
This yields the same information as walkdirs() only each entry is yielded
1113
in utf-8. On platforms which have a filesystem encoding of utf8 the paths
1114
are returned as exact byte-strings.
1118
_directory = _directory_kind
1119
_listdir = os.listdir
1120
_kind_from_mode = file_kind_from_stat_mode
1121
if sys.platform == 'win32':
1122
# We need to do the listdir using unicode paths, and then encode them
1124
assert False, 'not supported yet'
1125
if sys.getfilesystemencoding() not in ('UTF-8', 'US-ASCII',
1126
'ANSI_X3.4-1968'): # ascii
1127
assert False, 'not supported yet'
1128
# TODO: make these assert instead
1129
if isinstance(top, unicode):
1130
top = top.encode('utf8')
1131
if isinstance(prefix, unicode):
1132
prefix = prefix.encode('utf8')
1134
# The in-memory dirblocks should always have a prefix ending in '/'
1135
# unless the prefix is '' then it should not have a trailing slash
1136
pending = [(prefix, top)]
1138
relroot, top = pending.pop()
1142
rel_prefix = relroot + '/'
1143
top_slash = top + '/'
1144
# In plain for loop form
1146
for name in sorted(_listdir(top)):
1147
abspath = top_slash + name
1148
statvalue = _lstat(abspath)
1149
kind = _kind_from_mode(statvalue.st_mode)
1150
dirblock.append((rel_prefix + name, name, kind, statvalue, abspath))
1152
# 0 - relpath, 1- basename, 2- kind, 3- stat, 4-toppath
1153
## In list/generator comprehension form. On a 55k entry tree, this form
1154
## takes 1.75s versus 1.8s. So it is saving approx 50ms. Not a huge
1155
## savings, and may not be worth the complexity. And on smaller trees,
1156
## I've seen 115ms here versus 102ms in the for loop. So it isn't
1157
## always a win. This is just left for posterity.
1158
# dirblock = [(rel_prefix + name, # relpath
1160
# _kind_from_mode(statvalue.st_mode), # kind
1162
# abspath) # path on disk
1163
# for name, abspath, statvalue in
1164
# ((name, abspath, _lstat(abspath))
1165
# for name, abspath in
1166
# ((name, top_slash + name)
1167
# for name in sorted(_listdir(top))
1171
yield (relroot, top), dirblock
1172
# push the user specified dirs from dirblock
1173
pending.extend((d[0], d[4])
1174
for d in reversed(dirblock)
1175
if d[2] == _directory)
1109
1178
def copy_tree(from_path, to_path, handlers={}):
1110
1179
"""Copy all of the entries in from_path into to_path.