make-secnet-sites: new "include" keyword
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Thu, 15 Dec 2011 01:01:38 +0000 (01:01 +0000)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Fri, 16 Dec 2011 15:52:18 +0000 (15:52 +0000)
Allow "headers" files and "sites" files to contain "include"
directives.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
make-secnet-sites

index f102b1f..547f572 100755 (executable)
@@ -329,7 +329,7 @@ def set_property(obj,w):
        else:
                obj.properties[w[0]]=keywords[w[0]][0](w)
 
-def pline(i):
+def pline(i,allow_include=False):
        "Process a configuration file line"
        global allow_defs, obstack, root
        w=string.split(i)
@@ -340,6 +340,16 @@ def pline(i):
                allow_defs=sitelevel.depth
                obstack=[root]
                return
+       if keyword=='include':
+               if not allow_include:
+                       complain("include not permitted here")
+                       return
+               if len(w) != 2:
+                       complain("include requires one argument")
+                       return
+               newfile=os.path.join(os.path.dirname(file),w[1])
+               pfilepath(newfile,allow_include=allow_include)
+               return
        if levels.has_key(keyword):
                # We may go up any number of levels, but only down by one
                newdepth=levels[keyword].depth
@@ -379,12 +389,12 @@ def pline(i):
 
        complain("unknown keyword '%s'"%(keyword))
 
-def pfilepath(pathname):
+def pfilepath(pathname,allow_include=False):
        f=open(pathname)
-       pfile(pathname,f.readlines())
+       pfile(pathname,f.readlines(),allow_include=allow_include)
        f.close()
 
-def pfile(name,lines):
+def pfile(name,lines,allow_include=False):
        "Process a file"
        global file,line
        file=name
@@ -393,7 +403,7 @@ def pfile(name,lines):
                line=line+1
                if (i[0]=='#'): continue
                if (i[len(i)-1]=='\n'): i=i[:len(i)-1] # strip trailing LF
-               pline(i)
+               pline(i,allow_include=allow_include)
 
 def outputsites(w):
        "Output include file for secnet configuration"
@@ -455,14 +465,14 @@ else:
                if not ok:
                        print "caller not in group %s"%group
                        sys.exit(1)
-               pfilepath(header)
+               pfilepath(header,allow_include=True)
                userinput=sys.stdin.readlines()
                pfile("user input",userinput)
        else:
                if len(sys.argv)>3:
                        print "Too many arguments"
                        sys.exit(1)
-               pfilepath(sys.argv[1])
+               pfilepath(sys.argv[1],allow_include=True)
                of=sys.stdout
                if len(sys.argv)>2:
                        of=open(sys.argv[2],'w')