def main(): if os.getuid() != 0: version() # catalyst cannot be run as a normal user due to chroots, mounts, etc print "!!! catalyst: This script requires root privileges to operate" sys.exit(2) # we need some options in order to work correctly if len(sys.argv) < 2: usage() sys.exit(2) # parse out the command line arguments try: opts,args = getopt.getopt(sys.argv[1:], "apPThvdc:C:f:FVs:", ["purge", "purgeonly", "purgetmponly", "help", "version", "debug",\ "clear-autoresume", "config=", "cli=", "file=", "fetch", "verbose","snapshot="]) except getopt.GetoptError: usage() sys.exit(2) myconfig = "" myspecfile = "" mycmdline = [] # check preconditions if len(opts) == 0: print "!!! catalyst: please specify one of either -f or -C\n" usage() sys.exit(2) options = set() run = False for o, a in opts: if o in ("-h", "--help"): version() usage() sys.exit(1) if o in ("-V", "--version"): print get_version() sys.exit(1) if o in ("-d", "--debug"): conf_values["DEBUG"] = True conf_values["VERBOSE"] = True if o in ("-c", "--config"): myconfig = a if o in ("-C", "--cli"): run = True x = sys.argv.index(o) + 1 while x < len(sys.argv): mycmdline.append(sys.argv[x]) x = x + 1 if o in ("-f", "--file"): run = True myspecfile = a if o in ("-F", "--fetchonly"): options.add("fetch") if o in ("-v", "--verbose"): conf_values["VERBOSE"] = "1" if o in ("-s", "--snapshot"): if len(sys.argv) < 3: print "!!! catalyst: missing snapshot identifier\n" usage() sys.exit(2) else: run = True mycmdline.append("target=snapshot") mycmdline.append("version_stamp=" + a) if o in ("-p", "--purge"): options.add("purge") if o in ("-P", "--purgeonly"): options.add("purgeonly") if o in ("-T", "--purgetmponly"): options.add("purgetmponly") if o in ("-a", "--clear-autoresume"): options.add("clear-autoresume") #print "MAIN: cli options =", options if not run: print "!!! catalyst: please specify one of either -f or -C\n" usage() sys.exit(2) # made it this far so start by outputting our version info version() # import configuration file and import our main module using those settings parse_config(myconfig) conf_values["options"].update(options) #print "MAIN: conf_values['options'] =", conf_values["options"] # initialize our contents generator contents_map = ContentsMap(CONTENTS_DEFINITIONS) conf_values["contents_map"] = contents_map # initialze our hash and contents generators hash_map = HashMap(HASH_DEFINITIONS) conf_values["hash_map"] = hash_map # Start checking that digests are valid now that hash_map is initialized if "digests" in conf_values: for i in conf_values["digests"].split(): if i not in HASH_DEFINITIONS: print print i + " is not a valid digest entry" print "Valid digest entries:" print HASH_DEFINITIONS.keys() print print "Catalyst aborting...." sys.exit(2) if find_binary(hash_map.hash_map[i].cmd) == None: print print "digest=" + i print "\tThe " + hash_map.hash_map[i].cmd + \ " binary was not found. It needs to be in your system path" print print "Catalyst aborting...." sys.exit(2) if "hash_function" in conf_values: if conf_values["hash_function"] not in HASH_DEFINITIONS: print print conf_values["hash_function"]+\ " is not a valid hash_function entry" print "Valid hash_function entries:" print HASH_DEFINITIONS.keys() print print "Catalyst aborting...." sys.exit(2) if find_binary( hash_map.hash_map[conf_values["hash_function"]].cmd) == None: print print "hash_function=" + conf_values["hash_function"] print "\tThe "+hash_map.hash_map[conf_values["hash_function"]].cmd + \ " binary was not found. It needs to be in your system path" print print "Catalyst aborting...." sys.exit(2) addlargs = {} if myspecfile: spec = catalyst.config.SpecParser(myspecfile) addlargs.update(spec.get_values()) if mycmdline: try: cmdline = catalyst.config.ConfigParser() cmdline.parse_lines(mycmdline) addlargs.update(cmdline.get_values()) except CatalystError: print "!!! catalyst: Could not parse commandline, exiting." sys.exit(1) if "target" not in addlargs: raise CatalystError("Required value \"target\" not specified.") # everything is setup, so the build is a go try: build_target(addlargs) except CatalystError: print print "Catalyst aborting...." sys.exit(2) except KeyboardInterrupt: print "\nCatalyst build aborted due to user interrupt ( Ctrl-C )" print print "Catalyst aborting...." sys.exit(2) except LockInUse: print "Catalyst aborting...." sys.exit(2) except: print "Catalyst aborting...." raise sys.exit(2)
def version(): print get_version() print "Copyright 2003-2008 Gentoo Foundation" print "Copyright 2008-2012 various authors" print "Distributed under the GNU General Public License version 2.1\n"
def version(): log.info(get_version()) log.info('Copyright 2003-%s Gentoo Foundation', datetime.datetime.now().year) log.info('Copyright 2008-2012 various authors') log.info('Distributed under the GNU General Public License version 2.1')
def get_parser(): """Return an argument parser""" epilog = textwrap.dedent("""\ Usage examples: Using the snapshot option to make a snapshot of the ebuild repo: $ catalyst --snapshot <git-treeish> Using the specfile option (-f, --file) to build a stage target: $ catalyst -f stage1-specfile.spec """) parser = argparse.ArgumentParser( epilog=epilog, formatter_class=argparse.RawDescriptionHelpFormatter) parser.add_argument('-V', '--version', action='version', version=get_version(), help='display version information') parser.add_argument('--enter-chroot', default=False, action='store_true', help='Enter chroot before starting the build') group = parser.add_argument_group('Program output options') group.add_argument('-d', '--debug', default=False, action='store_true', help='enable debugging (and default --log-level debug)') group.add_argument('-v', '--verbose', default=False, action='store_true', help='verbose output (and default --log-level info)') group.add_argument('--log-level', default=None, choices=('critical', 'error', 'warning', 'notice', 'info', 'debug'), help='set verbosity of output (default: notice)') group.add_argument( '--log-file', type=FilePath(exists=False), help='write all output to this file (instead of stdout)') group.add_argument('--color', default=None, action='store_true', help='colorize output all the time (default: detect)') group.add_argument( '--nocolor', dest='color', action='store_false', help='never colorize output all the time (default: detect)') group = parser.add_argument_group('Developer options') group.add_argument('--trace', default=False, action='store_true', help='trace program output (akin to `sh -x`)') group.add_argument('--profile', default=False, action='store_true', help='profile program execution') group = parser.add_argument_group('Temporary file management') group.add_argument('-a', '--clear-autoresume', default=False, action='store_true', help='clear autoresume flags') group.add_argument('-p', '--purge', default=False, action='store_true', help='clear tmp dirs, package cache, autoresume flags') group.add_argument( '-P', '--purgeonly', default=False, action='store_true', help='clear tmp dirs, package cache, autoresume flags and exit') group.add_argument('-T', '--purgetmponly', default=False, action='store_true', help='clear tmp dirs and autoresume flags and exit') group.add_argument('--versioned-cachedir', dest='versioned_cachedir', action='store_true', help='use stage version on cache directory name') group.add_argument('--unversioned-cachedir', dest='versioned_cachedir', action='store_false', help='do not use stage version on cache directory name') group.set_defaults(versioned_cachedir=False) group = parser.add_argument_group('Target/config file management') group.add_argument('-F', '--fetchonly', default=False, action='store_true', help='fetch files only') group.add_argument('-c', '--configs', type=FilePath(), action='append', help='use specified configuration files') group.add_argument('-f', '--file', type=FilePath(), help='read specfile') group.add_argument('-s', '--snapshot', type=str, help='Make an ebuild repo snapshot') return parser
def get_parser(): """Return an argument parser""" epilog = """Usage examples: Using the commandline option (-C, --cli) to build a Portage snapshot: $ catalyst -C target=snapshot version_stamp=my_date Using the snapshot option (-s, --snapshot) to build a release snapshot: $ catalyst -s 20071121 Using the specfile option (-f, --file) to build a stage target: $ catalyst -f stage1-specfile.spec""" parser = argparse.ArgumentParser( epilog=epilog, formatter_class=argparse.RawDescriptionHelpFormatter) parser.add_argument('-V', '--version', action='version', version=get_version(), help='display version information') group = parser.add_argument_group('Program output options') group.add_argument('-d', '--debug', default=False, action='store_true', help='enable debugging (and default --log-level debug)') group.add_argument('-v', '--verbose', default=False, action='store_true', help='verbose output (and default --log-level info)') group.add_argument('--log-level', default=None, choices=('critical', 'error', 'warning', 'notice', 'info', 'debug'), help='set verbosity of output (default: notice)') group.add_argument( '--log-file', type=FilePath(exists=False), help='write all output to this file (instead of stdout)') group.add_argument('--color', default=None, action='store_true', help='colorize output all the time (default: detect)') group.add_argument( '--nocolor', dest='color', action='store_false', help='never colorize output all the time (default: detect)') group = parser.add_argument_group('Developer options') group.add_argument('--trace', default=False, action='store_true', help='trace program output (akin to `sh -x`)') group.add_argument('--profile', default=False, action='store_true', help='profile program execution') group = parser.add_argument_group('Temporary file management') group.add_argument('-a', '--clear-autoresume', default=False, action='store_true', help='clear autoresume flags') group.add_argument('-p', '--purge', default=False, action='store_true', help='clear tmp dirs, package cache, autoresume flags') group.add_argument( '-P', '--purgeonly', default=False, action='store_true', help='clear tmp dirs, package cache, autoresume flags and exit') group.add_argument('-T', '--purgetmponly', default=False, action='store_true', help='clear tmp dirs and autoresume flags and exit') group.add_argument('--versioned-cachedir', dest='versioned_cachedir', action='store_true', help='use stage version on cache directory name') group.add_argument('--unversioned-cachedir', dest='versioned_cachedir', action='store_false', help='do not use stage version on cache directory name') group.set_defaults(versioned_cachedir=False) group = parser.add_argument_group('Target/config file management') group.add_argument('-F', '--fetchonly', default=False, action='store_true', help='fetch files only') group.add_argument('-c', '--configs', type=FilePath(), action='append', help='use specified configuration files') group.add_argument('-f', '--file', type=FilePath(), help='read specfile') group.add_argument('-s', '--snapshot', help='generate a release snapshot') group.add_argument('-C', '--cli', default=[], nargs=argparse.REMAINDER, help='catalyst commandline (MUST BE LAST OPTION)') return parser
def get_parser(): """Return an argument parser""" epilog = """Usage examples: Using the commandline option (-C, --cli) to build a Portage snapshot: $ catalyst -C target=snapshot version_stamp=my_date Using the snapshot option (-s, --snapshot) to build a release snapshot: $ catalyst -s 20071121 Using the specfile option (-f, --file) to build a stage target: $ catalyst -f stage1-specfile.spec""" parser = argparse.ArgumentParser(epilog=epilog, formatter_class=argparse.RawDescriptionHelpFormatter) parser.add_argument('-V', '--version', action='version', version=get_version(), help='display version information') group = parser.add_argument_group('Program output options') group.add_argument('-d', '--debug', default=False, action='store_true', help='enable debugging (and default --log-level debug)') group.add_argument('-v', '--verbose', default=False, action='store_true', help='verbose output (and default --log-level info)') group.add_argument('--log-level', default=None, choices=('critical', 'error', 'warning', 'notice', 'info', 'debug'), help='set verbosity of output (default: notice)') group.add_argument('--log-file', type=FilePath(exists=False), help='write all output to this file (instead of stdout)') group.add_argument('--color', default=None, action='store_true', help='colorize output all the time (default: detect)') group.add_argument('--nocolor', dest='color', action='store_false', help='never colorize output all the time (default: detect)') group = parser.add_argument_group('Temporary file management') group.add_argument('-a', '--clear-autoresume', default=False, action='store_true', help='clear autoresume flags') group.add_argument('-p', '--purge', default=False, action='store_true', help='clear tmp dirs, package cache, autoresume flags') group.add_argument('-P', '--purgeonly', default=False, action='store_true', help='clear tmp dirs, package cache, autoresume flags and exit') group.add_argument('-T', '--purgetmponly', default=False, action='store_true', help='clear tmp dirs and autoresume flags and exit') group = parser.add_argument_group('Target/config file management') group.add_argument('-F', '--fetchonly', default=False, action='store_true', help='fetch files only') group.add_argument('-c', '--configs', type=FilePath(), action='append', help='use specified configuration files') group.add_argument('-f', '--file', type=FilePath(), help='read specfile') group.add_argument('-s', '--snapshot', help='generate a release snapshot') group.add_argument('-C', '--cli', default=[], nargs=argparse.REMAINDER, help='catalyst commandline (MUST BE LAST OPTION)') return parser