chiark / gitweb /
make-secnet-sites: Move option parser to the front of the file
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Wed, 16 Oct 2019 17:28:29 +0000 (18:28 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Thu, 24 Oct 2019 18:16:16 +0000 (19:16 +0100)
This means that we will be able to use information from the option
parser when creating our classes etc.  This will be useful as we are
going to support multiple output file versions etc.

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

index 04ead35dd955aae5ad33453ffadc352a67557e5a..5162b54e18b8dee1cb0a6421e9d2c68c112ec219 100755 (executable)
@@ -66,6 +66,51 @@ import ipaddrset
 
 VERSION="0.1.18"
 
+# Are we being invoked from userv?
+service=0
+# If we are, which group does the caller want to modify?
+group=None
+
+if len(sys.argv)<2:
+       inputfile=None
+       of=sys.stdout
+else:
+       if sys.argv[1]=='-u':
+               if len(sys.argv)!=6:
+                       print "Wrong number of arguments"
+                       sys.exit(1)
+               service=1
+               header=sys.argv[2]
+               groupfiledir=sys.argv[3]
+               sitesfile=sys.argv[4]
+               group=sys.argv[5]
+               if not os.environ.has_key("USERV_USER"):
+                       print "Environment variable USERV_USER not found"
+                       sys.exit(1)
+               user=os.environ["USERV_USER"]
+               # Check that group is in USERV_GROUP
+               if not os.environ.has_key("USERV_GROUP"):
+                       print "Environment variable USERV_GROUP not found"
+                       sys.exit(1)
+               ugs=os.environ["USERV_GROUP"]
+               ok=0
+               for i in string.split(ugs):
+                       if group==i: ok=1
+               if not ok:
+                       print "caller not in group %s"%group
+                       sys.exit(1)
+       else:
+               if sys.argv[1]=='-P':
+                       prefix=sys.argv[2]
+                       sys.argv[1:3]=[]
+               if len(sys.argv)>3:
+                       print "Too many arguments"
+                       sys.exit(1)
+               inputfile=sys.argv[1]
+               of=sys.stdout
+               if len(sys.argv)>2:
+                       of=open(sys.argv[2],'w')
+
 # Classes describing possible datatypes in the configuration file
 
 class basetype:
@@ -452,55 +497,10 @@ def outputsites(w):
                map(lambda x:"%svpn/%s/all-sites"%(prefix,x),
                        root.children.keys()),","))
 
-# Are we being invoked from userv?
-service=0
-# If we are, which group does the caller want to modify?
-group=None
-
 line=0
 file=None
 complaints=0
 
-if len(sys.argv)<2:
-       inputfile=None
-       of=sys.stdout
-else:
-       if sys.argv[1]=='-u':
-               if len(sys.argv)!=6:
-                       print "Wrong number of arguments"
-                       sys.exit(1)
-               service=1
-               header=sys.argv[2]
-               groupfiledir=sys.argv[3]
-               sitesfile=sys.argv[4]
-               group=sys.argv[5]
-               if not os.environ.has_key("USERV_USER"):
-                       print "Environment variable USERV_USER not found"
-                       sys.exit(1)
-               user=os.environ["USERV_USER"]
-               # Check that group is in USERV_GROUP
-               if not os.environ.has_key("USERV_GROUP"):
-                       print "Environment variable USERV_GROUP not found"
-                       sys.exit(1)
-               ugs=os.environ["USERV_GROUP"]
-               ok=0
-               for i in string.split(ugs):
-                       if group==i: ok=1
-               if not ok:
-                       print "caller not in group %s"%group
-                       sys.exit(1)
-       else:
-               if sys.argv[1]=='-P':
-                       prefix=sys.argv[2]
-                       sys.argv[1:3]=[]
-               if len(sys.argv)>3:
-                       print "Too many arguments"
-                       sys.exit(1)
-               inputfile=sys.argv[1]
-               of=sys.stdout
-               if len(sys.argv)>2:
-                       of=open(sys.argv[2],'w')
-
 # Sanity check section
 # Delete nodes where leaf=0 that have no children