def _build_execution_header_output(self): """ Return a string used as stdout/stderr header text. """ my_str = "{%s of %s particles | %s of %s packages | %s} " % ( darkgreen(str(self._spec_number)), purple(str(self._tot_spec)), darkgreen(str(self._pkg_number)), purple(str(self._tot_pkgs)), brown(self._params["__name__"]),) # file name return my_str
def _build_execution_header_output(self): """ Return a string used as stdout/stderr header text. """ my_str = "{%s of %s particles | %s of %s packages | %s} " % ( darkgreen(str(self._spec_number)), purple(str(self._tot_spec)), darkgreen(str(self._pkg_number)), purple(str(self._tot_pkgs)), brown(self._params["__name__"]), ) # file name return my_str
def main(): """ Main App. """ install_exception_handler() # disable color if standard output is not a TTY if not is_stdout_a_tty(): nocolor() # Load Binary PMS modules import matter.binpms as _pms pms_dir = os.path.dirname(_pms.__file__) for thing in os.listdir(pms_dir): if thing.startswith("__init__.py"): continue thing = os.path.join(pms_dir, thing) if not os.path.isfile(thing): continue if not thing.endswith(".py"): continue name = os.path.basename(thing) name = name.rstrip(".py") package = "matter.binpms.%s" % (name,) try: importlib.import_module(package) # they will then register except ImportError as err: pass avail_binpms = BaseBinaryPMS.available_pms matter_spec = MatterSpec() parser_data = matter_spec.data() matter_spec_params = "" for spec_key in sorted(parser_data.keys()): par = parser_data[spec_key] matter_spec_params += "%s: %s\n" % ( purple(spec_key), darkgreen(par.get("desc", "N/A")),) _env_vars_help = """\ Environment variables for Package Builder module: %s = repository identifier %s = alternative command used to sync Portage default: %s %s = alternative command used to sync Portage overlays default: %s Environment variables passed to --post executables: %s = exit status from previous execution phases, useful for detecting execution errors. Matter Resources Lock file you can use to detect if matter is running: %s (--blocking switch makes it acquire in blocking mode) Matter .spec file supported parameters: %s Available Binary PMSs: %s """ % ( purple("MATTER_REPOSITORY_ID"), purple("MATTER_PORTAGE_SYNC_CMD"), darkgreen(PackageBuilder.DEFAULT_PORTAGE_SYNC_CMD), purple("MATTER_OVERLAYS_SYNC_CMD"), darkgreen(PackageBuilder.DEFAULT_OVERLAYS_SYNC_CMD), purple("MATTER_EXIT_STATUS"), darkgreen(MatterResourceLock.LOCK_FILE_PATH), matter_spec_params, "\n".join( ["%s: %s" % (purple(k.NAME), darkgreen(k.__name__)) \ for k in avail_binpms]),) parser = argparse.ArgumentParser( description="Automated Packages Builder", epilog=_env_vars_help, formatter_class=argparse.RawDescriptionHelpFormatter) # * instead of + in order to support --sync only tasks parser.add_argument( "spec", nargs="+", metavar="<spec>", type=file, help="matter spec file") default_pms = avail_binpms[0] for k in avail_binpms: if k.DEFAULT: default_pms = k break parser.add_argument( "--pms", default=default_pms.NAME, help="specify an alternative Binary PMS (see --help for a list), " "current default: %s" % (default_pms.NAME,)) parser.add_argument( "--blocking", help="when trying to acquire Binary PMS locks, " "block until success.", action="store_true") parser.add_argument("--commit", help="commit built packages to repository.", action="store_true") parser.add_argument( "--gentle", help="increase the system validation checks, be extremely " "careful wrt the current system status.", action="store_true") parser.add_argument("--pre", metavar="<exec>", type=file, help="executable to be called once for setup purposes.", default=None) parser.add_argument("--post", metavar="<exec>", type=file, help="executable to be called once for teardown purposes.", default=None) parser.add_argument( "--push", help="push Binary PMS package updates to online " "repository (only if --commit).", action="store_true") parser.add_argument( "--sync", help="sync Portage tree, and attached overlays, before starting.", action="store_true") parser.add_argument( "--sync-best-effort", default=False, help="sync Portage tree and attached overlays, as --sync, but do " "not exit if sync fails.", action="store_true") parser.add_argument( "--disable-preserved-libs", dest="disable_preserved_libs", default=False, help="disable prerserved libraries check.", action="store_true") parser.add_argument( "--pretend", dest="pretend", default=False, help="show what would be done without alterint the current system.", action="store_true") # extend parser arguments for k in avail_binpms: k.extend_parser(parser) try: nsargs = parser.parse_args(sys.argv[1:]) except IOError as err: if err.errno == errno.ENOENT: print_error(err.strerror + ": " + err.filename) return 1 raise if os.getuid() != 0: # root access required print_error("superuser access required") return 1 # parse spec files specs = [] for spec_f in nsargs.spec: spec = SpecParser(spec_f) data = spec.parse() if data: specs.append(data) if not specs: print_error("invalid spec files provided") return 1 # O(n) determine what is the BinaryPMS to use klass = None for k in avail_binpms: if k.NAME == nsargs.pms: klass = k break if klass is None: print_error("invalid Binary PMS specified: %s" % (nsargs.pms,)) return 1 binary_pms = None exit_st = 0 cwd = os.getcwd() try: try: binary_pms = klass(cwd, nsargs) except BaseBinaryPMS.BinaryPMSLoadError as err: # repository not available or not configured print_error("Cannot load Binary Package Manager: %s" % (err,)) return 3 print_info("Loaded Binary PMS: %s" % (klass.NAME,)) # validate repository entries of spec metadata for spec in specs: try: binary_pms.validate_spec(spec) except BaseBinaryPMS.SpecParserError as err: print_error("%s" % (err,)) return 1 if nsargs.blocking: print_info("--blocking enabled, please wait for locks...") resource_lock = binary_pms.get_resource_lock(nsargs.blocking) with resource_lock: with MatterResourceLock(nsargs.blocking): exit_st = matter_main(binary_pms, nsargs, cwd, specs) except BaseBinaryResourceLock.NotAcquired: print_error("unable to acquire PMS Resources lock") return 42 except MatterResourceLock.NotAcquired: print_error("unable to acquire Matter Resources lock") return 42 except KeyboardInterrupt: print_error("Keyboard Interrupt, pid: %s" % (os.getpid(),)) return 42 finally: if binary_pms is not None: binary_pms.shutdown() print_warning("") print_warning("") print_warning("Tasks complete, exit status: %d" % (exit_st,)) return exit_st
def main(): """ Main App. """ install_exception_handler() # disable color if standard output is not a TTY if not is_stdout_a_tty(): nocolor() # Load Binary PMS modules import matter.binpms as _pms pms_dir = os.path.dirname(_pms.__file__) for thing in os.listdir(pms_dir): if thing.startswith("__init__.py"): continue thing = os.path.join(pms_dir, thing) if not os.path.isfile(thing): continue if not thing.endswith(".py"): continue name = os.path.basename(thing) name = name.rstrip(".py") package = "matter.binpms.%s" % (name, ) try: importlib.import_module(package) # they will then register except ImportError as err: pass avail_binpms = BaseBinaryPMS.available_pms matter_spec = MatterSpec() parser_data = matter_spec.data() matter_spec_params = "" for spec_key in sorted(parser_data.keys()): par = parser_data[spec_key] matter_spec_params += "%s: %s\n" % ( purple(spec_key), darkgreen(par.get("desc", "N/A")), ) _env_vars_help = """\ Environment variables for Package Builder module: %s = repository identifier %s = alternative command used to sync Portage default: %s %s = alternative command used to sync Portage overlays default: %s Environment variables passed to --post executables: %s = exit status from previous execution phases, useful for detecting execution errors. Matter Resources Lock file you can use to detect if matter is running: %s (--blocking switch makes it acquire in blocking mode) Matter .spec file supported parameters: %s Available Binary PMSs: %s """ % ( purple("MATTER_REPOSITORY_ID"), purple("MATTER_PORTAGE_SYNC_CMD"), darkgreen(PackageBuilder.DEFAULT_PORTAGE_SYNC_CMD), purple("MATTER_OVERLAYS_SYNC_CMD"), darkgreen(PackageBuilder.DEFAULT_OVERLAYS_SYNC_CMD), purple("MATTER_EXIT_STATUS"), darkgreen(MatterResourceLock.LOCK_FILE_PATH), matter_spec_params, "\n".join( ["%s: %s" % (purple(k.NAME), darkgreen(k.__name__)) \ for k in avail_binpms]),) parser = argparse.ArgumentParser( description="Automated Packages Builder", epilog=_env_vars_help, formatter_class=argparse.RawDescriptionHelpFormatter) # * instead of + in order to support --sync only tasks parser.add_argument("spec", nargs="+", metavar="<spec>", type=file, help="matter spec file") default_pms = avail_binpms[0] for k in avail_binpms: if k.DEFAULT: default_pms = k break parser.add_argument( "--pms", default=default_pms.NAME, help="specify an alternative Binary PMS (see --help for a list), " "current default: %s" % (default_pms.NAME, )) parser.add_argument("--blocking", help="when trying to acquire Binary PMS locks, " "block until success.", action="store_true") parser.add_argument("--commit", help="commit built packages to repository.", action="store_true") parser.add_argument( "--gentle", help="increase the system validation checks, be extremely " "careful wrt the current system status.", action="store_true") parser.add_argument( "--pre", metavar="<exec>", type=file, help="executable to be called once for setup purposes.", default=None) parser.add_argument( "--post", metavar="<exec>", type=file, help="executable to be called once for teardown purposes.", default=None) parser.add_argument("--push", help="push Binary PMS package updates to online " "repository (only if --commit).", action="store_true") parser.add_argument( "--sync", help="sync Portage tree, and attached overlays, before starting.", action="store_true") parser.add_argument( "--sync-best-effort", default=False, help="sync Portage tree and attached overlays, as --sync, but do " "not exit if sync fails.", action="store_true") parser.add_argument("--disable-preserved-libs", dest="disable_preserved_libs", default=False, help="disable prerserved libraries check.", action="store_true") parser.add_argument( "--pretend", dest="pretend", default=False, help="show what would be done without alterint the current system.", action="store_true") # extend parser arguments for k in avail_binpms: k.extend_parser(parser) try: nsargs = parser.parse_args(sys.argv[1:]) except IOError as err: if err.errno == errno.ENOENT: print_error(err.strerror + ": " + err.filename) return 1 raise if os.getuid() != 0: # root access required print_error("superuser access required") return 1 # parse spec files specs = [] for spec_f in nsargs.spec: spec = SpecParser(spec_f) data = spec.parse() if data: specs.append(data) if not specs: print_error("invalid spec files provided") return 1 # O(n) determine what is the BinaryPMS to use klass = None for k in avail_binpms: if k.NAME == nsargs.pms: klass = k break if klass is None: print_error("invalid Binary PMS specified: %s" % (nsargs.pms, )) return 1 binary_pms = None exit_st = 0 cwd = os.getcwd() try: try: binary_pms = klass(cwd, nsargs) except BaseBinaryPMS.BinaryPMSLoadError as err: # repository not available or not configured print_error("Cannot load Binary Package Manager: %s" % (err, )) return 3 print_info("Loaded Binary PMS: %s" % (klass.NAME, )) # validate repository entries of spec metadata for spec in specs: try: binary_pms.validate_spec(spec) except BaseBinaryPMS.SpecParserError as err: print_error("%s" % (err, )) return 1 if nsargs.blocking: print_info("--blocking enabled, please wait for locks...") resource_lock = binary_pms.get_resource_lock(nsargs.blocking) with resource_lock: with MatterResourceLock(nsargs.blocking): exit_st = matter_main(binary_pms, nsargs, cwd, specs) except BaseBinaryResourceLock.NotAcquired: print_error("unable to acquire PMS Resources lock") return 42 except MatterResourceLock.NotAcquired: print_error("unable to acquire Matter Resources lock") return 42 except KeyboardInterrupt: print_error("Keyboard Interrupt, pid: %s" % (os.getpid(), )) return 42 finally: if binary_pms is not None: binary_pms.shutdown() print_warning("") print_warning("") print_warning("Tasks complete, exit status: %d" % (exit_st, )) return exit_st