lower case in config file

This commit is contained in:
Marcus Stoegbauer 2013-01-13 21:32:33 +00:00
parent 748fef4403
commit ddb521d9cc
2 changed files with 17 additions and 16 deletions

View File

@ -67,19 +67,19 @@ def workdir(directory):
debug.debug("===============================", 1) debug.debug("===============================", 1)
# skip directory if no CONFIGFILE present # skip directory if no CONFIGFILE present
if not os.path.isfile(directory+"/"+cfg.get("Main", "CONFIGFILE")): if not os.path.isfile(directory+"/"+cfg.get("Main", "configfile")):
debug.debug("No %s in %s, skipping." % (cfg.get("Main", "CONFIGFILE"), directory), 1) debug.debug("No %s in %s, skipping." % (cfg.get("Main", "configfile"), directory), 1)
return ({},None) return ({},None)
# if not DEST # if not DEST
# get config file for directory # get config file for directory
dirConfig = Tools.getConfig(directory+"/"+cfg.get("Main", "CONFIGFILE")) dirConfig = Tools.getConfig(directory+"/"+cfg.get("Main", "configfile"))
if not dirConfig: if not dirConfig:
debug.debug("Cannot read %s in %s, skipping." % (cfg.get("Main", "CONFIGFILE"), directory), 1) debug.debug("Cannot read %s in %s, skipping." % (cfg.get("Main", "configfile"), directory), 1)
return ({},None) return ({},None)
# if not dirConfig # if not dirConfig
destdir = dirConfig.get("Main","DEST") destdir = dirConfig.get("Main","dest")
# destfiles is a dict of all files that will be created from the classes config # destfiles is a dict of all files that will be created from the classes config
# key is the destination filename, values are all classes filenames that are used to # key is the destination filename, values are all classes filenames that are used to
# build the file # build the file
@ -121,7 +121,7 @@ def buildFile(classfiles, destfile, commentstring):
returns the name of tempfile""" returns the name of tempfile"""
content = [] content = []
if commentstring != "": if commentstring != "":
content.append(commentstring + " " + cfg.get("Main","STAMP") + " " + time.strftime("%+") + "\n") content.append(commentstring + " " + cfg.get("Main","stamp") + " " + time.strftime("%+") + "\n")
# if commentstring not empty # if commentstring not empty
for f in classfiles: for f in classfiles:
@ -130,8 +130,8 @@ def buildFile(classfiles, destfile, commentstring):
fp.close() fp.close()
if commentstring == "": if commentstring == "":
# look for stamp in content, replace with real stamp # look for stamp in content, replace with real stamp
if re.search(re.escape(cfg.get("Main","STAMPREPLACE")), filecontent): if re.search(re.escape(cfg.get("Main","stampreplace")), filecontent):
filecontent = re.sub(re.escape(cfg.get("Main","STAMPREPLACE")), cfg.get("Main","STAMP"), filecontent) filecontent = re.sub(re.escape(cfg.get("Main","stampreplace")), cfg.get("Main","stamp"), filecontent)
# if search # if search
# if commentstring empty # if commentstring empty
content.append(filecontent) content.append(filecontent)
@ -227,7 +227,7 @@ def main():
cfg.setfilename(configfile) cfg.setfilename(configfile)
debug.debug("Classes for host: %s" % hostclasses) debug.debug("Classes for host: %s" % hostclasses)
configdir = cfg.get("Main", "CONFIGDIR") configdir = cfg.get("Main", "configdir")
for d in os.listdir(configdir): for d in os.listdir(configdir):
destfiles = {} destfiles = {}
name = configdir+d name = configdir+d

View File

@ -49,6 +49,7 @@ def error(out):
def getConfig(filename): def getConfig(filename):
"""reads filename as config, checks for DEST parameter and returns cfgfile object""" """reads filename as config, checks for DEST parameter and returns cfgfile object"""
ret = None
try: try:
ret = cfgfile.Conf(filename) ret = cfgfile.Conf(filename)
except: except:
@ -57,19 +58,19 @@ def getConfig(filename):
# try # try
# check for DEST parameter # check for DEST parameter
if not ret.check("Main", "DEST"): if not ret.check("Main", "dest"):
error("No DEST in config file %s" % filename) error("No DEST in config file %s" % filename)
return False return False
# if no DEST # if no DEST
# replace $HOME with real home directory # replace $HOME with real home directory
if ret.get("Main", "DEST") == "$HOME": if ret.get("Main", "dest") == "$HOME":
ret.set("Main", "DEST", os.environ['HOME']) ret.set("Main", "dest", os.environ['HOME'])
# if $HOME # if $HOME
# make sure DEST ends with / # make sure DEST ends with /
if not ret.get("Main", "DEST").endswith("/"): if not ret.get("Main", "dest").endswith("/"):
ret.set("Main", "DEST", ret.get("Main", "DEST")+"/") ret.set("Main", "dest", ret.get("Main", "dest")+"/")
# if not / # if not /
return ret return ret
@ -123,7 +124,7 @@ def userConfigGenerated(filename, cfg):
return False return False
# if not filename # if not filename
if not cfg.check("Main","STAMP"): if not cfg.check("Main","stamp"):
# no STAMP in userconfig.cfg, so no way to check if file was generated by userconfig # no STAMP in userconfig.cfg, so no way to check if file was generated by userconfig
return False return False
# no STAMP # no STAMP
@ -131,7 +132,7 @@ def userConfigGenerated(filename, cfg):
fp = open(filename, "r") fp = open(filename, "r")
for line in fp: for line in fp:
if re.search(re.escape(cfg.get("Main","STAMP")), line): if re.search(re.escape(cfg.get("Main","stamp")), line):
return True return True
# if search # if search
# for line # for line