Erste Alpha, ohne kopieren
This commit is contained in:
parent
9685491307
commit
d3f9de40a4
@ -36,7 +36,7 @@ class checks(object):
|
|||||||
|
|
||||||
def arch(self):
|
def arch(self):
|
||||||
"""docstring for arch"""
|
"""docstring for arch"""
|
||||||
return(800, "ARCH", platform.system())
|
return(800, "Arch", platform.system())
|
||||||
# def arch
|
# def arch
|
||||||
|
|
||||||
def hostname(self):
|
def hostname(self):
|
||||||
|
117
userconfig.py
117
userconfig.py
@ -13,21 +13,67 @@ Copyright (c) 2013 __MyCompanyName__. All rights reserved.
|
|||||||
|
|
||||||
import sys
|
import sys
|
||||||
import os
|
import os
|
||||||
|
import tempfile
|
||||||
from checks import checks
|
from checks import checks
|
||||||
|
|
||||||
classchecks = checks()
|
classchecks = checks()
|
||||||
|
|
||||||
configdir = "../"
|
configdir = "../"
|
||||||
|
|
||||||
hostclasses = classchecks.__classesForHost__()
|
hostclasses = classchecks.__classesForHost__()
|
||||||
|
verbose = 1
|
||||||
|
|
||||||
def work(directory):
|
def debug(out, level=0):
|
||||||
|
"""docstring for debug"""
|
||||||
|
if verbose:
|
||||||
|
if level > 0:
|
||||||
|
print "*"*level,out
|
||||||
|
else:
|
||||||
|
print out
|
||||||
|
# if verbose
|
||||||
|
# def debug
|
||||||
|
|
||||||
|
def getDEST(directory):
|
||||||
|
"""docstring for getDEST"""
|
||||||
|
f = open(directory+"/DEST")
|
||||||
|
destdir= f.read()[:-1]
|
||||||
|
if destdir == "$HOME":
|
||||||
|
destdir = os.environ['HOME']
|
||||||
|
# if $HOME
|
||||||
|
if not destdir.endswith("/"):
|
||||||
|
destdir += "/"
|
||||||
|
# if not /
|
||||||
|
return destdir
|
||||||
|
# def getDEST
|
||||||
|
|
||||||
|
def workconf(directory, destdir, depth=2):
|
||||||
|
"""docstring for workconf"""
|
||||||
|
dirs = os.listdir(directory)
|
||||||
|
ret = []
|
||||||
|
for d in dirs:
|
||||||
|
name = directory+"/"+d
|
||||||
|
if os.path.isdir(name):
|
||||||
|
# fixme: create name
|
||||||
|
workconf(name, destdir, depth+1)
|
||||||
|
# if dir
|
||||||
|
ret.append(name)
|
||||||
|
debug("workconf: found file %s" % name, depth)
|
||||||
|
# for d
|
||||||
|
return ret
|
||||||
|
# def workconf
|
||||||
|
|
||||||
|
def workdir(directory):
|
||||||
"""docstring for work"""
|
"""docstring for work"""
|
||||||
|
debug("===============================", 1)
|
||||||
|
|
||||||
if not os.path.isfile(directory+"/DEST"):
|
if not os.path.isfile(directory+"/DEST"):
|
||||||
|
debug("No DEST in %s, skipping." % directory, 1)
|
||||||
return
|
return
|
||||||
# if not DEST
|
# if not DEST
|
||||||
dirs = os.listdir(directory)
|
destdir = getDEST(directory)
|
||||||
dirs.remove("DEST")
|
# 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
|
||||||
|
# build the file
|
||||||
|
destfiles = {}
|
||||||
|
# Schritt 1: Dateien einlesen
|
||||||
for h in hostclasses:
|
for h in hostclasses:
|
||||||
if h[0] != "":
|
if h[0] != "":
|
||||||
classdir = directory+"/"+h[0]+"_"+h[1]
|
classdir = directory+"/"+h[0]+"_"+h[1]
|
||||||
@ -35,14 +81,65 @@ def work(directory):
|
|||||||
classdir = directory+"/"+h[1]
|
classdir = directory+"/"+h[1]
|
||||||
# if all
|
# if all
|
||||||
if os.path.isdir(classdir):
|
if os.path.isdir(classdir):
|
||||||
print "Directory",classdir,"exists."
|
debug("workdir: %s" % classdir, 1)
|
||||||
|
tempfiles = workconf(classdir, destdir)
|
||||||
|
# tempfiles is a list of files within one classdir
|
||||||
|
|
||||||
|
for f in tempfiles:
|
||||||
|
destname = destdir+os.path.basename(f) # destination filename
|
||||||
|
if not destfiles.has_key(destname):
|
||||||
|
destfiles[destname] = []
|
||||||
|
# if not destname, create key with empty list
|
||||||
|
destfiles[destname].append(f) # append each file to dict
|
||||||
|
# for tempfiles
|
||||||
# if classdir
|
# if classdir
|
||||||
# for hostclasses
|
# for hostclasses
|
||||||
return
|
debug("workdir: %s, Files: %s" % (directory, str(destfiles)))
|
||||||
|
debug("^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^", 1)
|
||||||
|
return destfiles
|
||||||
# def work
|
# def work
|
||||||
|
|
||||||
|
def buildFile(destfile, classfiles):
|
||||||
|
"""docstring for buildFile"""
|
||||||
|
content = []
|
||||||
|
for f in classfiles:
|
||||||
|
fp = open(f, "r")
|
||||||
|
content.append(fp.read())
|
||||||
|
fp.close()
|
||||||
|
# end f
|
||||||
|
|
||||||
|
(tempfd, tempfilename) = tempfile.mkstemp(prefix=os.path.basename(destfile), dir="/tmp")
|
||||||
|
|
||||||
|
fp = None
|
||||||
|
try:
|
||||||
|
fp = os.fdopen(tempfd, "w")
|
||||||
|
except:
|
||||||
|
print "Cannot write to temporary file",tempfilename
|
||||||
|
os.remove(tempfilename)
|
||||||
|
sys.exit(1)
|
||||||
|
# try
|
||||||
|
|
||||||
|
for block in content:
|
||||||
|
fp.write(block)
|
||||||
|
fp.write("\n")
|
||||||
|
# for content
|
||||||
|
fp.close()
|
||||||
|
# fixme: diff tempfilename destfile
|
||||||
|
# fixme: header marker for "is under userconfig control"
|
||||||
|
# fixme: if diff and not under userconfig control, backup destfile
|
||||||
|
# fixme: copy tempfilename to destfile
|
||||||
|
# fixme: remove tempfilename
|
||||||
|
# def buildFile
|
||||||
|
|
||||||
|
def buildAllFiles(destfiles):
|
||||||
|
"""docstring for buildFiles"""
|
||||||
|
for df in destfiles.keys():
|
||||||
|
buildFile(df, destfiles[df])
|
||||||
|
# for df
|
||||||
|
# def buildAllFiles
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
print "Classes for host:",hostclasses
|
debug("Classes for host: %s" % hostclasses)
|
||||||
for d in os.listdir(configdir):
|
for d in os.listdir(configdir):
|
||||||
name = configdir+d
|
name = configdir+d
|
||||||
if not os.path.isdir(name):
|
if not os.path.isdir(name):
|
||||||
@ -52,7 +149,9 @@ def main():
|
|||||||
elif os.path.isfile(name+"/.ignore"):
|
elif os.path.isfile(name+"/.ignore"):
|
||||||
continue
|
continue
|
||||||
else:
|
else:
|
||||||
work(name)
|
debug("main: %s" % name)
|
||||||
|
destfiles = workdir(name)
|
||||||
|
buildAllFiles(destfiles)
|
||||||
# if
|
# if
|
||||||
# for d
|
# for d
|
||||||
# def main
|
# def main
|
||||||
|
Loading…
Reference in New Issue
Block a user