1 """Recursively copy a directory but skip undesired files and
2 directories (CVS, backup files, pyc files, etc)"""
12 if name
== 'CVS': return 0
13 if name
== '.cvsignore': return 0
14 if name
== '.DS_store': return 0
15 if name
== '.svn': return 0
16 if name
.endswith('~'): return 0
17 if name
.endswith('.BAK'): return 0
18 if name
.endswith('.pyc'): return 0
19 if name
.endswith('.pyo'): return 0
20 if name
.endswith('.orig'): return 0
23 def copycleandir(src
, dst
):
24 for cursrc
, dirs
, files
in os
.walk(src
):
25 assert cursrc
.startswith(src
)
26 curdst
= dst
+ cursrc
[len(src
):]
30 if not os
.path
.exists(curdst
):
35 print "copy", os
.path
.join(cursrc
, fn
), os
.path
.join(curdst
, fn
)
37 shutil
.copy2(os
.path
.join(cursrc
, fn
), os
.path
.join(curdst
, fn
))
40 print "skipfile", os
.path
.join(cursrc
, fn
)
41 for i
in range(len(dirs
)-1, -1, -1):
42 if not isclean(dirs
[i
]):
44 print "skipdir", os
.path
.join(cursrc
, dirs
[i
])
48 if len(sys
.argv
) != 3:
49 sys
.stderr
.write("Usage: %s srcdir dstdir\n" % sys
.argv
[0])
51 copycleandir(sys
.argv
[1], sys
.argv
[2])
53 if __name__
== '__main__':