introduce "-d" to py.cleanup

--HG--
branch : trunk
This commit is contained in:
holger krekel 2009-10-12 11:24:41 +02:00
parent 90f39426b4
commit 1bdc0896ca
3 changed files with 38 additions and 5 deletions

View File

@ -18,6 +18,8 @@ def main():
action="store_true",
help="display would-be-removed filenames"
)
parser.add_option("-d", action="store_true", dest="removedir",
help="remove empty directories")
(options, args) = parser.parse_args()
if not args:
args = ["."]
@ -29,8 +31,16 @@ def main():
path = py.path.local(arg)
py.builtin.print_("cleaning path", path, "of extensions", ext)
for x in path.visit(shouldremove, lambda x: x.check(dotfile=0, link=0)):
if options.dryrun:
py.builtin.print_("would remove", x)
else:
py.builtin.print_("removing", x)
x.remove()
remove(x, options)
if options.removedir:
for x in path.visit(lambda x: x.check(dir=1),
lambda x: x.check(dotfile=0, link=0)):
remove(x, options)
def remove(path, options):
if options.dryrun:
py.builtin.print_("would remove", path)
else:
py.builtin.print_("removing", path)
path.remove()

View File

@ -1,6 +1,8 @@
Changes between 1.0.2 and '1.1.0b1'
=====================================
* introduce and test "py.cleanup -d" to remove empty directories
* fix issue #59 - robustify unittest test collection
* make bpython/help interaction work by adding an __all__ attribute

View File

@ -26,3 +26,24 @@ class TestPyLookup:
result.stdout.fnmatch_lines(
["%s:1: stuff = x" % (searched.basename,)]
)
class TestPyCleanup:
def test_basic(self, testdir, tmpdir):
p = tmpdir.ensure("hello.py")
result = testdir.runpybin("py.cleanup", tmpdir)
assert result.ret == 0
assert p.check()
pyc = p.new(ext='pyc')
pyc.ensure()
result = testdir.runpybin("py.cleanup", tmpdir)
assert not pyc.check()
def test_dir_remove(self, testdir, tmpdir):
p = tmpdir.mkdir("a")
result = testdir.runpybin("py.cleanup", tmpdir)
assert result.ret == 0
assert p.check()
result = testdir.runpybin("py.cleanup", tmpdir, '-d')
assert result.ret == 0
assert not p.check()