1 # -*- coding: iso-8859-1 -*-
2 # Copyright © 2013, The AROS Development Team. All rights reserved.
4 # Copy directory 'src' recursively to 'dst' while ignoring
5 # all files given by 'ignore' parameter. Only files younger
6 # than those in 'dst' are copied. You can specify multiple
9 # The files '.cvsignore', 'mmakefile.src' and the directories
10 # 'CVS', '.svn' are ignored.
12 # This is a support script for the %copy_dir_recursive macro
13 # in make.tmpl. Main purpose is to fix problem with file names
14 # which contain space characters.
16 import sys
, os
, shutil
19 def in_ignore_list(name
, ignore
):
20 # check if rightmost part of name is in ignore list
22 if len(name
) >= len(ign
):
23 if name
[-len(ign
):] == ign
:
24 # print "%s found in ignore list" % name
29 def copy_tree(src
, dst
, ignore
):
30 names
= os
.listdir(src
)
32 if not os
.path
.exists(dst
):
36 srcname
= os
.path
.join(src
, name
)
37 dstname
= os
.path
.join(dst
, name
)
39 if os
.path
.isdir(srcname
):
40 if name
not in ("CVS", ".svn"):
41 # print "Copying dir %s to %s" % (srcname, dstname)
42 copy_tree(srcname
, dstname
, ignore
)
44 if (name
not in (".cvsignore", "mmakefile.src")) and not in_ignore_list(srcname
, ignore
):
45 if not os
.path
.exists(dstname
) or (os
.path
.getctime(srcname
) > os
.path
.getctime(dstname
)):
46 # print "Copying file %s to %s" % (srcname, dstname)
47 shutil
.copy(srcname
, dstname
)
49 ################################################################################
68 print "Usage: python cpy-dir-rec.py -s <souredir> -d <target directories> [-e <files to exclude>]"
70 print "cpy-dir-rec: unknown argument %s" % arg
73 if state
== st_source
:
75 elif state
== st_dest
:
77 elif state
== st_exclude
:
80 for destdir
in destdirs
:
81 print "Copying directory '%s' to '%s', ignore '%s'" % (sourcedir
, destdir
, ignore
)
82 copy_tree(sourcedir
, destdir
, ignore
)