diff options
-rwxr-xr-x | bin/repoman | 99 |
1 files changed, 41 insertions, 58 deletions
diff --git a/bin/repoman b/bin/repoman index 622a7efa6..82025f6f8 100755 --- a/bin/repoman +++ b/bin/repoman @@ -9,6 +9,7 @@ import codecs import errno +import logging import optparse import os import re @@ -61,15 +62,16 @@ import portage.const import portage.dep portage.dep._dep_check_strict = True import portage.exception -from portage import cvstree -from portage import normalize_path +from portage import cvstree, normalize_path from portage.manifest import Manifest from portage.exception import ParseError from portage.process import find_binary, spawn - +from portage.util import initialize_logger from portage.output import bold, create_color_func, darkgreen, \ green, nocolor, red, turquoise, yellow +initialize_logger() + allowed_filename_chars="a-zA-Z0-9._-+:" allowed_filename_chars_set = {} map(allowed_filename_chars_set.setdefault, map(chr, range(ord('a'), ord('z')+1))) @@ -88,24 +90,13 @@ if repoman_settings.get("NOCOLOR", "").lower() in ("yes", "true") or \ not sys.stdout.isatty(): nocolor() -def warn(txt): - print exename+": "+txt -def err(txt): - warn(txt) - sys.exit(1) - -def err_help(txt): - help(exitstatus=-1,helpfulness=0) - warn(txt) +def exithandler(signum=None, frame=None): + logging.fatal("Interrupted; exiting...") sys.exit(1) + os.kill(0, signal.SIGKILL) -def exithandler(signum=None,frame=None): - sys.stderr.write("\n"+exename+": Interrupted; exiting...\n") - sys.exit(1) - os.kill(0,signal.SIGKILL) signal.signal(signal.SIGINT,exithandler) - class RepomanHelpFormatter(optparse.IndentedHelpFormatter): """Repoman needs it's own HelpFormatter for now, because the default ones murder the help text.""" @@ -172,14 +163,14 @@ def ParseArgs(args, qahelp): parser.add_option('-p', '--pretend', dest='pretend', default=False, action='store_true', help='don\'t commit or fix anything; just show what would be done') - parser.add_option('-q', '--quiet', dest="verbosity", action="store_const", const=0, + parser.add_option('-q', '--quiet', dest="quiet", action="count", default=0, help='do not print unnecessary messages') parser.add_option('-f', '--force', dest='force', default=False, action='store_true', help='Commit with QA violations') parser.add_option('-v', '--verbose', dest="verbosity", action='count', - help='be very verbose in output') + help='be very verbose in output', default=0) parser.add_option('-x', '--xmlparse', dest='xml_parse', action='store_true', default=False, help='forces the metadata.xml parse check to be carried out') @@ -224,6 +215,15 @@ def ParseArgs(args, qahelp): if opts.mode == 'commit' and opts.ignore_masked: parser.error('Commit mode and --ignore_masked are not compatable') + # Use the verbosity and quiet options to fiddle with the loglevel appropriately + for val in range(opts.verbosity): + logger = logging.getLogger() + logger.setLevel(logger.getEffectiveLevel() - 10) + + for val in range(opts.quiet): + logger = logging.getLogger() + logger.setLevel(logger.getEffectiveLevel() + 10) + return (opts, args) qahelp={ @@ -334,7 +334,7 @@ commitmessagefile=None for x in missingvars: x += ".missing" if x not in qacats: - print "* missingvars values need to be added to qahelp ("+x+")" + logging.warn('* missingvars values need to be added to qahelp ("%s")' % x) qacats.append(x) qawarnings.append(x) @@ -344,9 +344,6 @@ valid_restrict = frozenset(["binchecks", "bindist", "fetch", "mirror", # file.executable no_exec = frozenset(["Manifest","ChangeLog","metadata.xml"]) -verbose=0 -quiet=0 - def last(full=False): """Print the results of the last repoman run Args: @@ -424,8 +421,7 @@ if os.path.isdir("CVS"): isCvs = True if options.mode == 'commit' and not options.pretend and not isCvs: - print - print darkgreen("Not in a CVS repository; enabling pretend mode.") + logging.info("Not in a CVS repository; enabling pretend mode.") options.pretend = True def have_profile_dir(path, maxdepth=3): @@ -502,10 +498,9 @@ if portdir_overlay != portdir: else: os.environ["PORTDIR_OVERLAY"] = "" -if quiet < 2: - print "\nSetting paths:" - print "PORTDIR = \""+os.environ["PORTDIR"]+"\"" - print "PORTDIR_OVERLAY = \""+os.environ["PORTDIR_OVERLAY"]+"\"" +logging.info('Setting paths:') +logging.info('PORTDIR = "' + os.environ['PORTDIR'] + '"') +logging.info('PORTDIR_OVERLAY = "' + os.environ['PORTDIR_OVERLAY']+'"') # Now that PORTDIR_OVERLAY is properly overridden, create the portdb. repoman_settings = portage.config(local_config=False, @@ -569,8 +564,8 @@ try: parse_use_local_desc(f, luselist) f.close() except (IOError, OSError, ParseError), e: - print >> sys.stderr, str(e) - err("Couldn't read from use.local.desc") + logging.exception("Couldn't read from use.local.desc", e) + sys.exit(1) if portdir_overlay != portdir: filename = os.path.join(portdir_overlay, "profiles", "use.local.desc") @@ -580,8 +575,8 @@ if portdir_overlay != portdir: parse_use_local_desc(f, luselist) f.close() except (IOError, OSError, ParseError), e: - print >> sys.stderr, str(e) - err("Couldn't read from '%s'" % filename) + logging.exception("Couldn't read from '%s'" % filename, e) + sys.exit(1) del filename # setup a uselist from portage @@ -594,22 +589,23 @@ try: vardescs = portage.grabfile(portdir+"/profiles/desc/"+var.lower()+".desc") for l in range(0, len(vardescs)): uselist.append(var.lower() + "_" + vardescs[l].split()[0]) -except SystemExit, e: - raise # Need to propogate this -except: - err("Couldn't read USE flags from use.desc") +except (IOError, OSError, ParseError), e: + logging.exception("Couldn't read USE flags from use.desc", e) + sys.exit(1) # retrieve a list of current licenses in portage liclist = set(portage.listdir(os.path.join(portdir, "licenses"))) if not liclist: - err("Couldn't find licenses?") + logging.fatal("Couldn't find licenses?") + sys.exit(1) if portdir_overlay != portdir: liclist.update(portage.listdir(os.path.join(portdir_overlay, "licenses"))) # retrieve list of offical keywords kwlist = set(portage.grabfile(os.path.join(portdir, "profiles", "arch.list"))) if not kwlist: - err("Couldn't read KEYWORDS from arch.list") + logging.fatal("Couldn't read KEYWORDS from arch.list") + sys.exit(1) manifest1_compat = not os.path.exists( os.path.join(portdir, "manifest1_obsolete")) @@ -802,7 +798,7 @@ if options.mode == "manifest": pass elif options.pretend: print green("\nRepoMan does a once-over of the neighborhood...") -elif quiet < 1: +else: print green("\nRepoMan scours the neighborhood...") new_ebuilds = set() @@ -817,8 +813,7 @@ arch_caches={} arch_xmatch_caches = {} for x in scanlist: #ebuilds and digests added to cvs respectively. - if verbose: - print "checking package " + x + logging.info("checking package %s" % x) eadded=[] dadded=[] catdir,pkgdir=x.split("/") @@ -1524,8 +1519,6 @@ if os.access(portage.const.CACHE_PATH, os.W_OK): savef.close() portage.apply_secpass_permissions(fpath, gid=portage.portage_gid, mode=0664) -if quiet < 2: - print # TODO(antarus) This function and last () look familiar ;) @@ -1581,21 +1574,14 @@ def grouplist(mylist,seperator="/"): if options.mode != 'commit': if dofull: print bold("Note: type \"repoman full\" for a complete listing.") - if quiet < 1: - print if dowarn and not dofail: - if quiet < 2: - print green("RepoMan sez:"),"\"You're only giving me a partial QA payment?\n I'll take it this time, but I'm not happy.\"" - else: - print green("RepoMan sez:"),"\"OK for now, but I'll be back ...\"" + print green("RepoMan sez:"),"\"You're only giving me a partial QA payment?\n I'll take it this time, but I'm not happy.\"" elif not dofail: print green("RepoMan sez:"),"\"If everyone were like you, I'd be out of business!\"" elif dofail: print turquoise("Please fix these important QA issues first.") print green("RepoMan sez:"),"\"Make your QA payment on time and you'll never see the likes of me.\"\n" sys.exit(1) - if quiet < 1: - print else: if dofail and can_force and options.force and not options.pretend: print green("RepoMan sez:") + \ @@ -1705,10 +1691,8 @@ else: print "*",green(str(len(myupdates))),"files being committed...",green(str(len(myheaders))),"have headers that will change." print "*","Files with headers will cause the manifests to be made and recommited." - if quiet == 0: - print "myupdates:",myupdates - print "myheaders:",myheaders - print + logging.info("myupdates:", str(myupdates)) + logging.info("myheaders:", str(myheaders)) if commitmessagefile: try: @@ -1816,8 +1800,7 @@ else: if "PORTAGE_GPG_DIR" not in repoman_settings: if os.environ.has_key("HOME"): repoman_settings["PORTAGE_GPG_DIR"] = os.path.join(os.environ["HOME"], ".gnupg") - if quiet < 1: - print "Automatically setting PORTAGE_GPG_DIR to",repoman_settings["PORTAGE_GPG_DIR"] + logging.info("Automatically setting PORTAGE_GPG_DIR to %s" % repoman_settings["PORTAGE_GPG_DIR"]) else: raise portage.exception.MissingParameter("PORTAGE_GPG_DIR is unset!") gpg_dir = repoman_settings["PORTAGE_GPG_DIR"] |