示例#1
0
文件: help.py 项目: B-Rich/entropy
    def bashcomp(self, last_arg):
        """
        Overridden from EitCommand
        """
        import sys

        descriptors = EitCommandDescriptor.obtain()
        descriptors.sort(key = lambda x: x.get_name())
        outcome = []
        for descriptor in descriptors:
            name = descriptor.get_name()
            if name == EitHelp.NAME:
                # do not add self
                continue
            outcome.append(name)
            aliases = descriptor.get_class().ALIASES
            outcome.extend(aliases)

        def _startswith(string):
            if last_arg is not None:
                return string.startswith(last_arg)
            return True

        outcome = sorted(filter(_startswith, outcome))
        sys.stdout.write(" ".join(outcome) + "\n")
        sys.stdout.flush()
示例#2
0
文件: help.py 项目: skwerlman/entropy
    def bashcomp(self, last_arg):
        """
        Overridden from EitCommand
        """
        import sys

        descriptors = EitCommandDescriptor.obtain()
        descriptors.sort(key=lambda x: x.get_name())
        outcome = []
        for descriptor in descriptors:
            name = descriptor.get_name()
            if name == EitHelp.NAME:
                # do not add self
                continue
            outcome.append(name)
            aliases = descriptor.get_class().ALIASES
            outcome.extend(aliases)

        def _startswith(string):
            if last_arg is not None:
                return string.startswith(last_arg)
            return True

        outcome = sorted(filter(_startswith, outcome))
        sys.stdout.write(" ".join(outcome) + "\n")
        sys.stdout.flush()
示例#3
0
文件: help.py 项目: skwerlman/entropy
    def _show_help(self, *args):
        parser = argparse.ArgumentParser(
            description=_("Entropy Infrastructure Toolkit"),
            epilog="http://www.sabayon.org",
            formatter_class=ColorfulFormatter)

        descriptors = EitCommandDescriptor.obtain()
        descriptors.sort(key=lambda x: x.get_name())
        group = parser.add_argument_group("command", "available commands")
        for descriptor in descriptors:
            aliases = descriptor.get_class().ALIASES
            aliases_str = ", ".join([teal(x) for x in aliases])
            if aliases_str:
                aliases_str = " [%s]" % (aliases_str, )
            name = "%s%s" % (purple(descriptor.get_name()), aliases_str)
            desc = descriptor.get_description()
            group.add_argument(name, help=darkgreen(desc), action="store_true")
        parser.print_help()
        if not self._args:
            return 1
        return 0
示例#4
0
文件: help.py 项目: B-Rich/entropy
    def _show_help(self, *args):
        parser = argparse.ArgumentParser(
            description=_("Entropy Infrastructure Toolkit"),
            epilog="http://www.sabayon.org",
            formatter_class=ColorfulFormatter)

        descriptors = EitCommandDescriptor.obtain()
        descriptors.sort(key = lambda x: x.get_name())
        group = parser.add_argument_group("command", "available commands")
        for descriptor in descriptors:
            aliases = descriptor.get_class().ALIASES
            aliases_str = ", ".join([teal(x) for x in aliases])
            if aliases_str:
                aliases_str = " [%s]" % (aliases_str,)
            name = "%s%s" % (purple(descriptor.get_name()),
                aliases_str)
            desc = descriptor.get_description()
            group.add_argument(name, help=darkgreen(desc), action="store_true")
        parser.print_help()
        if not self._args:
            return 1
        return 0
示例#5
0
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)
示例#6
0
文件: main.py 项目: B-Rich/entropy
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)