Spelling fixes.
[lilypond.git] / stepmake / bin / install.py
blob9818543a3f15022d74c0d1d0638e77b3af8cace8
1 #!@PYTHON@
2 import string
3 import getopt
4 import sys
5 import os
6 import shutil
7 (opts, args) = getopt.getopt (sys.argv[1:], 'b:cdg:m:o:st:', [])
8 transform_base = None
9 group = None
10 owner = None
11 transform = None
12 mode = None
13 copy = False
14 create_dir = False
16 for (o,a) in opts:
17 if o == '-b':
18 transform_base = a
19 elif o == '-c':
20 copy = True
21 elif o == '-d':
22 create_dir = True
23 elif o == '-g':
24 group = a
25 elif o == '-m':
26 mode = string.atoi (a, 8)
27 elif o == '-o':
28 owner = a
29 elif o == '-s':
30 strip = True
31 elif o == '-t':
32 transform = a
33 elif o == '-h':
34 print ''' Usage: $0 [OPTION]... SRCFILE DSTFILE
35 or: $0 [OPTION]... SRCFILES... DIRECTORY
36 or: $0 -d DIRECTORIES...
38 In the first form, install SRCFILE to DSTFILE, removing SRCFILE by default.
39 In the second, create the directory path DIR.
41 Options:
42 -b=TRANSFORMBASENAME
43 -c copy source (using $cpprog) instead of moving (using $mvprog).
44 -d create directories instead of installing files.
45 -g GROUP $chgrp installed files to GROUP.
46 -m MODE $chmod installed files to MODE.
47 -o USER $chown installed files to USER.
48 -s strip installed files (using $stripprog).
49 -t=TRANSFORM
50 --help display this help and exit.
51 --version display version info and exit.'''
52 sys.exit (0)
54 if not mode:
55 if create_dir:
56 mode = 0755
57 else:
58 mode = 0644
61 chown_me = []
63 dest = None
64 if not create_dir:
65 dest = args.pop()
67 for f in args:
68 if create_dir:
69 if os.path.isdir (f):
70 continue
72 os.makedirs (f, mode=mode)
73 chown_me.append (f)
74 else:
75 if copy:
76 if os.path.exists (dest) and not os.path.isdir (dest):
77 os.remove (dest)
78 shutil.copy2 (f, dest)
79 else:
80 shutil.move (f, dest)
82 if os.path.isdir (dest):
83 chown_me.append (os.path.join (dest, os.path.basename (f)))
84 else:
85 chown_me.append (dest)
87 for f in chown_me:
88 os.chmod (f, mode)
89 if group <> None or owner <> None:
90 os.chown (f, group, owner)