Exemplo n.º 1
0
    def status(self):
        if not (os.path.exists(self.restore_log_path) and os.path.isfile(self.restore_log_path)):
            cli_ui.warning('No restore log found!')
            sys.exit(0)  # FIXME: Don't exit, rather throw an exception

        restore_log = self._get_restore_log()

        if not self.rubrik:
            creds = self._read_credentials(ignore_stored=True, presets={'address': restore_log['cluster']['ip']})
            self._connect(creds)

        statuses = []

        for job in restore_log['jobs']:
            klass = config_class(job['configType'])
            status = klass(self.path, self.rubrik, logging.getLogger()).status(job)
            if status:
                statuses.append(status)

        status_rows = list(map(
            lambda s: [
                (status_color(s[0]), s[0]),
                (cli_ui.lightgray, s[1]),
                (cli_ui.lightgray, s[2]),
                (cli_ui.lightgray, s[3]),
                (cli_ui.bold, s[4])],
            statuses
        ))

        cli_ui.info('\nBackup Id:', cli_ui.turquoise, restore_log['backupId'], end='\n\n')
        cli_ui.info_table(status_rows, headers=['Status', 'Start time', 'End time', 'Type', 'Name'])
Exemplo n.º 2
0
 def display_bad_branches(self) -> None:
     if not self.bad_branches:
         return
     ui.error("Some projects were not on the correct branch")
     headers = ("project", "actual", "expected")
     data = [((ui.bold, name), (ui.red, actual), (ui.green, expected))
             for (name, actual, expected) in self.bad_branches]
     ui.info_table(data, headers=headers)
     raise BadBranches()
Exemplo n.º 3
0
def test_table_with_dict_no_color(dumb_tty: DumbTTY) -> None:
    data = {
        (cli_ui.bold, "Name"): [(cli_ui.green, "Alice"),
                                (cli_ui.green, "Bob")],
        (cli_ui.bold, "Age"): [(cli_ui.blue, 24), (cli_ui.blue, 9)],
    }
    cli_ui.info_table(data, headers="keys", fileobj=dumb_tty)
    actual = dumb_tty.getvalue()
    # fmt: off
    expected = ("Name      Age\n"
                "------  -----\n"
                "Alice      24\n"
                "Bob         9\n")
    # fmt: on
    assert actual == expected
Exemplo n.º 4
0
def test_table_with_lists_no_color(dumb_tty: DumbTTY) -> None:
    headers = ["name", "score"]
    data = [
        [(cli_ui.bold, "John"), (cli_ui.green, 10)],
        [(cli_ui.bold, "Jane"), (cli_ui.green, 5)],
    ]
    cli_ui.info_table(data, headers=headers, fileobj=dumb_tty)
    actual = dumb_tty.getvalue()
    # fmt: off
    expected = ("name      score\n"
                "------  -------\n"
                "John         10\n"
                "Jane          5\n")
    # fmt: on
    assert actual == expected
Exemplo n.º 5
0
def test_table_with_lists_with_color(smart_tty: SmartTTY) -> None:
    headers = ["name", "score"]
    data = [
        [(cli_ui.bold, "John"), (cli_ui.green, 10)],
        [(cli_ui.bold, "Jane"), (cli_ui.green, 5)],
    ]
    cli_ui.info_table(data, headers=headers, fileobj=smart_tty)
    actual = smart_tty.getvalue()
    # fmt: off
    expected = ("name      score\n"
                "------  -------\n"
                f"{BRIGHT}John{RESET_ALL}         {GREEN}10{RESET_ALL}\n"
                f"{BRIGHT}Jane{RESET_ALL}          {GREEN}5{RESET_ALL}\n")
    # fmt: on
    assert actual == expected
Exemplo n.º 6
0
def test_table_with_dict_and_color(smart_tty: SmartTTY) -> None:
    data = {
        (
            cli_ui.bold,
            "Name",
        ): [(cli_ui.green, "Alice"), (cli_ui.green, "Bob")],
        (
            cli_ui.bold,
            "Age",
        ): [(cli_ui.blue, 24), (cli_ui.blue, 9)],
    }
    cli_ui.info_table(data, headers="keys", fileobj=smart_tty)
    actual = smart_tty.getvalue()
    # fmt: off
    expected = (f"{BRIGHT}Name{RESET_ALL}      {BRIGHT}Age{RESET_ALL}\n"
                "------  -----\n"
                f"{GREEN}Alice{RESET_ALL}      {BLUE}24{RESET_ALL}\n"
                f"{GREEN}Bob{RESET_ALL}         {BLUE}9{RESET_ALL}\n")
    # fmt: on
    assert actual == expected
Exemplo n.º 7
0
            os.mkdir(sc_path_reports)
            cli_ui.info_3("Directory ", sc_path_reports, " Created ")
        except FileExistsError:
            cli_ui.info_3("Directory ", sc_path_reports, " already exists")

        ts = calendar.timegm(time.gmtime())
        verifyJS(results.url, ts)
        print('\n' * 2)
        cli_ui.info_section("RESULTADO")
        cli_ui.info_1("URL: " + str(results.url))
        cli_ui.info_1("ARCHIVOS ENCONTRADOS EN VIRUS TOTAL: " + str(vt_count))

        if (vt_count > 0):
            print('\n' * 2)
            cli_ui.info_section("DETALLE")
            cli_ui.info_table(data_final, headers=headers)

        if (vt_upload_count > 0):
            print('\n' * 2)
            cli_ui.info_section("DETALLE ARCHIVOS ENVIADOS A VIRUS TOTAL")
            cli_ui.info(
                cli_ui.darkblue,
                "NOTA: ESTOS ARCHIVOS HAN SIDO ENVIADOS A ANALIZAR A VIRUS TOTAL."
            )

            cli_ui.info_table(data_files_vt, headers=headers_vt_files)
    else:
        cli_ui.warning(
            'No option was selected. To check CLI options, run script in help mode: \'{} -h\''
            .format(__file__))