| Index: test/lib/TestCmd.py
|
| diff --git a/test/lib/TestCmd.py b/test/lib/TestCmd.py
|
| index 71403614b9bf091e0f052d152980bb308bb77189..4db976013b04662e3fea958f0bda30b941332af9 100644
|
| --- a/test/lib/TestCmd.py
|
| +++ b/test/lib/TestCmd.py
|
| @@ -311,13 +311,6 @@ except NameError:
|
| result.append(tuple(map(lambda l, i=i: l[i], lists)))
|
| return result
|
|
|
| -class Collector:
|
| - def __init__(self, top):
|
| - self.entries = [top]
|
| - def __call__(self, arg, dirname, names):
|
| - pathjoin = lambda n, d=dirname: os.path.join(d, n)
|
| - self.entries.extend(map(pathjoin, names))
|
| -
|
| def _caller(tblist, skip):
|
| string = ""
|
| arr = []
|
| @@ -1462,29 +1455,29 @@ class TestCmd(object):
|
| # It's a directory and we're trying to turn on read
|
| # permission, so it's also pretty easy, just chmod the
|
| # directory and then chmod every entry on our walk down the
|
| - # tree. Because os.path.walk() is top-down, we'll enable
|
| + # tree. Because os.walk() is top-down, we'll enable
|
| # read permission on any directories that have it disabled
|
| - # before os.path.walk() tries to list their contents.
|
| + # before os.walk() tries to list their contents.
|
| do_chmod(top)
|
|
|
| - def chmod_entries(arg, dirname, names, do_chmod=do_chmod):
|
| - for n in names:
|
| + for dirname, dirnames, filenames in os.walk(top):
|
| + for n in dirnames:
|
| + do_chmod(os.path.join(dirname, n))
|
| + for n in filenames:
|
| do_chmod(os.path.join(dirname, n))
|
| -
|
| - os.path.walk(top, chmod_entries, None)
|
| else:
|
| # It's a directory and we're trying to turn off read
|
| # permission, which means we have to chmod the directoreis
|
| # in the tree bottom-up, lest disabling read permission from
|
| # the top down get in the way of being able to get at lower
|
| - # parts of the tree. But os.path.walk() visits things top
|
| - # down, so we just use an object to collect a list of all
|
| - # of the entries in the tree, reverse the list, and then
|
| - # chmod the reversed (bottom-up) list.
|
| - col = Collector(top)
|
| - os.path.walk(top, col, None)
|
| - col.entries.reverse()
|
| - for d in col.entries: do_chmod(d)
|
| + # parts of the tree.
|
| + for dirname, dirnames, filenames in os.walk(top, topdown=False):
|
| + for n in dirnames:
|
| + do_chmod(os.path.join(dirname, n))
|
| + for n in filenames:
|
| + do_chmod(os.path.join(dirname, n))
|
| +
|
| + do_chmod(top)
|
|
|
| def writable(self, top, write=1):
|
| """Make the specified directory tree writable (write == 1)
|
| @@ -1518,9 +1511,12 @@ class TestCmd(object):
|
| if os.path.isfile(top):
|
| do_chmod(top)
|
| else:
|
| - col = Collector(top)
|
| - os.path.walk(top, col, None)
|
| - for d in col.entries: do_chmod(d)
|
| + do_chmod(top)
|
| + for dirname, dirnames, filenames in os.walk(top):
|
| + for n in dirnames:
|
| + do_chmod(os.path.join(dirname, n))
|
| + for n in filenames:
|
| + do_chmod(os.path.join(dirname, n))
|
|
|
| def executable(self, top, execute=1):
|
| """Make the specified directory tree executable (execute == 1)
|
| @@ -1551,29 +1547,29 @@ class TestCmd(object):
|
| # It's a directory and we're trying to turn on execute
|
| # permission, so it's also pretty easy, just chmod the
|
| # directory and then chmod every entry on our walk down the
|
| - # tree. Because os.path.walk() is top-down, we'll enable
|
| + # tree. Because os.walk() is top-down, we'll enable
|
| # execute permission on any directories that have it disabled
|
| - # before os.path.walk() tries to list their contents.
|
| + # before os.walk() tries to list their contents.
|
| do_chmod(top)
|
|
|
| - def chmod_entries(arg, dirname, names, do_chmod=do_chmod):
|
| - for n in names:
|
| + for dirname, dirnames, filenames in os.walk(top):
|
| + for n in dirnames:
|
| + do_chmod(os.path.join(dirname, n))
|
| + for n in filenames:
|
| do_chmod(os.path.join(dirname, n))
|
| -
|
| - os.path.walk(top, chmod_entries, None)
|
| else:
|
| # It's a directory and we're trying to turn off execute
|
| # permission, which means we have to chmod the directories
|
| # in the tree bottom-up, lest disabling execute permission from
|
| # the top down get in the way of being able to get at lower
|
| - # parts of the tree. But os.path.walk() visits things top
|
| - # down, so we just use an object to collect a list of all
|
| - # of the entries in the tree, reverse the list, and then
|
| - # chmod the reversed (bottom-up) list.
|
| - col = Collector(top)
|
| - os.path.walk(top, col, None)
|
| - col.entries.reverse()
|
| - for d in col.entries: do_chmod(d)
|
| + # parts of the tree.
|
| + for dirname, dirnames, filenames in os.walk(top, topdown=False):
|
| + for n in dirnames:
|
| + do_chmod(os.path.join(dirname, n))
|
| + for n in filenames:
|
| + do_chmod(os.path.join(dirname, n))
|
| +
|
| + do_chmod(top)
|
|
|
| def write(self, file, content, mode = 'wb'):
|
| """Writes the specified content text (second argument) to the
|
|
|