Prepare setuptools for MySQL support

This commit is contained in:
Klaus-Uwe Mitterer 2016-05-30 21:58:53 +02:00
parent 6a87b5c36a
commit 70d9cd4592

View file

@ -2,19 +2,53 @@ import configparser, csv, datetime, html.parser, itertools, os, sqlite3, sys, tw
class SetupException(Exception):
def __str__(self):
return "Seems like config.cfg has not been created yet. Run setup.py to do so."
return "Seems like config.cfg has not been created yet or contains serious errors. Run setup.py to create it."
def getSetting(section, setting):
def getSetting(section, setting, path = "config.cfg"):
config = configparser.RawConfigParser()
config.read('config.cfg')
config.read(path)
return config.get(section, setting)
def dbtype():
try:
return getSetting("Database", "type")
except:
return 0 # for SQLite3
### Must only be called AFTER dbtype()! ###
def dbhost():
try:
return getSetting("Database", "host")
except:
raise SetupException()
def dbuser():
try:
return getSetting("Database", "user")
except:
raise SetupException()
def dbpass():
try:
return getSetting("Database", "pass")
except:
raise SetupException()
def dbname():
try:
return getSetting("Database", "name")
except:
raise SetupException()
def dbpath():
try:
return getSetting("Database", "path")
except:
return "Database.db"
return SetupException()
###
def cke():
try: