From: Ian Jackson Date: Wed, 16 Oct 2019 17:28:29 +0000 (+0100) Subject: make-secnet-sites: Move option parser to the front of the file X-Git-Tag: v0.5.0~38 X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=secnet.git;a=commitdiff_plain;h=80d3061d9fef13149a87be565803998735fb90ea make-secnet-sites: Move option parser to the front of the file 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 --- diff --git a/make-secnet-sites b/make-secnet-sites index 04ead35..5162b54 100755 --- a/make-secnet-sites +++ b/make-secnet-sites @@ -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