Ejemplo n.º 1
0
def test_find_docker_not_installed(fake_process):
    def raise_FNF(process):
        raise FileNotFoundError

    fake_process.register_subprocess(["docker", "inspect", "pihole"],
                                     stdout="not running FNF",
                                     callback=raise_FNF)
    result = utils.find_docker()
    assert result == [False, None]

    def raise_CPE(process):
        raise CalledProcessError(returncode=1, cmd="test")

    fake_process.register_subprocess(["docker", "inspect", "pihole"],
                                     stdout="not running CPE",
                                     callback=raise_CPE)
    result = utils.find_docker()
    assert result == [False, None]
Ejemplo n.º 2
0
def main():
    """main method"""
    try:
        utils.clear()
        print(color('    ┌──────────────────────────────────────────┐', fg='#b61042'))
        print(color('    │       ', fg='#b61042') +
              color(f'π-hole 5 list tool  v{__version__}', '#FFF') + color('         │', fg='#b61042'))
        print(color('    └──────────────────────────────────────────┘', fg='#b61042'))
        utils.info('    https://github.com/jessedp/pihole5-list-tool\n')
        utils.danger('    Do not hit ENTER or Y if a step seems to hang!')
        utils.danger("    Use CTRL+C if you're sure it's hung and report it.\n")

        db_file = ''
        use_docker = False
        docker = utils.find_docker()

        if docker[0] is True:
            utils.success(f'Found Running Docker config: {docker[1]}')
            use_docker = inquirer.confirm('Use Docker-ized config?', 'n')
            if use_docker:
                db_file = docker[1]

        if not use_docker:
            db_file = inquirer.ask_db()

        list_type = inquirer.ask_list_type()

        if list_type == constants.BLACKLIST:
            process_blacklists(db_file)

        if list_type == constants.WHITELIST:
            process_whitelists(db_file)

        if inquirer.confirm('Update Gravity for immediate effect?'):
            print()
            if use_docker:
                os.system('docker exec pihole bash "/usr/local/bin/pihole" "-g"')
            else:
                os.system('pihole -g')
        else:
            if use_docker:
                utils.info('Update Gravity through the web interface or by running:\n\t' +
                           '# docker exec pihole bash "/usr/local/bin/pihole" "-g"')

            else:
                utils.info(
                    'Update Gravity through the web interface or by running:\n\t# pihole -g')

            utils.info('\n\tBye!')

    except (KeyboardInterrupt, KeyError):
        sys.exit(0)
Ejemplo n.º 3
0
def BROKEN_test_find_docker_image_found(fake_process, shared_datadir):
    """ Not actually launching mock process """
    path = "/home/jesse/projects/pihole/etc-pihole"

    output = (shared_datadir /
              "docker_inspect_pihole.json").read_text().strip()

    fake_process.register_subprocess(
        ["docker", "inspect", "pihole"],
        stdout=output,
    )

    result = utils.find_docker()
    # os.path.exists.assert_called_once_with(path)

    assert result == [True, path]
Ejemplo n.º 4
0
def BROKEN_test_find_docker_image_not_found(fake_process):
    """ Not actually launching mock process """
    fake_process.register_subprocess(["docker", "inspect", "pihole"],
                                     stdout="bad json")
    result = utils.find_docker()
    assert result == [False, None]
Ejemplo n.º 5
0
def test_find_docker_image_not_running(fake_process):
    fake_process.register_subprocess(["docker", "inspect", "pihole"],
                                     stdout="not running",
                                     returncode=1)
    result = utils.find_docker()
    assert result == [False, None]
Ejemplo n.º 6
0
def main():
    """main method"""
    try:
        utils.clear()
        print(
            color("    ┌──────────────────────────────────────────┐",
                  fg="#b61042"))
        print(
            color("    │       ", fg="#b61042") +
            color(f"π-hole 5 list tool  v{__version__}", "#FFF") +
            color("         │", fg="#b61042"))
        print(
            color("    └──────────────────────────────────────────┘",
                  fg="#b61042"))
        utils.info("    https://github.com/jessedp/pihole5-list-tool\n")

        db_file = ""
        use_docker = False
        docker = utils.find_docker()

        if docker[0] is True:
            utils.success(f"Found Running Docker config: {docker[1]}")
            use_docker = inquirer.confirm("Use Docker-ized config?", "n")
            if use_docker:
                db_file = docker[1]

        if not use_docker:
            db_file = inquirer.ask_db()

        list_type = inquirer.ask_list_type()

        print()
        utils.danger("    Do not hit ENTER or Y if a step seems to hang!")
        utils.danger(
            "    Use CTRL+C if you're sure it's hung and report it.\n")

        if list_type == constants.BLOCKLIST:
            process_blocklists(db_file)

        if list_type == constants.ALLOWLIST:
            process_allowlists(db_file)

        if inquirer.confirm("Update Gravity for immediate effect?"):
            print()
            if use_docker:
                os.system(
                    'docker exec pihole bash "/usr/local/bin/pihole" "-g"')
            else:
                os.system("pihole -g")
        else:
            if use_docker:
                utils.info(
                    "Update Gravity through the web interface or by running:\n\t"
                    + '# docker exec pihole bash "/usr/local/bin/pihole" "-g"')

            else:
                utils.info(
                    "Update Gravity through the web interface or by running:\n\t# pihole -g"
                )

            utils.info("\n\tBye!")

    except (KeyboardInterrupt, KeyError):
        sys.exit(0)