1 # -*- coding: iso-8859-1 -*-
2 # Copyright © 2013-2017, 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 # Conversion to Unicode is needed in order to yield Unicode file names.
31 # This can be important on Windows. Without this the script fails to access
32 # directories like Locale/Help/Español on non-western systems, where locale
33 # is different from Latin-1 (e. g. russian).
34 # See http://docs.python.org/2/howto/unicode.html#unicode-filenames
35 names
= os
.listdir(unicode(src
))
37 if not os
.path
.exists(dst
):
41 srcname
= os
.path
.join(src
, name
)
42 dstname
= os
.path
.join(dst
, name
)
44 if os
.path
.isdir(srcname
):
45 if name
not in ("CVS", ".svn"):
46 # print "Copying dir %s to %s" % (srcname, dstname)
47 copy_tree(srcname
, dstname
, ignore
)
49 if (name
not in (".cvsignore", "mmakefile.src", "mmakefile")) and not in_ignore_list(srcname
, ignore
):
50 if not os
.path
.exists(dstname
) or (os
.path
.getctime(srcname
) > os
.path
.getctime(dstname
)):
51 # print "Copying file %s to %s" % (srcname, dstname)
52 shutil
.copy(srcname
, dstname
)
54 ################################################################################
73 print "Usage: python cpy-dir-rec.py -s <souredir> -d <target directories> [-e <files to exclude>]"
75 print "cpy-dir-rec: unknown argument %s" % arg
78 if state
== st_source
:
80 elif state
== st_dest
:
82 elif state
== st_exclude
:
85 for destdir
in destdirs
:
86 print "Copying directory '%s' to '%s', ignore '%s'" % (sourcedir
, destdir
, ignore
)
87 copy_tree(sourcedir
, destdir
, ignore
)