
UCC Code Repository
Parent Directory
|
Revision Log
sessioning at an application level now works, just need to add it to the web interface through cookies
''' Installer.py - installation tools for PACT. ''' import pgdb import sys, os, pickle import commands class DBHostNotFound (Exception): pass class DBNameNotFound (Exception): pass class DBLoginFailed (Exception): pass class NeedDBName (Exception): pass class NeedDBUser (Exception): pass class NeedDBPass (Exception): pass class InvalidDatabaseSettings (Exception): pass class DatabaseError (Exception): pass def GetConf (): try: confile = open ("conf.pkl", "rb+") conf = pickle.load (confile) confile.close () except IOError: conf = {} except EOFError: conf = {} return conf def SaveConf (conf): confile = open ("conf.pkl", "wb+") pickle.dump (conf, confile) confile.close () def Set (name, value): conf = GetConf () conf [name] = value SaveConf (conf) if not name == "dbpass": return conf[name] else: return "******" def Get (name): conf = GetConf () return conf [name] # Fill unfilled values with defaults if available, otherwise raise an exception. # Then do the installation. def Test (): conf = GetConf () if not conf.has_key ("pyciscopath"): conf ["pyciscopath"] = os.path.abspath (os.path.dirname (sys.argv[0]) + "/pycisco/") if not conf.has_key ("pyaaapath"): conf ["pyaaapath"] = os.path.abspath (os.path.dirname (sys.argv[0]) + "/pyaaa/") if not conf.has_key ("dbhost"): conf ["dbhost"] = "localhost" if not conf.has_key ("dbport"): conf ["dbport"] = "5432" if not conf.has_key ("dbpref"): conf ["dbpref"] = "pact" if not conf.has_key ("dbname"): raise NeedDBName () if not conf.has_key ("dbuser"): raise NeedDBUser () if not conf.has_key ("dbpass"): raise NeedDBPass () SaveConf (conf) def Install (): Test () conf = GetConf () try: db = pgdb.connect (host = conf["dbhost"] + ":" + conf["dbport"], user = conf["dbuser"], password = conf["dbpass"], database = conf["dbname"]) except pgdb.InternalError: raise InvalidDatabaseSettings () cur = db.cursor () sqlfile = open ("sql/postgre.sql", 'r') try: for command in ''.join (sqlfile.readlines ()).split ("#"): cur.execute (command.replace ("TABLEPREFIX", conf["dbpref"])) db.commit () except pgdb.DatabaseError: raise DatabaseError () return True def Uninstall (): Test () conf = GetConf () try: db = pgdb.connect (host = conf["dbhost"] + ":" + conf["dbport"], user = conf["dbuser"], password = conf["dbpass"], database = conf["dbname"]) pref = conf["dbpref"] except pgdb.InternalError: raise InvalidDatabaseSettings () cur = db.cursor () sqlfile = open ("sql/postgre.sql", 'r') try: cur.execute ("DROP TABLE %s_users" % pref) cur.execute ("DROP TABLE %s_permissions" % pref) cur.execute ("DROP TABLE %s_memberships" % pref) cur.execute ("DROP TABLE %s_groups" % pref) cur.execute ("DROP TABLE %s_sessions" % pref) cur.execute ("DROP TABLE %s_parameters" % pref) cur.execute ("DROP TABLE %s_NetworkDevice" % pref) db.commit () except pgdb.DatabaseError: raise DatabaseError () commands.getoutput ("rm conf.pkl") return True
| UCC Webmasters | ViewVC Help |
| Powered by ViewVC 1.0.5 |