Commit 9ec4aa01 authored by Benjamin Peterson's avatar Benjamin Peterson

Replace instances of os.path.walk with os.walk

parent e3b1940e
...@@ -95,18 +95,16 @@ def make_zipfile (base_name, base_dir, verbose=0, dry_run=0): ...@@ -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", log.info("creating '%s' and adding '%s' to it",
zip_filename, base_dir) 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: if not dry_run:
z = zipfile.ZipFile(zip_filename, "w", z = zipfile.ZipFile(zip_filename, "w",
compression=zipfile.ZIP_DEFLATED) 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() z.close()
return zip_filename return zip_filename
......
...@@ -211,10 +211,6 @@ def touch(path, text=''): ...@@ -211,10 +211,6 @@ def touch(path, text=''):
fp.write(text) fp.write(text)
fp.close() fp.close()
def zap(actions, dirname, names):
for name in names:
actions.append(os.path.join(dirname, name))
class LongReprTest(unittest.TestCase): class LongReprTest(unittest.TestCase):
def setUp(self): def setUp(self):
longname = 'areallylongpackageandmodulenametotestreprtruncation' longname = 'areallylongpackageandmodulenametotestreprtruncation'
...@@ -233,7 +229,9 @@ class LongReprTest(unittest.TestCase): ...@@ -233,7 +229,9 @@ class LongReprTest(unittest.TestCase):
def tearDown(self): def tearDown(self):
actions = [] 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.append(self.pkgname)
actions.sort() actions.sort()
actions.reverse() actions.reverse()
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment