cas | 17 ++++++++---------
cas-admin | 34 ++++++++++++++++------------------
cas.conf | 2 +-
3 files changed, 25 insertions(+), 28 deletions(-)
New commits:
commit 62c37e64f4049c0fbf0d88ebc5bdfc785edcbede
Author: adam stokes <uzr(a)jak.rebo>
Date: Mon Sep 28 13:34:37 2009 -0400
- rework config items to be in a dict
allows for easy addition of configuration items
diff --git a/cas b/cas
index 87519aa..9423bd7 100755
--- a/cas
+++ b/cas
@@ -42,11 +42,10 @@ if sys.version_info[:2] < (2,3):
# into a key,value pair automatically
config = ConfigParser.ConfigParser()
config.read("/etc/cas.conf")
-WORKDIRECTORY = config.get("settings","workDirectory")
-DEBUGLEVEL = config.get("settings","debugLevel")
-SMTPHOST = config.get("settings", "mailServer")
-# Read database parameters
-DATABASE = config.get("settings", "database")
+settings = {}
+if config.has_section("settings"):
+ for opt, val in config.items("settings"):
+ settings[opt.upper()] = val
# Check for some advanced configurations
# Test to see if we provide a 32bit crash binary
@@ -134,7 +133,7 @@ class TimestampHandler(object):
class CasApplication(object):
def __init__(self, args):
- self.db = CasStorage(DATABASE)
+ self.db = CasStorage(settings["DATABASE"])
self.db.connect()
self.parse_options(args)
self.util = UtilBase()
@@ -173,7 +172,7 @@ class CasApplication(object):
# build logger object to deal with logging per job and keep things
# clean and easy to debug
- self.casLog = Logging(self.storagePath, self.identifier, DEBUGLEVEL)
+ self.casLog = Logging(self.storagePath, self.identifier,
settings["DEBUGLEVEL"])
# Add job to database, this allows us to purge
# data based on job date creation then by other
@@ -321,7 +320,7 @@ class CasApplication(object):
if os.path.isfile(crashOutFile) and self.email:
self.casLog.info("Crash output processed, sending email to %s" %
(self.email,))
try:
- mailServer = smtplib.SMTP(SMTPHOST)
+ mailServer = smtplib.SMTP(settings["SMTPHOST"])
try:
# Compose email msg of results
msg = "Subject: CAS results for %s\r\n\n" %
(self.identifier,)
@@ -346,7 +345,7 @@ class CasApplication(object):
if __name__=="__main__":
# Before we start the database has to exist.
- if not os.path.isfile(DATABASE):
+ if not os.path.isfile(settings["DATABASE"]):
raise SystemExit("No Database exist, please run cas-admin --help for more
information.")
# Begin CAS
app = CasApplication(sys.argv[1:])
diff --git a/cas-admin b/cas-admin
index 728a6f5..2558f7b 100755
--- a/cas-admin
+++ b/cas-admin
@@ -36,12 +36,10 @@ if sys.version_info[:2] < (2,3):
# Read in configuration
config = ConfigParser.ConfigParser()
config.read("/etc/cas.conf")
-KERNELS = config.get("settings","kernels")
-RPMFILTER = config.get("settings","rpmFilter")
-DEBUGS = config.get("settings","debugs")
-DEBUGLEVEL = config.get("settings","debugLevel")
-DATABASE = config.get("settings","database")
-WORKDIRECTORY = config.get("settings","workDirectory")
+settings = {}
+if config.has_section("settings"):
+ for opt, val in config.items("settings"):
+ settings[opt.upper()] = val
# read maintenance options
PURGELIMIT = config.get("maintenance","purgeLimit")
@@ -53,9 +51,9 @@ class CasDatabaseHandler(object):
self.util = UtilBase()
# setup database connection
self.first_run = False
- if not os.path.isfile(DATABASE):
+ if not os.path.isfile(settings["DATABASE"]):
self.first_run = True
- self.db = CasStorage(DATABASE)
+ self.db = CasStorage(settings["DATABASE"])
self.db.connect()
if self.first_run:
self.db.buildTable()
@@ -64,7 +62,7 @@ class CasDatabaseHandler(object):
# Uses emacs regex -- see `man find`
# TODO: rework kernel filtering to expand scope
# beyond just debuginfo rpms.
- cmd = ["find", "-L", KERNELS, "-iregex",
RPMFILTER]
+ cmd = ["find", "-L", settings["KERNELS"],
"-iregex", settings["RPMFILTER"]]
pipe = Popen(cmd, stdout=PIPE, stderr=PIPE)
# setup count for kernels found, mainly for console output
count = 0
@@ -77,7 +75,7 @@ class CasDatabaseHandler(object):
rpms = self.db.getAllDebuginfoRPM()
for id, rpm in rpms:
# temporary storage path in form of DEBUGS/COUNT
- dst = os.path.join(DEBUGS, str(count))
+ dst = os.path.join(settings["DEBUGS"], str(count))
if not os.path.isdir(dst):
os.makedirs(dst)
rpmTool = RPMBase()
@@ -103,9 +101,9 @@ class CasServerHandler(object):
self.util = UtilBase()
# setup database connection
self.first_run = False
- if not os.path.isfile(DATABASE):
+ if not os.path.isfile(settings["DATABASE"]):
self.first_run = True
- self.db = CasStorage(DATABASE)
+ self.db = CasStorage(settings["DATABASE"])
self.db.connect()
if self.first_run:
self.db.buildTable()
@@ -152,7 +150,7 @@ class PurgeHandler(object):
cutOffDate = self.todaysDate - datetime.timedelta(days=self.purgeDataDays)
self.casLog.debug(cutOffDate)
# Start of purging data
- for root, dirs, files in os.walk(WORKDIRECTORY):
+ for root, dirs, files in os.walk(settings["WORKDIRECTORY"]):
for d in dirs:
dirpath = os.path.join(root,d)
# pull out date from directory structure and trim it to
@@ -171,7 +169,7 @@ class PurgeHandler(object):
class CasAdminApplication(object):
def __init__(self, args):
self.parse_options(args)
- self.casLog = Logging("/var/log","cas-admin", DEBUGLEVEL)
+ self.casLog = Logging("/var/log","cas-admin",
settings["DEBUGLEVEL"])
def parse_options(self, args):
parser = optparse.OptionParser(usage="cas-admin [opts] args")
@@ -198,10 +196,10 @@ class CasAdminApplication(object):
"""
if os.getuid() is not 0:
raise RuntimeError, "You must be root(0), instead you are id(%d)" %
(os.getuid())
- if not os.path.isdir(os.path.dirname(DATABASE)):
- os.makedirs(os.path.dirname(DATABASE))
- if not os.path.isdir(DEBUGS):
- os.makedirs(DEBUGS)
+ if not os.path.isdir(os.path.dirname(settings["DATABASE"])):
+ os.makedirs(os.path.dirname(settings["DATABASE"]))
+ if not os.path.isdir(settings["DEBUGS"]):
+ os.makedirs(settings["DEBUGS"])
# if autopurge is enabled lets clean up some stale data
if AUTOPURGE:
diff --git a/cas.conf b/cas.conf
index 1928139..b3dcd8d 100644
--- a/cas.conf
+++ b/cas.conf
@@ -34,7 +34,7 @@ workDirectory=/cores
# Mail server, e.g.
mail.example.com
# Provides job results via email
-mailServer=mail.example.com
+stmphost=mail.example.com
# database connection info
database=/var/db/cas/cas.db