From 5764c32db099485eb69f6d683288235adb4937ba Mon Sep 17 00:00:00 2001 From: genone Date: Thu, 7 Oct 2004 00:06:47 +0000 Subject: Minor enhancements for glsa-check + major enhancements for glsa.py svn path=/; revision=146 --- trunk/src/glsa-check/glsa-check | 23 +++++--- trunk/src/glsa-check/glsa.py | 117 +++++++++++++++++++++++++--------------- 2 files changed, 90 insertions(+), 50 deletions(-) (limited to 'trunk/src') diff --git a/trunk/src/glsa-check/glsa-check b/trunk/src/glsa-check/glsa-check index f7a0954..4d682f0 100644 --- a/trunk/src/glsa-check/glsa-check +++ b/trunk/src/glsa-check/glsa-check @@ -20,9 +20,10 @@ optionmap = [ ["-p", "--pretend", "show the necessary commands to apply this GLSA"], ["-f", "--fix", "try to auto-apply this GLSA (experimental)"], ["-i", "--inject", "inject the given GLSA into the checkfile"], -["-n", "--nocolor", "disable colors"], +["-n", "--nocolor", "disable colors (option)"], ["-h", "--help", "show this help message"], -["-v", "--version", "some information about this tool"] +["-V", "--version", "some information about this tool"], +["-v", "--verbose", "print more messages (option)"], ] # print a warning as this is beta code @@ -45,13 +46,19 @@ try: if option in args: nocolor() args.remove(option) + + verbose = False + for option in ["--verbose", "-v"]: + if option in args: + verbose = True + args.remove(option) # sanity checking if len(args) <= 0: print "no option given: what should I do ?" mode="help" elif len(args) > 1: - print "please use only one option per call" + print "please use only one command per call" mode = "help" else: # in what mode are we ? @@ -59,6 +66,7 @@ try: for m in optionmap: if args in [o for o in m[:-1]]: mode = m[1][2:] + except GetoptError, e: print "unknown option given:", e mode = "help" @@ -139,7 +147,8 @@ if mode == "list": try: myglsa = Glsa(myid, glsaconfig) except GlsaTypeException, e: - #print "invalid GLSA: %s (error message was: %s)" % (myid, e) + if verbose: + print "invalid GLSA: %s (error message was: %s)" % (myid, e) continue if myglsa.isApplied(): status = "[A]" @@ -164,7 +173,8 @@ if mode in ["dump", "fix", "inject", "pretend"]: try: myglsa = Glsa(myid, glsaconfig) except GlsaTypeException, e: - #print "invalid GLSA: %s (error message was: %s)" % (myid, e) + if verbose: + print "invalid GLSA: %s (error message was: %s)" % (myid, e) continue if mode == "dump": myglsa.dump() @@ -210,7 +220,8 @@ if mode == "test": try: myglsa = Glsa(myid, glsaconfig) except GlsaTypeException, e: - #print "invalid GLSA: %s (error message was: %s)" % (myid, e) + if verbose: + print "invalid GLSA: %s (error message was: %s)" % (myid, e) continue if myglsa.isVulnerable(): outputlist.append(myglsa.nr) diff --git a/trunk/src/glsa-check/glsa.py b/trunk/src/glsa-check/glsa.py index 842725a..dc7fd8e 100644 --- a/trunk/src/glsa-check/glsa.py +++ b/trunk/src/glsa-check/glsa.py @@ -24,6 +24,7 @@ import portage opMapping = {"le": "<=", "lt": "<", "eq": "=", "gt": ">", "ge": ">=", "rge": ">=~", "rle": "<=~", "rgt": " >~", "rlt": " <~"} NEWLINE_ESCAPE = "!;\\n" # some random string to mark newlines that should be preserved +SPACE_ESCAPE = "!;_" # some random string to mark spaces that should be preserved def center(text, width): """ @@ -68,12 +69,17 @@ def wrap(text, width, caption=""): """ rValue = "" line = caption + text = text.replace(2*NEWLINE_ESCAPE, NEWLINE_ESCAPE+" "+NEWLINE_ESCAPE) words = text.split() indentLevel = len(caption)+1 + for w in words: - if len(line)+len(w)+1 > width: + if line[-1] == "\n": + rValue += line + line = " "*indentLevel + if len(line)+len(w.replace(NEWLINE_ESCAPE, ""))+1 > width: rValue += line+"\n" - line = " "*indentLevel+w + line = " "*indentLevel+w.replace(NEWLINE_ESCAPE, "\n") elif w.find(NEWLINE_ESCAPE) >= 0: if len(line.strip()) > 0: rValue += line+" "+w.replace(NEWLINE_ESCAPE, "\n") @@ -87,6 +93,7 @@ def wrap(text, width, caption=""): line += w if len(line) > 0: rValue += line.replace(NEWLINE_ESCAPE, "\n") + rValue = rValue.replace(SPACE_ESCAPE, " ") return rValue def checkconfig(myconfig): @@ -154,6 +161,8 @@ def getListElements(listnode): if not listnode.nodeName in ["ul", "ol"]: raise GlsaFormatException("Invalid function call: listnode is not