change the outfile parameter for Glsa.dump() from filename to filehandle
authorgenone <genone@gentoo.org>
Wed, 8 Dec 2004 10:13:33 +0000 (10:13 -0000)
committergenone <genone@gentoo.org>
Wed, 8 Dec 2004 10:13:33 +0000 (10:13 -0000)
svn path=/; revision=178

trunk/ChangeLog
trunk/src/glsa-check/glsa.py

index 644b4cc8e44a9607b7da4119e4e0bc57dd248f79..253b7439582819edd9d8d0ebce9e6255d65f5d7b 100644 (file)
@@ -1,7 +1,9 @@
 2004-12-08 Marius Mauch <genone@gentoo.org>
        * equery: implemented the --category option
        * glsa-check: fixed the bug where it wanted to unnecessary merge masked packages
-       
+       * glsa.py: changed the outfile parameter in Glsa.dump() to outstream so we don't
+                  have to open/close a file which breaks pipes
+
 2004-11-29 Karl Trygve Kalleberg <karltk@gentoo.org>
        * branched v0-3-0: major rework in equery is in progess. the main
        branch is reserved for minor and incremental fixups.
index c1420880b1237e01eca7cfd1206732356b6a9337..feef19fcecc728c7d291c695da5dfcb761b1da07 100644 (file)
@@ -494,61 +494,57 @@ class Glsa:
                self.services = self.affected.getElementsByTagName("service")
                return None
 
-       def dump(self, outfile="/dev/stdout", encoding="latin1"):
+       def dump(self, outstream=sys.stdout):
                """
                Dumps a plaintext representation of this GLSA to I{outfile} or 
                B{stdout} if it is ommitted. You can specify an alternate
                I{encoding} if needed (default is latin1).
                
-               @type   outfile: String
-               @param  outfile: Filename to dump the output in 
-                                                (defaults to "/dev/stdout")
-               @type   encoding: The encoding that should be used when writing 
-                                                 to I{outfile}.
+               @type   outstream: File
+               @param  outfile: Stream that should be used for writing
+                                                (defaults to sys.stdout)
                """
-               myfile = codecs.open(outfile, "w", encoding)
                width = int(self.config["PRINTWIDTH"])
-               myfile.write(center("GLSA %s: \n%s" % (self.nr, self.title), width)+"\n")
-               myfile.write((width*"=")+"\n")
-               myfile.write(wrap(self.synopsis, width, caption="Synopsis:         ")+"\n")
-               myfile.write("Announced on:      %s\n" % self.announced)
-               myfile.write("Last revised on:   %s\n\n" % self.revised)
+               outstream.write(center("GLSA %s: \n%s" % (self.nr, self.title), width)+"\n")
+               outstream.write((width*"=")+"\n")
+               outstream.write(wrap(self.synopsis, width, caption="Synopsis:         ")+"\n")
+               outstream.write("Announced on:      %s\n" % self.announced)
+               outstream.write("Last revised on:   %s\n\n" % self.revised)
                if self.glsatype == "ebuild":
                        for k in self.packages.keys():
                                pkg = self.packages[k]
                                for path in pkg:
                                        vul_vers = string.join(path["vul_vers"])
                                        unaff_vers = string.join(path["unaff_vers"])
-                                       myfile.write("Affected package:  %s\n" % k)
-                                       myfile.write("Affected archs:    ")
+                                       outstream.write("Affected package:  %s\n" % k)
+                                       outstream.write("Affected archs:    ")
                                        if path["arch"] == "*":
-                                               myfile.write("All\n")
+                                               outstream.write("All\n")
                                        else:
-                                               myfile.write("%s\n" % path["arch"])
-                                       myfile.write("Vulnerable:        %s\n" % vul_vers)
-                                       myfile.write("Unaffected:        %s\n\n" % unaff_vers)
+                                               outstream.write("%s\n" % path["arch"])
+                                       outstream.write("Vulnerable:        %s\n" % vul_vers)
+                                       outstream.write("Unaffected:        %s\n\n" % unaff_vers)
                elif self.glsatype == "infrastructure":
                        pass
                if len(self.bugs) > 0:
-                       myfile.write("\nRelated bugs:      ")
+                       outstream.write("\nRelated bugs:      ")
                        for i in range(0, len(self.bugs)):
-                               myfile.write(self.bugs[i])
+                               outstream.write(self.bugs[i])
                                if i < len(self.bugs)-1:
-                                       myfile.write(", ")
+                                       outstream.write(", ")
                                else:
-                                       myfile.write("\n")                              
+                                       outstream.write("\n")                           
                if self.background:
-                       myfile.write("\n"+wrap(self.background, width, caption="Background:       "))
-               myfile.write("\n"+wrap(self.description, width, caption="Description:      "))
-               myfile.write("\n"+wrap(self.impact_text, width, caption="Impact:           "))
-               myfile.write("\n"+wrap(self.workaround, width, caption="Workaround:       "))
-               myfile.write("\n"+wrap(self.resolution, width, caption="Resolution:       "))
+                       outstream.write("\n"+wrap(self.background, width, caption="Background:       "))
+               outstream.write("\n"+wrap(self.description, width, caption="Description:      "))
+               outstream.write("\n"+wrap(self.impact_text, width, caption="Impact:           "))
+               outstream.write("\n"+wrap(self.workaround, width, caption="Workaround:       "))
+               outstream.write("\n"+wrap(self.resolution, width, caption="Resolution:       "))
                myreferences = ""
                for r in self.references:
                        myreferences += (r.replace(" ", SPACE_ESCAPE)+NEWLINE_ESCAPE+" ")
-               myfile.write("\n"+wrap(myreferences, width, caption="References:       "))
-               myfile.write("\n")
-               myfile.close()
+               outstream.write("\n"+wrap(myreferences, width, caption="References:       "))
+               outstream.write("\n")
        
        def isVulnerable(self):
                """