start service tasks separately in-case platforms need to perform additional set-up...
[AROS.git] / scripts / cpy-dir-rec.py
blobb8fb384b3d1ff655214269d25a4e2e629ba3942e
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
7 # 'dst' directories.
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
21 for ign in ignore:
22 if len(name) >= len(ign):
23 if name[-len(ign):] == ign:
24 # print "%s found in ignore list" % name
25 return True
26 return False
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):
38 os.makedirs(dst)
40 for name in names:
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)
48 else:
49 if (name not in (".cvsignore", "mmakefile.src")) 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 ################################################################################
56 st_source = 1
57 st_dest = 2
58 st_exclude = 3
59 state = 0
61 sourcedir = "."
62 destdirs = []
63 ignore = []
65 for arg in sys.argv:
66 if arg == "-s":
67 state = st_source
68 elif arg == "-d":
69 state = st_dest
70 elif arg == "-e":
71 state = st_exclude
72 elif arg == "-h":
73 print "Usage: python cpy-dir-rec.py -s <souredir> -d <target directories> [-e <files to exclude>]"
74 elif arg[0] == "-":
75 print "cpy-dir-rec: unknown argument %s" % arg
76 sys.exit(1)
77 else:
78 if state == st_source:
79 sourcedir = arg
80 elif state == st_dest:
81 destdirs.append(arg)
82 elif state == st_exclude:
83 ignore.append(arg)
85 for destdir in destdirs:
86 print "Copying directory '%s' to '%s', ignore '%s'" % (sourcedir, destdir, ignore)
87 copy_tree(sourcedir, destdir, ignore)