[py-svn] py-trunk commit eefec6c36925: introduce "-d" to py.cleanup
commits-noreply at bitbucket.org
commits-noreply at bitbucket.org
Mon Oct 12 16:08:21 CEST 2009
# HG changeset patch -- Bitbucket.org
# Project py-trunk
# URL http://bitbucket.org/hpk42/py-trunk/overview/
# User holger krekel <holger at merlinux.eu>
# Date 1255339481 -7200
# Node ID eefec6c36925a832818b091e742705939557d505
# Parent 60b5a4f2ca9ad6894347afd4c449a1d16f66f523
introduce "-d" to py.cleanup
--- a/_py/cmdline/pycleanup.py
+++ b/_py/cmdline/pycleanup.py
@@ -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()
+
--- a/testing/cmdline/test_cmdline.py
+++ b/testing/cmdline/test_cmdline.py
@@ -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()
+
--- a/doc/changelog.txt
+++ b/doc/changelog.txt
@@ -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
More information about the pytest-commit
mailing list