How to use rich - 10 common examples

To help you get started, we’ve selected a few rich examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ArturSpirin / test_junkie / test_junkie / cli / hq / hq.py View on Github external
def ls(display_tokens=False):

        if not os.path.exists(Config.get_hq_root_dir()):
            console.print("Resource not found.")
            exit(0)
        docs = os.listdir(Config.get_hq_root_dir())
        if docs:
            from rich.table import Table

            table = Table(title="")

            table.add_column("ID", justify="left", style="blue")
            table.add_column("Host")
            table.add_column("Name")
            if display_tokens:
                table.add_column("Token", justify="left", no_wrap=True)
            table.add_column("Status", justify="left")

            for doc in docs:
                with open(Config.get_hq_root_dir() + os.sep + doc, "r+") as details:
                    server = loads(details.read())
                    if display_tokens:
                        table.add_row(f"{server['id']}", f"{server['host']}", f"{server['name']}", f"{server['token']}")
                    else:
                        table.add_row(f"{server['id']}", f"{server['host']}", f"{server['name']}")
            console.print(table)
github ArturSpirin / test_junkie / test_junkie / cli / audit / tags / commands.py View on Github external
no_test_retries, no_suite_meta, no_test_meta):
    """Pivot test information from tag's perspective"""
    if verbose:
        from test_junkie.debugger import LogJunkie
        LogJunkie.enable_logging(10)

    from test_junkie.cli.run.cli_runner import CliRunner
    from test_junkie.cli.audit.cli_audit import CliAudit
    try:
        tj = CliRunner(sources=sources, ignore=[".git"], suites=suites, no_guess_root=no_guess_root)
        tj.scan()
        aggregator = CliAudit(suites=tj.suites, args=locals())
        aggregator.aggregate()
        aggregator.print_results(command="tags")
    except BadCliParameters as error:
        print("[[[bold red]ERROR[/bold red]]] [bold red]{error}[/bold red]".format(error=error))
github brandonskerritt / Ciphey / test / progress.py View on Github external
from rich.progress import track
import time

for step in track(range(1)):
    # do_step(step)
    if step == 50:
        exit(1)
    time.sleep(10)
github ArturSpirin / test_junkie / test_junkie / cli / hq / agent / agent.py View on Github external
import os
import pickle
from json import loads
from rich.console import Console
from test_junkie.cli.config.Config import Config

console = Console()


class Agent:

    def __init__(self):

        pass

    @staticmethod
    def get_agent(host):
        return f"{Config.get_agents_root_dir()}{os.sep}{Agent.md5(host)}.pickle"

    @staticmethod
    def md5(host):
        import hashlib
        m = hashlib.md5()
github intel / cve-bin-tool / test / test_output_engine.py View on Github external
def test_output_console(self):
        """Test Formatting Output as console"""

        console = Console(file=self.mock_file)
        output_console(self.MOCK_OUTPUT, console=console)
        expected_output = "│ vendorname0  │ productname0  │ 1.0      │ CVE-1234-1234  │ MEDIUM   │\n│ vendorname0  │ productname0  │ 1.0      │ CVE-1234-9876  │ LOW      │\n│ vendorname0  │ productname0  │ 2.8.6    │ CVE-1234-1111  │ LOW      │\n│ vendorname1  │ productname1  │ 3.2.1.0  │ CVE-1234-5678  │ HIGH     │\n└──────────────┴───────────────┴──────────┴────────────────┴──────────┘\n"
        self.mock_file.seek(0)  # reset file position
        self.assertIn(expected_output, self.mock_file.read())
github BrancoLab / BrainRender / tests / test_scene_io.py View on Github external
)

    cam3 = buildcam(
        dict(
            position=[1862.135, -4020.792, -36292.348],
            focal=[6587.835, 3849.085, 5688.164],
            viewup=[0.185, -0.97, 0.161],
            distance=42972.44,
            clipping=[29629.503, 59872.10],
        )
    )

    # ------------------------------- Create frames ------------------------------ #
    # Create frames
    prev_neurons = []
    for step in track(
        np.arange(N_FRAMES), total=N_FRAMES, description="Generating frames..."
    ):
        if step % N_frames_for_change == 0:  # change neurons every N framse

            # reset neurons from previous set of neurons
            for neuron in prev_neurons:
                for component, actor in neuron.items():
                    actor.alpha(minalpha)
                    actor.color(darkcolor)
            prev_neurons = []

            # highlight new neurons
            neurons = choices(neurons_actors, k=N_neurons_in_frame)
            for n, neuron in enumerate(neurons):
                color = colorMap(
                    n, "Greens_r", vmin=-2, vmax=N_neurons_in_frame + 3
github brandonskerritt / Ciphey / tests / generate_tests.py View on Github external
def main(self):
        with open("test_main_generated.py", "w") as f:
            f.write("from ciphey.__main__ import main, make_default_config")
            print("Opened fild")
            for i in track(range(1, self.HOW_MANY_TESTS)):
                print("In the for loop")
                x = self.enCiphey_obj.getRandomEncryptedSentence()
                print(x)
                # if x["CipherUsed"] == "MorseCode":
                # self.make_test_lc_true_template(cipher=x)
                to_append = self.make_test_lc_true_template(cipher=x)
                print(f"Adding {to_append}")
                f.write(to_append)
github AcidWeb / CurseBreaker / CurseBreaker.py View on Github external
optkeep = True
            else:
                optkeep = False
            addons = self.parse_args(args)
            with Progress('{task.completed}/{task.total}', '|', BarColumn(bar_width=None), '|',
                          auto_refresh=False, console=self.console) as progress:
                task = progress.add_task('', total=len(addons))
                while not progress.finished:
                    for addon in addons:
                        name, version = self.core.del_addon(addon, optkeep)
                        if name:
                            self.table.add_row(f'[bold red]Uninstalled[/bold red]',
                                               Text(name, no_wrap=True), Text(version, no_wrap=True))
                        else:
                            self.table.add_row(f'[bold black]Not installed[/bold black]',
                                               Text(addon, no_wrap=True), Text('', no_wrap=True))
                        progress.update(task, advance=1, refresh=True)
            self.console.print(self.table)
        else:
            self.console.print('[green]Usage:[/green]\n\tThis command accepts a space-separated list of addon names or '
                               'full links as an argument.\n\t[bold white]Flags:[/bold white]\n\t\t[bold white]-k[/bold'
                               ' white] - Keep the addon files after uninstalling.', highlight=False)
github AcidWeb / CurseBreaker / CurseBreaker.py View on Github external
update_addon(addon if isinstance(addon, str) else addon['URL'], update, force)
                        if provider:
                            source = f' [bold white]{source}[/bold white]'
                        else:
                            source = ''
                        if versionold:
                            if versionold == versionnew:
                                if modified:
                                    self.table.add_row(f'[bold red]Modified[/bold red]{source}',
                                                       Text(name, no_wrap=True), Text(versionold, no_wrap=True))
                                else:
                                    if self.core.config['CompactMode'] and compacted > -1:
                                        compacted += 1
                                    else:
                                        self.table.add_row(f'[green]Up-to-date[/green]{source}',
                                                           Text(name, no_wrap=True), Text(versionold, no_wrap=True))
                            else:
                                if modified or blocked:
                                    self.table.add_row(f'[bold red]Update suppressed[/bold red]{source}',
                                                       Text(name, no_wrap=True), Text(versionold, no_wrap=True))
                                else:
                                    self.table.add_row(f'[yellow]{"Updated" if update else "Update available"}'
                                                       f'[/yellow]{source}', Text(name, no_wrap=True),
                                                       Text(versionnew, style='yellow', no_wrap=True))
                        else:
                            self.table.add_row(f'[bold black]Not installed[/bold black]{source}',
                                               Text(addon, no_wrap=True), Text('', no_wrap=True))
                    except Exception as e:
                        exceptions.append(e)
                    progress.update(task, advance=1 if args else 0.5, refresh=True)
        if addline:
            self.console.print('')
github AcidWeb / CurseBreaker / CurseBreaker.py View on Github external
self.table.add_row(f'[bold red]Modified[/bold red]{source}',
                                                       Text(name, no_wrap=True), Text(versionold, no_wrap=True))
                                else:
                                    if self.core.config['CompactMode'] and compacted > -1:
                                        compacted += 1
                                    else:
                                        self.table.add_row(f'[green]Up-to-date[/green]{source}',
                                                           Text(name, no_wrap=True), Text(versionold, no_wrap=True))
                            else:
                                if modified or blocked:
                                    self.table.add_row(f'[bold red]Update suppressed[/bold red]{source}',
                                                       Text(name, no_wrap=True), Text(versionold, no_wrap=True))
                                else:
                                    self.table.add_row(f'[yellow]{"Updated" if update else "Update available"}'
                                                       f'[/yellow]{source}', Text(name, no_wrap=True),
                                                       Text(versionnew, style='yellow', no_wrap=True))
                        else:
                            self.table.add_row(f'[bold black]Not installed[/bold black]{source}',
                                               Text(addon, no_wrap=True), Text('', no_wrap=True))
                    except Exception as e:
                        exceptions.append(e)
                    progress.update(task, advance=1 if args else 0.5, refresh=True)
        if addline:
            self.console.print('')
        self.console.print(self.table)
        if compacted > 0:
            self.console.print(f'Additionally [green]{compacted}[/green] addons are up-to-date.')
        if len(addons) == 0:
            self.console.print('Apparently there are no addons installed by CurseBreaker.\n'
                               'Command [green]import[/green] might be used to detect already installed addons.')
        if len(exceptions) > 0:
            self.handle_exception(exceptions, False)