source: SH_SHM/trunk/setup/setup.py @ 331

Revision 331, 2.7 KB checked in by marcus, 12 years ago (diff)

r170 | walther | 2011-02-17 18:13:41 +0100 (Do, 17 Feb 2011) | 1 line

Working on installation procedure.

  • Property svn:eol-style set to native
  • Property svn:executable set to *
Line 
1#! /usr/bin/env python
2
3import os
4import sys
5
6default_location = "/usr/local/sh"
7downloads = {
8    "locsat": "ftp://ftp.szgrf.bgr.de/pub/software/locsat-linux.tar.gz",
9    "fk": "ftp://ftp.szgrf.bgr.de/pub/software/fk-linux.tar.gz"
10}
11
12def fetchinfo(**kwargs):
13    """
14    Fetch information about user etc.
15    """
16    dbg = kwargs["debug"]
17
18    home = os.getenv("HOME")
19    pwd = os.path.realpath(os.path.split(sys.argv[0])[0])
20    tmp = os.getenv("TEMP")
21    if not tmp:
22        tmp = pwd
23       
24    uid = os.getuid()
25    root = uid == 0
26    if root:
27        shcroot = default_location
28    else:
29        shcroot = os.path.join(home, "sh")
30
31    del kwargs
32    return locals()
33
34def banner():
35    print "="*78
36    print "  Setup program for Seismic Handler v0.1"
37    print "="*78
38    print "\n This piece of software will try to setup the included source code.\n"
39
40def download(target, pkg):
41    os.system("echo wget -P %s %s" % (target, downloads[pkg]))
42
43def setup(**kwargs):
44    """
45    Setup Seismic Handler from source.
46    """
47    banner()
48    dbg = kwargs["debug"]
49
50    data = fetchinfo(debug=dbg)
51    if dbg:
52        print data
53
54    if not data["root"]:
55        res = query("You have no administrative rights. "
56                    "Perform user installation [Yn]? ")
57        if res.lower() == "n":
58            abort()
59
60    while 1:
61        target = query("Installation directory [%s, q = exit]: " % data["shcroot"])
62        if target.lower() == "q":
63            abort()
64
65        if not target:
66            target = data["shcroot"]
67
68        if not os.path.exists(target):
69            try:
70                os.mkdir(target)
71            except Exception, e:
72                if dbg:
73                    print e
74                   
75                print "Cannot create target directory: %s" % target
76                continue
77
78        break
79
80    copy(os.path.join(data["pwd"], ".."), os.path.join(target, "sh"), dbg)
81    download(target, "locsat")
82    download(target, "fk")
83
84    install(target)
85
86def install(target):
87    os.system(os.path.join(target, "setup/SHM-install.csh %s" % target))
88
89def copy(src, trt, dbg=False):
90    if dbg:
91        os.system("echo cp -rvd %s %s" % (src, trt))
92    else:
93        os.system("cp -rd %s %s" % (src, trt))
94
95def abort(text=None):
96    if not text:
97        text = "Installation aborted by user."
98
99    quit(text)
100
101def query(text):
102    """
103    Query user.
104    """
105    return raw_input(text)
106
107if __name__ == "__main__":
108    from optparse import OptionParser
109    parser = OptionParser()
110    parser.add_option("--debug", dest="debug", action="store_true",
111                      help="Turn on debug option.", default=False)
112
113    (options, args) = parser.parse_args()
114
115    setup(**vars(options))
Note: See TracBrowser for help on using the repository browser.