def main(): """Parse command line and execute all actions.""" # set default options options = {} options['nocolor'] = (port_settings.get("NOCOLOR") in ('yes', 'true') or not sys.stdout.isatty()) if options['nocolor']: pp.output.nocolor() # parse command line options and actions try: action = parseArgs(options) # filter exception to know what message to display except ParseArgsException as e: if e.value == 'help': printUsage(help='all') sys.exit(0) elif e.value[:5] == 'help-': printUsage(help=e.value[5:]) sys.exit(0) elif e.value == 'version': printVersion() sys.exit(0) else: printUsage(e.value) sys.exit(2) output = OutputControl(options) options['verbose-output'] = lambda x: None if not options['quiet']: if options['verbose']: options['verbose-output'] = output.einfo # parse the exclusion file if not 'exclude-file' in options: # set it to the default exclude file if it exists exclude_file = "%s/etc/%s/%s.exclude" % (EPREFIX, __productname__, action) if os.path.isfile(exclude_file): options['exclude-file'] = exclude_file if 'exclude-file' in options: try: exclude = parseExcludeFile(options['exclude-file'], options['verbose-output']) except ParseExcludeFileException as e: print(pp.error(str(e)), file=sys.stderr) print(pp.error("Invalid exclusion file: %s" % options['exclude-file']), file=sys.stderr) print(pp.error("See format of this file in `man %s`" % __productname__), file=sys.stderr) sys.exit(1) else: exclude = {} # security check for non-pretend mode if not options['pretend'] and portage.secpass == 0: print(pp.error("Permission denied: you must be root or belong to " + "the portage group."), file=sys.stderr) sys.exit(1) # execute action doAction(action, options, exclude=exclude, output=output)
def main(): """Parse command line and execute all actions.""" # set default options options = {} options['nocolor'] = (port_settings.get("NOCOLOR") in ('yes','true') or not sys.stdout.isatty()) if options['nocolor']: pp.output.nocolor() # parse command line options and actions try: action = parseArgs(options) # filter exception to know what message to display except ParseArgsException as e: if e.value == 'help': printUsage(help='all') sys.exit(0) elif e.value[:5] == 'help-': printUsage(help=e.value[5:]) sys.exit(0) elif e.value == 'version': printVersion() sys.exit(0) else: printUsage(e.value) sys.exit(2) output = OutputControl(options) options['verbose-output'] = lambda x: None if not options['quiet']: if options['verbose']: options['verbose-output'] = output.einfo # parse the exclusion file if not 'exclude-file' in options: # set it to the default exclude file if it exists exclude_file = "%s/etc/%s/%s.exclude" % (EPREFIX,__productname__ , action) if os.path.isfile(exclude_file): options['exclude-file'] = exclude_file if 'exclude-file' in options: try: exclude = parseExcludeFile(options['exclude-file'], options['verbose-output']) except ParseExcludeFileException as e: print( pp.error(str(e)), file=sys.stderr) print( pp.error( "Invalid exclusion file: %s" % options['exclude-file']), file=sys.stderr) print( pp.error( "See format of this file in `man %s`" % __productname__), file=sys.stderr) sys.exit(1) else: exclude = {} # security check for non-pretend mode if not options['pretend'] and portage.secpass == 0: print( pp.error( "Permission denied: you must be root or belong to " + "the portage group."), file=sys.stderr) sys.exit(1) # execute action doAction(action, options, exclude=exclude, output=output)