From: Fabian Groffen Date: Thu, 19 Feb 2009 17:58:41 +0000 (-0000) Subject: Merged from trunk -r12633:12649 X-Git-Url: http://git.tremily.us/gitweb.cgi?a=commitdiff_plain;h=19b9ea4c37b3de03addcb8ab20a451a030aacee6;p=portage.git Merged from trunk -r12633:12649 | 12634 | Bug #230483 - Convert glsa-check option parsing to use the | | zmedico | optparse module. This replaces some code which triggers a | | | traceback from 2to3. Thanks to Ali Polatel for | | | this patch. | | 12635 | For python-3.0 compatibility, raise a real exception instead | | zmedico | of a string. | | 12636 | Inside post_emerge(), skip the vardbapi counter check when | | zmedico | in --pretend mode (significant performance improvement). | | | Thanks to Marat Radchenko (slonopotamus) for reporting. | | 12637 | Don't bother to calculate PORTAGE_COUNTER_HASH when in | | zmedico | --pretend mode. | | 12638 | Use a regular expression for the file.name check. This | | zmedico | replaces some odd map() usage that 2to3 warns about. | | 12639 | For python-3.0 compatibility, don't use string.letters. | | zmedico | | | 12640 | For compatibility with python-3.0, inherit from ObjectProxy | | zmedico | instead of inheriting directly from file. | | 12641 | For compatibility with python-3.0, always open streams for | | zmedico | pickles in binary mode. | | 12642 | For compatibility with python-3.0, open files in text mode | | zmedico | where appropriate. | | 12643 | Revert accidental python-3.0 syntax. | | zmedico | | | 12644 | Tweak code to avoid python-3.0 errors like this one: | | zmedico | SyntaxError: can not delete variable 'e' referenced in | | | nested scope | | 12645 | For python-3.0 compatibility, encode strings as binary | | zmedico | before trying to pass them to hashlib. | | 12646 | Tweak exception handling indentation to avoid a bug in 2to3. | | zmedico | | | 12647 | Fix update() methods to work with python-3.0. | | zmedico | | | 12648 | Handle ValueError when unpickling, since this can be | | zmedico | triggered by an unsupported pickle protocol. | | 12649 | Decode terminal codes from binary when necessary, for | | zmedico | python-3.0 compatibility since sys.stdout is a text stream. | svn path=/main/branches/prefix/; revision=12652 --- diff --git a/bin/archive-conf b/bin/archive-conf index f32edf296..887af6de9 100755 --- a/bin/archive-conf +++ b/bin/archive-conf @@ -89,8 +89,8 @@ def archive_conf(): md5_match_hash[conf] = conf todo_cnt -= 1 if todo_cnt == 0: - raise "Break" - except "Break": + raise StopIteration() + except StopIteration: pass for conf in args: diff --git a/bin/glsa-check b/bin/glsa-check index 97f393c8e..d5ab21f4b 100644 --- a/bin/glsa-check +++ b/bin/glsa-check @@ -17,111 +17,89 @@ import portage from portage.output import * -from getopt import getopt, GetoptError +from optparse import OptionGroup, OptionParser __program__ = "glsa-check" __author__ = "Marius Mauch " __version__ = "1.0" -optionmap = [ -["-l", "--list", "list all unapplied GLSA"], -["-d", "--dump", "--print", "show all information about the given GLSA"], -["-t", "--test", "test if this system is affected by the given GLSA"], -["-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 (option)"], -["-e", "--emergelike", "do not use a least-change algorithm (option)"], -["-h", "--help", "show this help message"], -["-V", "--version", "some information about this tool"], -["-v", "--verbose", "print more information (option)"], -["-c", "--cve", "show CAN ids in listing mode (option)"], -["-m", "--mail", "send a mail with the given GLSAs to the administrator"] -] +def cb_version(*args, **kwargs): + """Callback for --version""" + sys.stderr.write("\n"+ __program__ + ", version " + __version__ + "\n") + sys.stderr.write("Author: " + __author__ + "\n") + sys.stderr.write("This program is licensed under the GPL, version 2\n\n") + sys.exit(0) # option parsing -args = [] -params = [] -try: - args, params = getopt(sys.argv[1:], "".join([o[0][1] for o in optionmap]), \ - [x[2:] for x in reduce(lambda x,y: x+y, [z[1:-1] for z in optionmap])]) -# ["dump", "print", "list", "pretend", "fix", "inject", "help", "verbose", "version", "test", "nocolor", "cve", "mail"]) - args = [a for a,b in args] - - for option in ["--nocolor", "-n"]: - if option in args: - nocolor() - args.remove(option) - - verbose = False - for option in ["--verbose", "-v"]: - if option in args: - verbose = True - args.remove(option) - - list_cve = False - for option in ["--cve", "-c"]: - if option in args: - list_cve = True - args.remove(option) - - least_change = True - for option in ["--emergelike", "-e"]: - if option in args: - least_change = False - args.remove(option) - - # sanity checking - if len(args) <= 0: - sys.stderr.write("no option given: what should I do ?\n") - mode="help" - elif len(args) > 1: - sys.stderr.write("please use only one command per call\n") - mode = "help" - else: - # in what mode are we ? - args = args[0] - for m in optionmap: - if args in [o for o in m[:-1]]: - mode = m[1][2:] - -except GetoptError, e: - sys.stderr.write("unknown option given: ") - sys.stderr.write(str(e)+"\n") - mode = "help" - -# we need a set of glsa for most operation modes -if len(params) <= 0 and mode in ["fix", "test", "pretend", "dump", "inject", "mail"]: +parser = OptionParser(usage="%prog