#! /usr/bin/python2 #Helper program that generates gen_is.xml thats custom to linhes. #Contents of gen_is.xml are read from /etc/gen_is_xml.d #This script should be run everytime a is.xml entry is added or removed import os, sys import glob def read_snippets(dir_name): conf_snippets="" try: os.chdir(dir_name) except: print " gen_light_conf: Couldn't change dir to %s" %dir_name print " Exiting" sys.exit(0) file_list=glob.glob("*.conf") for conf_file in file_list: try: print " gen_light_conf: reading in %s" %conf_file f=open(conf_file,'r') lines=f.readlines() f.close() except: print " gen_light_conf: Couldn't open %s for reading" %conf_file print " Exiting" sys.exit(1) for line in lines: conf_snippets+=line if len(file_list) == 0: print " gen_light_conf: no conf files found" conf_snippets="" return conf_snippets def write_conf(conf,filename): try: f=open(filename, 'w') except: print " gen_light_conf: Couldn't open %s" %(filename) print " Exiting" sys.exit(2) f.write(conf) f.close() def main(): filename="/etc/lighttpd/conf.include" light_conf_dir="/etc/gen_light_conf.d/" conf_snippets=read_snippets(light_conf_dir) write_conf(conf_snippets,filename) if __name__ == "__main__": main()