Esempio n. 1
0
    def renderWidgets(self, line):
        """
        Execute the appropriate widgets and queue the output for sending from
        the main thread.
        """
        params = line.strip().split()  # We need to accept trailing \r

        parser = StatTextLineParser(self)
        options, args = parser.parse_args(params)

        # Render the widgets if the input wasn't a single keep_alive flag
        if not (options.keep_alive and not args):
            core = StatCore(self.queueLine, api=self.api, parser=parser)
            core.main(params)

        if options.keep_alive:
            self.keep_alive = not self.keep_alive
Esempio n. 2
0
    def renderWidgets(self, line):
        """
        Execute the appropriate widgets and queue the output for sending from
        the main thread.
        """
        params = line.strip().split()  # We need to accept trailing \r

        parser = StatTextLineParser(self)
        options, args = parser.parse_args(params)

        # Render the widgets if the input wasn't a single keep_alive flag
        if not (options.keep_alive and not args):
            core = StatCore(self.queueLine, api=self.api, parser=parser)
            core.main(params)

        if options.keep_alive:
            self.keep_alive = not self.keep_alive
Esempio n. 3
0
    def main(self, params):
        """
        Process some command line parameters and pass them to StatCore.
        """
        base_url = os.environ.get("STAT_URL", "https://stat.ripe.net/data/")
        token = os.environ.get("STAT_TOKEN")

        options, args = self.parser.parse_args(params)

        logger = logging.getLogger(None)
        if options.tracebacks:
            logger.setLevel(logging.ERROR)
        else:
            logger.setLevel(logging.CRITICAL)

        api = StatAPI("cli", base_url=base_url, token=token)
        stat = StatCore(self.output, parser=self.parser, api=api)
        if (options.login or options.password) and not options.username:
            options.username = self.get_input("username: "******"STAT_PASSWORD")
            if not password:
                password = getpass("password: "******"Failed to authenticate.")
            if options.login:
                if not success:
                    return 1
                token = stat.api.get_session()
                self.output(
                    "STAT_TOKEN=" + token + "; export STAT_TOKEN; "
                    "echo STAT_TOKEN has been set. You are now logged in to "
                    "RIPEstat with this shell."
                )
                return 0
        return stat.main(params)
Esempio n. 4
0
    def main(self, params):
        """
        Process some command line parameters and pass them to StatCore.
        """
        base_url = os.environ.get("STAT_URL", "https://stat.ripe.net/data/")
        token = os.environ.get("STAT_TOKEN")

        options, args = self.parser.parse_args(params)

        logger = logging.getLogger(None)
        if options.tracebacks:
            logger.setLevel(logging.ERROR)
        else:
            logger.setLevel(logging.CRITICAL)

        api = StatAPI("cli", base_url=base_url, token=token)
        stat = StatCore(self.output, parser=self.parser, api=api)
        if (options.login or options.password) and not options.username:
            options.username = self.get_input("username: "******"STAT_PASSWORD")
            if not password:
                password = getpass("password: "******"Failed to authenticate.")
            if options.login:
                if not success:
                    return 1
                token = stat.api.get_session()
                self.output(
                    "STAT_TOKEN=" + token + "; export STAT_TOKEN; "
                    "echo STAT_TOKEN has been set. You are now logged in to "
                    "RIPEstat with this shell.")
                return 0
        return stat.main(params)