/[shmookey]/portconf/Installer.py


UCC Code Repository

Contents of /portconf/Installer.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 116 - (hide annotations) (download) (as text)
Thu May 29 09:02:14 2008 UTC (13 years, 6 months ago) by shmookey
File MIME type: text/x-python
File size: 2999 byte(s)
sessioning at an application level now works, just need to add it to the web interface through cookies

1 shmookey 65 ''' Installer.py - installation tools for PACT.
2     '''
3    
4 shmookey 115 import pgdb
5 shmookey 80 import sys, os, pickle
6 shmookey 102 import commands
7 shmookey 65
8     class DBHostNotFound (Exception): pass
9     class DBNameNotFound (Exception): pass
10     class DBLoginFailed (Exception): pass
11     class NeedDBName (Exception): pass
12     class NeedDBUser (Exception): pass
13     class NeedDBPass (Exception): pass
14 shmookey 81 class InvalidDatabaseSettings (Exception): pass
15     class DatabaseError (Exception): pass
16 shmookey 65
17     def GetConf ():
18     try:
19     confile = open ("conf.pkl", "rb+")
20     conf = pickle.load (confile)
21     confile.close ()
22     except IOError:
23     conf = {}
24     except EOFError:
25     conf = {}
26     return conf
27    
28     def SaveConf (conf):
29     confile = open ("conf.pkl", "wb+")
30     pickle.dump (conf, confile)
31     confile.close ()
32    
33     def Set (name, value):
34     conf = GetConf ()
35     conf [name] = value
36     SaveConf (conf)
37 shmookey 101 if not name == "dbpass":
38     return conf[name]
39     else: return "******"
40 shmookey 65
41     def Get (name):
42     conf = GetConf ()
43     return conf [name]
44    
45     # Fill unfilled values with defaults if available, otherwise raise an exception.
46     # Then do the installation.
47     def Test ():
48     conf = GetConf ()
49     if not conf.has_key ("pyciscopath"):
50 shmookey 86 conf ["pyciscopath"] = os.path.abspath (os.path.dirname (sys.argv[0]) + "/pycisco/")
51 shmookey 65 if not conf.has_key ("pyaaapath"):
52 shmookey 86 conf ["pyaaapath"] = os.path.abspath (os.path.dirname (sys.argv[0]) + "/pyaaa/")
53 shmookey 65 if not conf.has_key ("dbhost"):
54     conf ["dbhost"] = "localhost"
55     if not conf.has_key ("dbport"):
56     conf ["dbport"] = "5432"
57 shmookey 106 if not conf.has_key ("dbpref"):
58     conf ["dbpref"] = "pact"
59 shmookey 65 if not conf.has_key ("dbname"):
60     raise NeedDBName ()
61     if not conf.has_key ("dbuser"):
62     raise NeedDBUser ()
63     if not conf.has_key ("dbpass"):
64     raise NeedDBPass ()
65     SaveConf (conf)
66    
67 shmookey 81 def Install ():
68     Test ()
69     conf = GetConf ()
70     try:
71     db = pgdb.connect (host = conf["dbhost"] + ":" + conf["dbport"], user = conf["dbuser"], password = conf["dbpass"], database = conf["dbname"])
72 shmookey 116 except pgdb.InternalError:
73 shmookey 81 raise InvalidDatabaseSettings ()
74     cur = db.cursor ()
75     sqlfile = open ("sql/postgre.sql", 'r')
76     try:
77 shmookey 106 for command in ''.join (sqlfile.readlines ()).split ("#"): cur.execute (command.replace ("TABLEPREFIX", conf["dbpref"]))
78 shmookey 81 db.commit ()
79 shmookey 116 except pgdb.DatabaseError:
80 shmookey 81 raise DatabaseError ()
81     return True
82 shmookey 102
83     def Uninstall ():
84     Test ()
85     conf = GetConf ()
86     try:
87     db = pgdb.connect (host = conf["dbhost"] + ":" + conf["dbport"], user = conf["dbuser"], password = conf["dbpass"], database = conf["dbname"])
88 shmookey 106 pref = conf["dbpref"]
89 shmookey 116 except pgdb.InternalError:
90 shmookey 102 raise InvalidDatabaseSettings ()
91     cur = db.cursor ()
92     sqlfile = open ("sql/postgre.sql", 'r')
93     try:
94 shmookey 106 cur.execute ("DROP TABLE %s_users" % pref)
95     cur.execute ("DROP TABLE %s_permissions" % pref)
96     cur.execute ("DROP TABLE %s_memberships" % pref)
97     cur.execute ("DROP TABLE %s_groups" % pref)
98     cur.execute ("DROP TABLE %s_sessions" % pref)
99     cur.execute ("DROP TABLE %s_parameters" % pref)
100     cur.execute ("DROP TABLE %s_NetworkDevice" % pref)
101 shmookey 102 db.commit ()
102 shmookey 116 except pgdb.DatabaseError:
103 shmookey 102 raise DatabaseError ()
104     commands.getoutput ("rm conf.pkl")
105     return True

Managed by UCC Webmasters ViewVC Help
Powered by ViewVC 1.1.26