예제 #1
0
 def init_singleton(self):
     self._progress = None
     self.oldcount = []
     Client.init_singleton(self,
                           xcache=False,
                           url_fetcher=InstallerUrlFetcher)
     nocolor()
예제 #2
0
        for regex in self._nsargs.filters:
            result = list(
                filter(functools.partial(_regex_filter, regex), result))

        klass = StdoutAntiMatterResult
        if self._nsargs.html:
            klass = HtmlAntiMatterResult

        return klass(result, self._nsargs)


if __name__ == "__main__":

    # disable color if standard output is not a TTY
    if not is_stdout_a_tty():
        nocolor()

    parser = argparse.ArgumentParser(
        description="Automated package updates scanner",
        formatter_class=argparse.RawDescriptionHelpFormatter)

    parser.add_argument("--verbose",
                        "-v",
                        action="store_true",
                        default=False,
                        help="verbose output")
    parser.add_argument("--extended",
                        "-x",
                        action="store_true",
                        default=False,
                        help="extended output")
예제 #3
0
파일: main.py 프로젝트: geaaru/entropy
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)
예제 #4
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)
예제 #5
0
 def init_singleton(self):
     Client.init_singleton(self, xcache = False,
         url_fetcher = InstallerUrlFetcher)
     nocolor()
예제 #6
0
 def init_singleton(self):
     Client.init_singleton(self,
                           xcache=False,
                           url_fetcher=InstallerUrlFetcher)
     nocolor()
예제 #7
0
            result = list(filter(
                    functools.partial(_regex_filter, regex),
                    result))

        klass = StdoutAntiMatterResult
        if self._nsargs.html:
            klass = HtmlAntiMatterResult

        return klass(result, self._nsargs)


if __name__ == "__main__":

    # disable color if standard output is not a TTY
    if not is_stdout_a_tty():
        nocolor()

    parser = argparse.ArgumentParser(
        description="Automated package updates scanner",
        formatter_class=argparse.RawDescriptionHelpFormatter)

    parser.add_argument("--verbose", "-v", action="store_true",
                        default=False, help="verbose output")
    parser.add_argument("--extended", "-x", action="store_true",
                        default=False, help="extended output")
    parser.add_argument("--quiet", "-q", action="store_true",
                        default=False, help="quiet output")
    parser.add_argument("--html", "-t", action="store_true",
                        default=False, help="prints in html format")

    parser.add_argument("--filter", "-f", dest="filters",
예제 #8
0
 def init_singleton(self):
     self._progress = None
     self.oldcount = []
     Client.init_singleton(self, xcache = False,
         url_fetcher = InstallerUrlFetcher)
     nocolor()