From: genone Date: Wed, 8 Dec 2004 10:13:33 +0000 (-0000) Subject: change the outfile parameter for Glsa.dump() from filename to filehandle X-Git-Tag: gentoolkit-0.2.4.3~328 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=2f296d8ba4086481933cdf88f12fd7a159f11499;p=gentoolkit.git change the outfile parameter for Glsa.dump() from filename to filehandle svn path=/; revision=178 --- diff --git a/trunk/ChangeLog b/trunk/ChangeLog index 644b4cc..253b743 100644 --- a/trunk/ChangeLog +++ b/trunk/ChangeLog @@ -1,7 +1,9 @@ 2004-12-08 Marius Mauch * 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 * branched v0-3-0: major rework in equery is in progess. the main branch is reserved for minor and incremental fixups. diff --git a/trunk/src/glsa-check/glsa.py b/trunk/src/glsa-check/glsa.py index c142088..feef19f 100644 --- a/trunk/src/glsa-check/glsa.py +++ b/trunk/src/glsa-check/glsa.py @@ -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): """