Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(13)

Unified Diff: test/lib/TestCmd.py

Issue 1429933006: Replaced deprecated os.path.walk usage with os.walk Base URL: https://chromium.googlesource.com/external/gyp.git@master
Patch Set: Rebase with master (4ec6c4e3a94bd04a6da2858163d40b2429b8aad1) Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698