ยปCore Development>Code coverage>Mac/Extras.install.py

Python code coverage for Mac/Extras.install.py

#countcontent
1n/a"""Recursively copy a directory but skip undesired files and
2n/adirectories (CVS, backup files, pyc files, etc)"""
3n/a
4n/aimport sys
5n/aimport os
6n/aimport shutil
7n/a
8n/averbose = 1
9n/adebug = 0
10n/a
11n/adef isclean(name):
12n/a if name == 'CVS': return 0
13n/a if name == '.cvsignore': return 0
14n/a if name == '.DS_store': return 0
15n/a if name == '.svn': return 0
16n/a if name.endswith('~'): return 0
17n/a if name.endswith('.BAK'): return 0
18n/a if name.endswith('.pyc'): return 0
19n/a if name.endswith('.pyo'): return 0
20n/a if name.endswith('.orig'): return 0
21n/a return 1
22n/a
23n/adef copycleandir(src, dst):
24n/a for cursrc, dirs, files in os.walk(src):
25n/a assert cursrc.startswith(src)
26n/a curdst = dst + cursrc[len(src):]
27n/a if verbose:
28n/a print("mkdir", curdst)
29n/a if not debug:
30n/a if not os.path.exists(curdst):
31n/a os.makedirs(curdst)
32n/a for fn in files:
33n/a if isclean(fn):
34n/a if verbose:
35n/a print("copy", os.path.join(cursrc, fn), os.path.join(curdst, fn))
36n/a if not debug:
37n/a shutil.copy2(os.path.join(cursrc, fn), os.path.join(curdst, fn))
38n/a else:
39n/a if verbose:
40n/a print("skipfile", os.path.join(cursrc, fn))
41n/a for i in range(len(dirs)-1, -1, -1):
42n/a if not isclean(dirs[i]):
43n/a if verbose:
44n/a print("skipdir", os.path.join(cursrc, dirs[i]))
45n/a del dirs[i]
46n/a
47n/adef main():
48n/a if len(sys.argv) != 3:
49n/a sys.stderr.write("Usage: %s srcdir dstdir\n" % sys.argv[0])
50n/a sys.exit(1)
51n/a copycleandir(sys.argv[1], sys.argv[2])
52n/a
53n/aif __name__ == '__main__':
54n/a main()