-Add option -f for rm.py.
-
-
Add option -s for cmp.py.
* rm.py ask interactively to remove read-only files or directories.
+* Add option -f for rm.py.
+
Version 0.5.0 (2017-07-09)
--------------------------
if __name__ == '__main__':
parser = argparse.ArgumentParser(description='Remove files/directories')
+ parser.add_argument('-f', '--force', action='store_true',
+ help='force (ignore non-existing files and errors)')
parser.add_argument('-r', '--recursive', action='store_true',
help='remove directories recursively')
parser.add_argument('names', nargs='+',
args = parser.parse_args()
for name in args.names:
+ if args.force and not os.path.exists(name):
+ continue
is_dir = os.path.isdir(name)
if not os.access(name, os.W_OK):
if is_dir:
continue
if is_dir:
if args.recursive:
- shutil.rmtree(name)
+ shutil.rmtree(name, args.force)
else:
os.rmdir(name)
else:
assert_files_exist('test1')
assert_files_not_exist('test2')
+ assert subprocess.call(
+ [sys.executable, test_prog_path, "test3"]) == 1 # not exists
+ assert subprocess.call(
+ [sys.executable, test_prog_path, "-f", "test3"]) == 0
+
def test_rm_recursive():
create_files(['test'])
[sys.executable, test_prog_path, "-r", "subdir"]) == 0
assert_files_exist('test')
assert_files_not_exist(['subdir/subd2/test'])
+
+ assert subprocess.call(
+ [sys.executable, test_prog_path, "-r", "test3"]) == 1 # not exists
+ assert subprocess.call(
+ [sys.executable, test_prog_path, "-rf", "test3"]) == 0