示例#1
0
def main(filename: str,
         filtered_devices: Optional[Sequence[str]] = None,
         verbose: int = 0,
         *,
         cleanup: bool = True):
    serialized_config = yaml.safe_load(open(filename))
    config = apischema.deserialize(ConfigurationFile, serialized_config)

    console = rich.console.Console()
    try:
        with console.status("[bold green] Performing checks..."):
            for info in get_configurations_from_file(
                    config, filtered_devices=filtered_devices):
                if isinstance(info, ConfigFileHappiError):
                    console.print("Failed to load", info.dev_name)
                    continue
                if isinstance(info, Exception):
                    console.print("Failed to load", info)
                    continue

                severity, results = check_device(info.device,
                                                 info.dev_config.checks)
                log_results_rich(
                    console,
                    device=info.device,
                    config=info.dev_config,
                    severity=severity,
                    results=results,
                    verbose=verbose,
                )
    finally:
        if cleanup:
            ophyd_cleanup()
示例#2
0
    def verify_key(self):
        key = console.input("\n[deep_sky_blue1]ENTER Key: [/deep_sky_blue1]",
                            password=True)

        with console.status("[bold green]Verifying...") as status:
            sleep(0.5)
            if key == SECRET_KEY_MAIN:
                console.print(
                    "\n[bright_green][VERIFICATION SUCCESSFULL][/bright_green]\n"
                )
                status.stop()
                return self.menu()
            else:
                console.print("\n[red][KEY ERROR]\n\n[EXITING]\n[/red]")
示例#3
0
def main() -> NoReturn:
    """The main entry point"""
    args = parser.parse_args()

    if args.query is None or args.query == "":
        parser.print_help()
    else:
        sites = set(args.sites)
        try:
            with console.status(f"Searching {', '.join(sites)}\n"):
                returned_data = {
                    site: sync_search(args.query, search_on_site=site)
                    for site in sites
                }
        except errors.RecaptchaError as error:
            raise error
        except errors.StackSearchBaseError as error:
            console.print(rich.markup.escape(repr(error)), style="bold red")
            sys.exit(1)
        if args.raw:
            print(json.dumps(returned_data))
            sys.exit(0)

        def print_questions_and_answers(data: Dict[str, Dict[str, List[str]]]):
            for site, questions in data.items():
                console.rule(f"[bold]Site: [blue]{site}[/]\n\n")
                for question, answers in questions.items():
                    console.rule("Question")
                    console.print(rich.markdown.Markdown(question))
                    console.rule("Answer(s)")
                    if len(answers) == 0:
                        console.print(
                            "[bold red]There were no answers for this question[/]"
                        )
                    else:
                        for index, answer in enumerate(answers):
                            console.rule(f"Answer [yellow]#{index}[/]",
                                         align="left")
                            console.print(rich.markdown.Markdown(answer))

        if args.pager:
            with console.pager(styles=args.pager_colors):
                print_questions_and_answers(returned_data)
        else:
            print_questions_and_answers(returned_data)
示例#4
0
def test_status():
    console = Console(file=io.StringIO(), force_terminal=True, width=20)
    status = console.status("foo")
    assert isinstance(status, Status)
示例#5
0
def test_no_nested_live():
    console = Console()
    with pytest.raises(errors.LiveError):
        with console.status("foo"):
            with console.status("bar"):
                pass
示例#6
0
console = console.Console()

project_environment_file_exists = os.path.isfile(
    os.path.dirname(os.path.realpath(__file__)) + "\\.env")

project_environment_file = os.path.dirname(
    os.path.realpath(__file__)) + "\\.env"

if not project_environment_file_exists:
    print("\n[blue bold]Let's set your masterpassword...[/blue bold]")
    USER_KEY = console.input(
        "\n[deep_sky_blue1]ENTER master password: [/deep_sky_blue1]",
        password=True)

    with console.status("[bold green]Working...") as status:
        sleep(1)
        console.print("\n[bold magenta]> Making .env[/bold magenta]")
        sleep(1)

        with open(project_environment_file, "w") as environment:
            console.print(
                "[bold magenta]> Setting up environment[/bold magenta]")
            environment.write(
                f"USER_KEY = {str(USER_KEY)}\nTOKEN = {Fernet.generate_key().decode('utf-8')}"
            )

            sleep(2)
            console.print("[bold magenta]> Starting App[/bold magenta]")
            sleep(1)