15 if len(sys.argv) != 3:
16 print(
'usage: copy.py source dest', file=sys.stderr)
17 return 1
18 source = sys.argv[1]
19 dest = sys.argv[2]
20
21 if os.path.isdir(source):
22 print(f
'{source} is a directory, tool "copy" does not support directory copies')
23 return 1
24
25 if os.path.exists(dest):
26 if os.path.isdir(dest):
27
28 def _on_error(fn, path, dummy_excinfo):
29
30
31
32 if not os.access(path, os.W_OK):
33 os.chmod(path, stat.S_IWRITE)
34 fn(path)
35
36 shutil.rmtree(dest, onerror=_on_error)
37 else:
38 if not os.access(dest, os.W_OK):
39
40 os.chmod(dest, stat.S_IWRITE)
41 os.unlink(dest)
42
43 shutil.copy2(source, dest)
44
45
def print(*args, **kwargs)