From 9ec4aa01f9e1b5f0d8ed94005ac5b14d6ff94ebc Mon Sep 17 00:00:00 2001 From: Benjamin Peterson Date: Thu, 8 May 2008 22:09:54 +0000 Subject: [PATCH] Replace instances of os.path.walk with os.walk --- Lib/distutils/archive_util.py | 14 ++++++-------- Lib/test/test_repr.py | 8 +++----- 2 files changed, 9 insertions(+), 13 deletions(-) diff --git a/Lib/distutils/archive_util.py b/Lib/distutils/archive_util.py index a9c6a5b488f..264e66faf21 100644 --- a/Lib/distutils/archive_util.py +++ b/Lib/distutils/archive_util.py @@ -95,18 +95,16 @@ def make_zipfile (base_name, base_dir, verbose=0, dry_run=0): log.info("creating '%s' and adding '%s' to it", zip_filename, base_dir) - def visit (z, dirname, names): - for name in names: - path = os.path.normpath(os.path.join(dirname, name)) - if os.path.isfile(path): - z.write(path, path) - log.info("adding '%s'" % path) - if not dry_run: z = zipfile.ZipFile(zip_filename, "w", compression=zipfile.ZIP_DEFLATED) - os.path.walk(base_dir, visit, z) + for dirpath, dirnames, filenames in os.walk(base_dir): + for name in filenames: + path = os.path.normpath(os.path.join(dirpath, name)) + if os.path.isfile(path): + z.write(path, path) + log.info("adding '%s'" % path) z.close() return zip_filename diff --git a/Lib/test/test_repr.py b/Lib/test/test_repr.py index 6284f4095a0..1094816ae60 100644 --- a/Lib/test/test_repr.py +++ b/Lib/test/test_repr.py @@ -211,10 +211,6 @@ def touch(path, text=''): fp.write(text) fp.close() -def zap(actions, dirname, names): - for name in names: - actions.append(os.path.join(dirname, name)) - class LongReprTest(unittest.TestCase): def setUp(self): longname = 'areallylongpackageandmodulenametotestreprtruncation' @@ -233,7 +229,9 @@ class LongReprTest(unittest.TestCase): def tearDown(self): actions = [] - os.path.walk(self.pkgname, zap, actions) + for dirpath, dirnames, filenames in os.walk(self.pkgname): + for name in dirnames + filenames: + actions.append(os.path.join(dirpath, name)) actions.append(self.pkgname) actions.sort() actions.reverse()