chiark / gitweb /
make-secnet-sites: OpBase.write_out: Tolerate sitesfile is None
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Wed, 4 Dec 2019 16:42:46 +0000 (16:42 +0000)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Sat, 15 Feb 2020 21:56:53 +0000 (21:56 +0000)
This will let us write to stdout.  The only user right now is OpUserv
which always sets sitesfile so no functional change yet.

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

index 5221051..f9c249b 100755 (executable)
@@ -299,7 +299,10 @@ class OpBase():
                else:
                        self.inputlines = pfilepath(self.inputfile)
        def write_out(self):
-               f=open(self.sitesfile+"-tmp",'w')
+               if self.sitesfile is None:
+                       f=sys.stdout
+               else:
+                       f=open(self.sitesfile+"-tmp",'w')
                f.write("# sites file autogenerated by make-secnet-sites\n")
                f.write("# generated %s, invoked by %s\n"%
                        (time.asctime(time.localtime(time.time())),
@@ -308,8 +311,9 @@ class OpBase():
                f.write("# valid /etc/secnet/sites.conf file\n\n")
                self.write_out_contents(f)
                f.write("# end of sites file\n")
-               f.close()
-               os.rename(self.sitesfile+"-tmp",self.sitesfile)
+               if self.sitesfile is not None:
+                       f.close()
+                       os.rename(self.sitesfile+"-tmp",self.sitesfile)
 
 class OpConf(OpBase):
        opts = ['--conf']