remove-old-files.py - remove old files. It's a portable replacement for
`find start_dir -type f -mtime +31 -delete`.
-rm.py - remove files.
+rm.py - remove files and directories.
which.py - find a program in PATH and print full path to it.
Add option -s for cmp.py.
-Add option -r for rm.py.
-
-
Extend find.py: add options to find files by name, extension, path.
News
====
-Version 0.4.1 (2017-06-??)
+Version 0.5.0 (2017-07-??)
--------------------------
+* Add option -r for rm.py.
+
* Use remove-old-files.py to cleanup pip cache.
Version 0.4.0 (2017-06-04)
#! /usr/bin/env python
+import argparse
import os
-import sys
+import shutil
-for filename in sys.argv[1:]:
- os.unlink(filename)
+if __name__ == '__main__':
+ parser = argparse.ArgumentParser(description='Remove old files')
+ parser.add_argument('-r', '--recursive', action='store_true',
+ help='remove directories recursively')
+ parser.add_argument('names', nargs='+',
+ help='files/directories names to remove')
+ args = parser.parse_args()
+
+ for name in args.names:
+ if os.path.isdir(name):
+ if args.recursive:
+ shutil.rmtree(name)
+ else:
+ os.rmdir(name)
+ else:
+ os.unlink(name)
[sys.executable, test_prog_path, "test2"]) == 0
assert_files_exist('test1')
assert_files_not_exist('test2')
+
+ create_files(['test1', 'test2'])
+ assert_files_exist(['test1', 'test2'])
+ assert subprocess.call(
+ [sys.executable, test_prog_path, "-r", "test2"]) == 0
+ assert_files_exist('test1')
+ assert_files_not_exist('test2')
+
+
+def test_rm_recursive():
+ create_files(['test'])
+ create_files(['test'], 'subdir/subd2')
+ assert_files_exist(['test', 'subdir/subd2/test'])
+ assert subprocess.call(
+ [sys.executable, test_prog_path, "subdir"]) == 1
+ assert subprocess.call(
+ [sys.executable, test_prog_path, "-r", "subdir"]) == 0
+ assert_files_exist('test')
+ assert_files_not_exist(['subdir/subd2/test'])