def _call_locked(self, func): """ Execute the given function at func after acquiring Entropy Resources Lock, for given repository at repo. The signature of func is: int func(entropy_client). """ client = None acquired = False try: try: client = self._entropy() except PermissionDenied as err: print_error(err.value) return 1 blocking = os.getenv("__EQUO_LOCKS_BLOCKING__") if blocking: client.output(darkgreen( _("Acquiring Entropy Resources " "Lock, please wait...")), back=True) acquired = entropy.tools.acquire_entropy_locks( client, blocking=blocking, spinner=True) if not acquired: client.output( darkgreen(_("Another Entropy is currently running.")), level="error", importance=1 ) return 1 return func(client) finally: if client is not None: client.shutdown() if acquired: entropy.tools.release_entropy_locks(client)
def _scan(self): """ Internal scan method, executes the actual scan and retuns a raw list of AntiMatterPackage objects. """ vardb, portdb = self._get_dbs() result = [] vardb.lock() try: cpv_all = vardb.cpv_all() cpv_all.sort() for count, package in enumerate(cpv_all): count_str = "[%s of %s]" % ( count, len(cpv_all), ) try: slot, repo = vardb.aux_get(package, ["SLOT", "repository"]) except KeyError: # package vanished, can still # happen even if locked? continue atom = portage.dep.Atom("=%s:%s::%s" % (package, slot, repo), allow_wildcard=True, allow_repo=True) if self._nsargs.verbose: print_warning("%s :: %s" % (count_str, atom), back=True) key_slot = "%s:%s" % (atom.cp, atom.slot) best_visible = portage.best(portdb.match(key_slot)) if not best_visible: # dropped upstream pkg = AntiMatterPackage(vardb, portdb, atom, None, -1) result.append(pkg) if self._nsargs.verbose: print_error(" %s no longer upstream or masked" % (key_slot, )) continue cmp_res = portage.versions.pkgcmp( portage.versions.pkgsplit(best_visible), portage.versions.pkgsplit(package)) pkg = AntiMatterPackage(vardb, portdb, atom, best_visible, cmp_res) result.append(pkg) finally: vardb.unlock() if cpv_all and self._nsargs.verbose: print_generic("") return result
def _to_unicode(arg): try: return const_convert_to_unicode(arg, enctype=etpConst['conf_encoding']) except UnicodeDecodeError: print_error("invalid argument: %s" % (arg, )) raise SystemExit(1)
def _to_unicode(arg): try: return const_convert_to_unicode( arg, enctype=etpConst['conf_encoding']) except UnicodeDecodeError: print_error("invalid argument: %s" % (arg,)) raise SystemExit(1)
def _call_shared(self, func): """ Execute the given function at func after acquiring Entropy Resources Lock in shared mode, for given repository at repo. The signature of func is: int func(entropy_client). """ client_class = None client = None acquired = False lock = None try: try: client_class = self._entropy_class() except PermissionDenied as err: print_error(err.value) return 1 lock = EntropyResourcesLock(output=client_class) lock.acquire_shared() acquired = True client = client_class() return func(client) finally: if client is not None: client.shutdown() if acquired: lock.release()
def _call_unlocked(self, func): """ Execute the given function at func after acquiring Entropy Resources Lock in shared mode, for given repository at repo. The signature of func is: int func(entropy_client). """ client = None acquired = False try: try: client = self._entropy() except PermissionDenied as err: print_error(err.value) return 1 # use blocking mode to avoid tainting stdout acquired = entropy.tools.acquire_entropy_locks( client, blocking=True, shared=True) if not acquired: client.output( darkgreen(_("Another Entropy is currently running.")), level="error", importance=1 ) return 1 return func(client) finally: if client is not None: client.shutdown() if acquired: entropy.tools.release_entropy_locks(client)
def _call_shared(self, func, repo): """ Execute the given function at func after acquiring Entropy Resources Lock in shared mode, for given repository at repo. The signature of func is: int func(entropy_server). """ server = None server_class = None acquired = False lock = None # make possible to avoid dealing with the resources lock. # This is useful if the lock is already acquired by some # parent or controller process. skip_lock = os.getenv("EIT_NO_RESOURCES_LOCK") is not None try: try: server_class = self._entropy_class() except PermissionDenied as err: print_error(err.value) return 1 if not skip_lock: lock = EntropyResourcesLock(output=server_class) lock.acquire_shared() acquired = True if not acquired: server_class.output(darkgreen( _("Another Entropy is currently running.")), level="error", importance=1) return 1 server = server_class(default_repository=repo) # make sure that repositories are closed now # to reset their internal states, which could have # become stale. # We cannot do this inside the API because we don't # know the lifecycle of EntropyRepository objects there. server.close_repositories() ServerRepositoryStatus().reset() return func(server) finally: if server is not None: server.shutdown() if acquired: lock.release()
def handle_exception(exc_class, exc_instance, exc_tb): # restore original exception handler, to avoid loops uninstall_exception_handler() entropy.tools.kill_threads() if exc_class is KeyboardInterrupt: os._exit(1) if exc_class is OnlineMirrorError: print_error("Mirror error: %s" % (exc_instance, )) os._exit(1) # always slap exception data (including stack content) entropy.tools.print_exception(tb_data=exc_tb, all_frame_data=True)
def _call_shared(self, func, repo): """ Execute the given function at func after acquiring Entropy Resources Lock in shared mode, for given repository at repo. The signature of func is: int func(entropy_server). """ server = None server_class = None acquired = False lock = None # make possible to avoid dealing with the resources lock. # This is useful if the lock is already acquired by some # parent or controller process. skip_lock = os.getenv("EIT_NO_RESOURCES_LOCK") is not None try: try: server_class = self._entropy_class() except PermissionDenied as err: print_error(err.value) return 1 if not skip_lock: lock = EntropyResourcesLock(output=server_class) lock.acquire_shared() acquired = True if not acquired: server_class.output(darkgreen(_("Another Entropy is currently running.")), level="error", importance=1) return 1 server = server_class(default_repository=repo) # make sure that repositories are closed now # to reset their internal states, which could have # become stale. # We cannot do this inside the API because we don't # know the lifecycle of EntropyRepository objects there. server.close_repositories() ServerRepositoryStatus().reset() return func(server) finally: if server is not None: server.shutdown() if acquired: lock.release()
def handle_exception(exc_class, exc_instance, exc_tb): # restore original exception handler, to avoid loops uninstall_exception_handler() entropy.tools.kill_threads() if exc_class is KeyboardInterrupt: os._exit(1) if exc_class is OnlineMirrorError: print_error("Mirror error: %s" % ( exc_instance,)) os._exit(1) # always slap exception data (including stack content) entropy.tools.print_exception(tb_data=exc_tb, all_frame_data=True)
def _call_exclusive(self, func): """ Execute the given function at func after acquiring Entropy Resources Lock, for given repository at repo. The signature of func is: int func(entropy_client). """ client_class = None client = None acquired = False lock = None try: try: client_class = self._entropy_class() except PermissionDenied as err: print_error(err.value) return 1 blocking = os.getenv("__EQUO_LOCKS_BLOCKING__") if blocking: client_class.output(darkgreen( _("Acquiring Entropy Resources " "Lock, please wait...")), back=True) lock = EntropyResourcesLock(output=client_class) if blocking: lock.acquire_exclusive() acquired = True else: acquired = lock.wait_exclusive() if not acquired: client_class.output( darkgreen(_("Another Entropy is currently running.")), level="error", importance=1 ) return 1 client = client_class() return func(client) finally: if client is not None: client.shutdown() if acquired: lock.release()
def _call_exclusive(self, func): """ Execute the given function at func after acquiring Entropy Resources Lock, for given repository at repo. The signature of func is: int func(entropy_client). """ client_class = None client = None acquired = False lock = None try: try: client_class = self._entropy_class() except PermissionDenied as err: print_error(err.value) return 1 blocking = os.getenv("__EQUO_LOCKS_BLOCKING__") if blocking: client_class.output(darkgreen( _("Acquiring Entropy Resources " "Lock, please wait...")), back=True) lock = EntropyResourcesLock(output=client_class) if blocking: lock.acquire_exclusive() acquired = True else: acquired = lock.wait_exclusive() if not acquired: client_class.output(darkgreen( _("Another Entropy is currently running.")), level="error", importance=1) return 1 client = client_class() return func(client) finally: if client is not None: client.shutdown() if acquired: lock.release()
def _call_exclusive(self, func, repo): """ Execute the given function at func after acquiring Entropy Resources Lock, for given repository at repo. The signature of func is: int func(entropy_server). """ server = None server_class = None acquired = False lock = None try: try: server_class = self._entropy_class() except PermissionDenied as err: print_error(err.value) return 1 lock = EntropyResourcesLock(output=server_class) acquired = lock.wait_exclusive() if not acquired: server_class.output(darkgreen(_("Another Entropy is currently running.")), level="error", importance=1) return 1 server = server_class(default_repository=repo) # make sure that repositories are closed now # to reset their internal states, which could have # become stale. # We cannot do this inside the API because we don't # know the lifecycle of EntropyRepository objects there. server.close_repositories() ServerRepositoryStatus().reset() return func(server) finally: if server is not None: server.shutdown() if acquired: lock.release()
def _call_unlocked(self, func, repo): """ Execute the given function at func after acquiring Entropy Resources Lock in shared mode, for given repository at repo. The signature of func is: int func(entropy_server). """ server = None acquired = False try: try: server = self._entropy(default_repository=repo) except PermissionDenied as err: print_error(err.value) return 1 # use blocking mode to avoid tainting stdout acquired = entropy.tools.acquire_entropy_locks( server, blocking=True, shared=True) if not acquired: server.output( darkgreen(_("Another Entropy is currently running.")), level="error", importance=1 ) return 1 # make sure that repositories are closed now # to reset their internal states, which could have # become stale. # We cannot do this inside the API because we don't # know the lifecycle of EntropyRepository objects there. server.close_repositories() ServerRepositoryStatus().reset() return func(server) finally: if server is not None: server.shutdown() if acquired: entropy.tools.release_entropy_locks(server)
"-n", action="store_true", default=False, help="list packages that have been recently " "added") mg_group.add_argument("--not-installed", "-i", action="store_true", default=False, help="list packages that haven't been installed") nsargs = None try: nsargs = parser.parse_args(sys.argv[1:]) nsargs.filters = [re.compile(x) for x in nsargs.filters] # still hardcoded, but candidate for argparse argument # used in the calculation of new packages. nsargs.new_days_old = 14 except re.error as err: print_error("Error, invalid regexp: %s" % (err, )) raise SystemExit(1) try: antimatter = AntiMatter(nsargs) antimatter.scan().notify() except KeyboardInterrupt: print_error("Interrupted.") raise SystemExit(1) raise SystemExit(0)
def main(): is_color = "--color" in sys.argv if is_color: sys.argv.remove("--color") if not is_color and not is_stdout_a_tty(): nocolor() warn_version_mismatch() install_exception_handler() descriptors = SoloCommandDescriptor.obtain() args_map = {} catch_all = None for descriptor in descriptors: klass = descriptor.get_class() if klass.CATCH_ALL: catch_all = klass args_map[klass.NAME] = klass for alias in klass.ALIASES: args_map[alias] = klass args = sys.argv[1:] # convert args to unicode, to avoid passing # raw string stuff down to entropy layers def _to_unicode(arg): try: return const_convert_to_unicode( arg, enctype=etpConst['conf_encoding']) except UnicodeDecodeError: print_error("invalid argument: %s" % (arg,)) raise SystemExit(1) args = list(map(_to_unicode, args)) is_bashcomp = False if "--bashcomp" in args: is_bashcomp = True args.remove("--bashcomp") # the first eit, because bash does: # argv -> equo --bashcomp equo repo # and we need to drop --bashcomp and # argv[2] if args: args.pop(0) cmd = None last_arg = None if args: last_arg = args[-1] cmd = args[0] args = args[1:] cmd_class = args_map.get(cmd) yell_class = args_map.get("yell") if cmd_class is None: cmd_class = catch_all cmd_obj = cmd_class(args) if is_bashcomp: try: cmd_obj.bashcomp(last_arg) except NotImplementedError: pass raise SystemExit(0) # non-root users not allowed allowed = True if os.getuid() != 0 and \ cmd_class is not catch_all and \ not cmd_class.ALLOW_UNPRIVILEGED and \ "--help" not in args: cmd_class = catch_all allowed = False if allowed: if not cmd_class.ALLOW_UNPRIVILEGED: if entropy.tools.islive(): warn_live_system() func, func_args = cmd_obj.parse() exit_st = func(*func_args) if exit_st == -10: # syntax error, yell at user func, func_args = yell_class(args).parse() func(*func_args) raise SystemExit(10) else: yell_class.reset() raise SystemExit(exit_st) else: # execute this anyway so that commands are # incomplete or invalid, the command error # message will take precedence. _func, _func_args = cmd_obj.parse() print_error(_("superuser access required")) raise SystemExit(1)
def main(): install_exception_handler() descriptors = EitCommandDescriptor.obtain() args_map = {} catch_all = None for descriptor in descriptors: klass = descriptor.get_class() if klass.CATCH_ALL: catch_all = klass args_map[klass.NAME] = klass for alias in klass.ALIASES: args_map[alias] = klass args = sys.argv[1:] # convert args to unicode, to avoid passing # raw string stuff down to entropy layers def _to_unicode(arg): try: return const_convert_to_unicode( arg, enctype=etpConst['conf_encoding']) except UnicodeDecodeError: print_error("invalid argument: %s" % (arg,)) raise SystemExit(1) args = list(map(_to_unicode, args)) is_bashcomp = False if "--bashcomp" in args: is_bashcomp = True args.remove("--bashcomp") # the first eit, because bash does: # argv -> eit --bashcomp eit add # and we need to drop --bashcomp and # argv[2] args.pop(0) cmd = None last_arg = None if args: last_arg = args[-1] cmd = args[0] args = args[1:] cmd_class = args_map.get(cmd) if cmd_class is None: cmd_class = catch_all cmd_obj = cmd_class(args) if is_bashcomp: try: cmd_obj.bashcomp(last_arg) except NotImplementedError: pass raise SystemExit(0) # non-root users not allowed allowed = True if os.getuid() != 0 and \ cmd_class is not catch_all: if not cmd_class.ALLOW_UNPRIVILEGED: cmd_class = catch_all allowed = False func, func_args = cmd_obj.parse() if allowed: exit_st = func(*func_args) raise SystemExit(exit_st) else: print_error(_("superuser access required")) raise SystemExit(1)
mg_group.add_argument("--downgrade", "-d", action="store_true", default=False, help="list packages that would be downgraded") mg_group.add_argument("--new", "-n", action="store_true", default=False, help="list packages that have been recently " "added") mg_group.add_argument("--not-installed", "-i", action="store_true", default=False, help="list packages that haven't been installed") nsargs = None try: nsargs = parser.parse_args(sys.argv[1:]) nsargs.filters = [re.compile(x) for x in nsargs.filters] # still hardcoded, but candidate for argparse argument # used in the calculation of new packages. nsargs.new_days_old = 14 except re.error as err: print_error("Error, invalid regexp: %s" % (err,)) raise SystemExit(1) try: antimatter = AntiMatter(nsargs) antimatter.scan().notify() except KeyboardInterrupt: print_error("Interrupted.") raise SystemExit(1) raise SystemExit(0)
def main(): is_color = "--color" in sys.argv if is_color: sys.argv.remove("--color") if not is_color and not is_stdout_a_tty(): nocolor() warn_version_mismatch() install_exception_handler() descriptors = SoloCommandDescriptor.obtain() args_map = {} catch_all = None for descriptor in descriptors: klass = descriptor.get_class() if klass.CATCH_ALL: catch_all = klass args_map[klass.NAME] = klass for alias in klass.ALIASES: args_map[alias] = klass args = sys.argv[1:] # convert args to unicode, to avoid passing # raw string stuff down to entropy layers def _to_unicode(arg): try: return const_convert_to_unicode(arg, enctype=etpConst['conf_encoding']) except UnicodeDecodeError: print_error("invalid argument: %s" % (arg, )) raise SystemExit(1) args = list(map(_to_unicode, args)) is_bashcomp = False if "--bashcomp" in args: is_bashcomp = True args.remove("--bashcomp") # the first eit, because bash does: # argv -> equo --bashcomp equo repo # and we need to drop --bashcomp and # argv[2] if args: args.pop(0) cmd = None last_arg = None if args: last_arg = args[-1] cmd = args[0] args = args[1:] cmd_class = args_map.get(cmd) yell_class = args_map.get("yell") if cmd_class is None: cmd_class = catch_all cmd_obj = cmd_class(args) if is_bashcomp: try: cmd_obj.bashcomp(last_arg) except NotImplementedError: pass raise SystemExit(0) # non-root users not allowed allowed = True if os.getuid() != 0 and \ cmd_class is not catch_all and \ not cmd_class.ALLOW_UNPRIVILEGED and \ "--help" not in args: cmd_class = catch_all allowed = False if allowed: if not cmd_class.ALLOW_UNPRIVILEGED: if entropy.tools.islive(): warn_live_system() func, func_args = cmd_obj.parse() exit_st = func(*func_args) if exit_st == -10: # syntax error, yell at user func, func_args = yell_class(args).parse() func(*func_args) raise SystemExit(10) else: yell_class.reset() raise SystemExit(exit_st) else: # execute this anyway so that commands are # incomplete or invalid, the command error # message will take precedence. _func, _func_args = cmd_obj.parse() print_error(_("superuser access required")) raise SystemExit(1)
def main(): install_exception_handler() descriptors = EitCommandDescriptor.obtain() args_map = {} catch_all = None for descriptor in descriptors: klass = descriptor.get_class() if klass.CATCH_ALL: catch_all = klass args_map[klass.NAME] = klass for alias in klass.ALIASES: args_map[alias] = klass args = sys.argv[1:] # convert args to unicode, to avoid passing # raw string stuff down to entropy layers def _to_unicode(arg): try: return const_convert_to_unicode(arg, enctype=etpConst['conf_encoding']) except UnicodeDecodeError: print_error("invalid argument: %s" % (arg, )) raise SystemExit(1) args = list(map(_to_unicode, args)) is_bashcomp = False if "--bashcomp" in args: is_bashcomp = True args.remove("--bashcomp") # the first eit, because bash does: # argv -> eit --bashcomp eit add # and we need to drop --bashcomp and # argv[2] args.pop(0) cmd = None last_arg = None if args: last_arg = args[-1] cmd = args[0] args = args[1:] cmd_class = args_map.get(cmd) if cmd_class is None: cmd_class = catch_all cmd_obj = cmd_class(args) if is_bashcomp: try: cmd_obj.bashcomp(last_arg) except NotImplementedError: pass raise SystemExit(0) # non-root users not allowed allowed = True if os.getuid() != 0 and \ cmd_class is not catch_all: if not cmd_class.ALLOW_UNPRIVILEGED: cmd_class = catch_all allowed = False func, func_args = cmd_obj.parse() if allowed: exit_st = func(*func_args) raise SystemExit(exit_st) else: print_error(_("superuser access required")) raise SystemExit(1)
def _scan(self): """ Internal scan method, executes the actual scan and retuns a raw list of AntiMatterPackage objects. """ vardb, portdb = self._get_dbs() result = [] vardb.lock() try: cpv_all = vardb.cpv_all() cpv_all.sort() for count, package in enumerate(cpv_all): count_str = "[%s of %s]" % ( count, len(cpv_all),) try: slot, repo = vardb.aux_get( package, ["SLOT", "repository"]) except KeyError: # package vanished, can still # happen even if locked? continue atom = portage.dep.Atom( "=%s:%s::%s" % (package, slot, repo), allow_wildcard=True, allow_repo=True) if self._nsargs.verbose: print_warning("%s :: %s" % (count_str, atom), back=True) key_slot = "%s:%s" % (atom.cp, atom.slot) best_visible = portage.best(portdb.match(key_slot)) if not best_visible: # dropped upstream pkg = AntiMatterPackage( vardb, portdb, atom, None, -1) result.append(pkg) if self._nsargs.verbose: print_error( " %s no longer upstream or masked" % (key_slot,)) continue cmp_res = portage.versions.pkgcmp( portage.versions.pkgsplit(best_visible), portage.versions.pkgsplit(package)) pkg = AntiMatterPackage( vardb, portdb, atom, best_visible, cmp_res) result.append(pkg) finally: vardb.unlock() if cpv_all and self._nsargs.verbose: print_generic("") return result