--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/iro/install.py Sat Mar 10 19:03:02 2012 +0100
@@ -0,0 +1,60 @@
+from twisted.python import log
+from sqlalchemy import create_engine
+from sqlalchemy.exc import DatabaseError
+import os
+
+from config import configParser, confFiles, main
+from error import NeededOption
+from offer.provider import providers
+
+from model.schema import Base
+import config
+
+def checkConfig():
+ try:
+ l = configParser.read(confFiles)
+ if len(l) > 0:
+ return True
+ return False
+ except NeededOption as e:
+ log.msg("Error while processing config file: %s"%e)
+ return False
+
+def checkDatabase():
+ engine = create_engine(config.main.dburl)
+ for t in Base.metadata.sorted_tables:
+ if not t.exists(engine):
+ return False
+ return True
+
+def checkDatabaseConnection():
+ try:
+ engine = create_engine(config.main.dburl)
+ con = engine.connect()
+ con.close()
+ return True
+ except DatabaseError as e:
+ log.msg("Error while trying to connect to database\n%s"%e)
+ return False
+
+def createDatabase():
+ engine = create_engine(config.main.dburl)
+ Base.metadata.create_all(engine)
+
+def createSampleConfig():
+ if not os.path.exists("iro.conf"):
+ with open("iro.conf",'w') as fp:
+ fp.write("\n".join(main.sampleConf()))
+ fp.write("\n")
+ k = providers.keys()
+ k.sort()
+ for p in k:
+ fp.write("\n".join(providers[p](p).sampleConf()))
+ fp.write("\n")
+ else:
+ log.msg("iro.conf exists and will not be overwritten.")
+
+def check():
+ if checkConfig() and checkDatabaseConnection() and checkDatabase():
+ return True
+ return False