Alpha 2, diff muss umgeschrieben werden, damit er Kommentare ignoriert
This commit is contained in:
parent
4f082dfce9
commit
31fd2d2c06
4
Tools.py
4
Tools.py
@ -76,7 +76,7 @@ def getConfig(filename):
|
|||||||
|
|
||||||
def diff(destfile, tempfile, commentstring, debug):
|
def diff(destfile, tempfile, commentstring, debug):
|
||||||
"""diff destfile and tempfile, returns True if files differ, False if they are the same"""
|
"""diff destfile and tempfile, returns True if files differ, False if they are the same"""
|
||||||
# FIXME: filter out comments?
|
# FIXME: filter out comments, SVN-Header and STAMP are causing diff errors
|
||||||
debug.debug("Diffing %s and %s" % (destfile, tempfile))
|
debug.debug("Diffing %s and %s" % (destfile, tempfile))
|
||||||
if not os.path.isfile(destfile):
|
if not os.path.isfile(destfile):
|
||||||
debug.debug("Destfile %s does not exist, returning True." % destfile)
|
debug.debug("Destfile %s does not exist, returning True." % destfile)
|
||||||
@ -137,7 +137,7 @@ def copyFile(sourcefile, destfile, debug):
|
|||||||
|
|
||||||
if os.path.isfile(sourcefile):
|
if os.path.isfile(sourcefile):
|
||||||
# sourcefile exists
|
# sourcefile exists
|
||||||
if os.access(destfile, os.W_OK):
|
if not os.path.isfile(destfile) or os.access(destfile, os.W_OK):
|
||||||
debug.debug("Copying %s to %s" % (sourcefile, destfile))
|
debug.debug("Copying %s to %s" % (sourcefile, destfile))
|
||||||
shutil.copy(sourcefile, destfile)
|
shutil.copy(sourcefile, destfile)
|
||||||
return True
|
return True
|
||||||
|
@ -16,6 +16,8 @@ import os
|
|||||||
import tempfile
|
import tempfile
|
||||||
import re
|
import re
|
||||||
import getopt
|
import getopt
|
||||||
|
import time
|
||||||
|
|
||||||
#
|
#
|
||||||
import cfgfile
|
import cfgfile
|
||||||
from checks import checks
|
from checks import checks
|
||||||
@ -65,14 +67,14 @@ def workdir(directory):
|
|||||||
# 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 ({},{})
|
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 ({},{})
|
return ({},None)
|
||||||
# if not dirConfig
|
# if not dirConfig
|
||||||
|
|
||||||
destdir = dirConfig.get("Main","DEST")
|
destdir = dirConfig.get("Main","DEST")
|
||||||
@ -112,19 +114,24 @@ def workdir(directory):
|
|||||||
return (destfiles, dirConfig)
|
return (destfiles, dirConfig)
|
||||||
# def work
|
# def work
|
||||||
|
|
||||||
def buildFile(classfiles, destfile):
|
def buildFile(classfiles, destfile, commentstring):
|
||||||
"""open all classfiles, assemble them and write the contents into a tempfile
|
"""open all classfiles, assemble them and write the contents into a tempfile
|
||||||
returns the name of tempfile"""
|
returns the name of tempfile"""
|
||||||
content = []
|
content = []
|
||||||
|
if commentstring != "":
|
||||||
|
content.append(commentstring + " " + cfg.get("Main","STAMP") + " " + time.strftime("%+") + "\n")
|
||||||
|
# if commentstring not empty
|
||||||
|
|
||||||
for f in classfiles:
|
for f in classfiles:
|
||||||
fp = open(f, "r")
|
fp = open(f, "r")
|
||||||
filecontent = fp.read()
|
filecontent = fp.read()
|
||||||
fp.close()
|
fp.close()
|
||||||
|
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 match
|
# if search
|
||||||
|
# if commentstring empty
|
||||||
content.append(filecontent)
|
content.append(filecontent)
|
||||||
# end f
|
# end f
|
||||||
|
|
||||||
@ -150,18 +157,22 @@ def buildFile(classfiles, destfile):
|
|||||||
|
|
||||||
def processAllFiles(destfiles, dirConfig):
|
def processAllFiles(destfiles, dirConfig):
|
||||||
"""processes all files in destfiles, generate files from classes, compare and copy if necessary"""
|
"""processes all files in destfiles, generate files from classes, compare and copy if necessary"""
|
||||||
|
debug.debug("processAllFiles, dirConfig: %s" % (str(dirConfig.getitems("Main"))))
|
||||||
|
|
||||||
for df in destfiles.keys():
|
for df in destfiles.keys():
|
||||||
# assemble file to tmp
|
# assemble file to tmp
|
||||||
tempfilename = buildFile(destfiles[df], df)
|
commentstring = ""
|
||||||
|
if dirConfig.check("Main", "commentstring"):
|
||||||
|
commentstring = dirConfig.get("Main", "commentstring")
|
||||||
|
debug.debug("Found commentstring %s in %s" % (commentstring, df))
|
||||||
|
# if COMMENTSTRNIG
|
||||||
|
|
||||||
|
tempfilename = buildFile(destfiles[df], df, commentstring)
|
||||||
if not tempfilename:
|
if not tempfilename:
|
||||||
debug.debug("Error while creating temp file for %s, skipping." % df)
|
debug.debug("Error while creating temp file for %s, skipping." % df)
|
||||||
continue
|
continue
|
||||||
# if not tempfilename
|
# if not tempfilename
|
||||||
|
|
||||||
commentstring = ""
|
|
||||||
if dirConfig.check("Main", "COMMENSTRING"):
|
|
||||||
commentstring = dirConfig.get("Main", "COMMENTSTRING")
|
|
||||||
# if COMMENTSTRNIG
|
|
||||||
|
|
||||||
# diff assembled file and config file
|
# diff assembled file and config file
|
||||||
if Tools.diff(df, tempfilename, commentstring, debug):
|
if Tools.diff(df, tempfilename, commentstring, debug):
|
||||||
@ -216,6 +227,7 @@ def main():
|
|||||||
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 = {}
|
||||||
name = configdir+d
|
name = configdir+d
|
||||||
if not os.path.isdir(name):
|
if not os.path.isdir(name):
|
||||||
continue
|
continue
|
||||||
@ -226,7 +238,12 @@ def main():
|
|||||||
else:
|
else:
|
||||||
debug.debug("main: %s" % name)
|
debug.debug("main: %s" % name)
|
||||||
(destfiles, dirConfig) = workdir(name)
|
(destfiles, dirConfig) = workdir(name)
|
||||||
processAllFiles(destfiles, dirConfig)
|
if isinstance(destfiles, dict):
|
||||||
|
if len(destfiles.keys()) > 0:
|
||||||
|
processAllFiles(destfiles, dirConfig)
|
||||||
|
# if > 0
|
||||||
|
else:
|
||||||
|
debug.debug("No destfiles for %s, skipping." % d)
|
||||||
# if
|
# if
|
||||||
# for d
|
# for d
|
||||||
# def main
|
# def main
|
||||||
|
Loading…
Reference in New Issue
Block a user