File: install.py

package info (click to toggle)
polyorb 2.11~20140418-3
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 30,012 kB
  • ctags: 465
  • sloc: ada: 273,015; sh: 4,507; makefile: 4,265; python: 1,332; cpp: 1,213; java: 507; ansic: 274; xml: 30; perl: 23; exp: 6
file content (68 lines) | stat: -rwxr-xr-x 1,729 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#! /usr/bin/env python

import getopt, os, shutil, string, sys

def usage():
    print "Usage: install.py [-m MODE] SRCFILE... DSTDIR"
    sys.exit(2)

def main():
    dir = False
    mode = 0444
    strip = False
    verbose = False

    try:
        opts, args = getopt.getopt(sys.argv[1:], "dm:sv")
    except getopt.GetoptError, err:
        # print help information and exit:
        print str(err) # will print something like "option -a not recognized"
        usage()

    for o, a in opts:
        if o == "-d":
            dir = True
        elif o == "-m":
            mode = string.atoi(a, 8)
        elif o == "-s":
            strip = True
        elif o == "-v":
            verbose = True
        else:
            assert False, "unhandled option"

    if len(args) == 0:
        usage()

    if not dir:
        dst = args.pop()

    for file in args:
        if file == '-':
            args.extend(map(string.rstrip, sys.stdin.readlines()))

        elif dir:
            if not os.path.isdir(file):
                os.makedirs(file)

        else:
            if os.path.isdir(dst):
                dstfile = os.path.join(dst,os.path.basename(file))
            else:
                dstfile = dst

            if verbose:
                print "%s -> %s" % (file, dstfile)

            if os.path.exists(dstfile):
                # Before doing the unlink, ensure that we have write access to
                # the file (required on Windows).
                os.chmod(dstfile, 0600)
                os.unlink(dstfile)
            shutil.copy2(file, dstfile)
            os.chmod(dstfile, mode)
            if strip:
                os.spawn(os.P_WAIT, "strip", dstfile)

if __name__ == "__main__":
    main()