Implemented %copy_dir_recursive with a Python script
[AROS.git] / scripts / cpy-dir-rec.py
blob3b4d45bb3e8d5f2fc3377abe7d58582f59ec1e49
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.
8 # The files '.cvsignore', 'mmakefile.src' and the directories
9 # 'CVS', '.svn' are ignored.
11 # This is a support script for the %copy_dir_recursive macro
12 # in make.tmpl. Main purpose is to fix problem with file names
13 # which contain space characters.
15 import sys, os, shutil
17 def copy_tree(src, dst, ignore):
18 names = os.listdir(src)
20 if not os.path.exists(dst):
21 os.makedirs(dst)
23 for name in names:
24 srcname = os.path.join(src, name)
25 dstname = os.path.join(dst, name)
27 if os.path.isdir(srcname):
28 if name not in ("CVS", ".svn"):
29 # print "Copying dir %s to %s" % (srcname, dstname)
30 copy_tree(srcname, dstname, ignore)
31 else:
32 if (name not in (".cvsignore", "mmakefile.src")) and (srcname not in ignore):
33 if not os.path.exists(dstname) or (os.path.getctime(srcname) > os.path.getctime(dstname)):
34 # print "Copying file %s to %s" % (srcname, dstname)
35 shutil.copy(srcname, dstname)
37 ################################################################################
39 st_source = 1
40 st_dest = 2
41 st_exclude = 3
42 state = 0
44 sourcedir = "."
45 destdirs = []
46 ignore = []
48 for arg in sys.argv:
49 if arg == "-s":
50 state = st_source
51 elif arg == "-d":
52 state = st_dest
53 elif arg == "-e":
54 state = st_exclude
55 else:
56 if state == st_source:
57 sourcedir = arg
58 elif state == st_dest:
59 destdirs.append(arg)
60 elif state == st_exclude:
61 ignore.append(arg)
63 for destdir in destdirs:
64 print "Copying directory '%s' to '%s', ignore '%s'" % (sourcedir, destdir, ignore)
65 copy_tree(sourcedir, destdir, ignore)