Example #1
0
def announce(base_parameters, receiver_email: str):
    """
    Send email to announce release of the new version
    """
    receiver_emails: List[str] = string_comma_to_list(receiver_email)

    template_file = "templates/announce_email.j2"
    base_parameters.template_arguments["receiver_email"] = receiver_emails
    message = render_template(template_file,
                              **base_parameters.template_arguments)

    inter_send_email(
        base_parameters.username,
        base_parameters.password,
        base_parameters.template_arguments["sender_email"],
        base_parameters.template_arguments["receiver_email"],
        message,
    )

    if click.confirm("Show Slack message for announcement?", default=True):
        base_parameters.template_arguments["slack_rc"] = False
        slack_msg = render_template("templates/slack.j2",
                                    **base_parameters.template_arguments)
        show_message("Slack", slack_msg)
    if click.confirm("Show Twitter message for announcement?", default=True):
        twitter_msg = render_template("templates/twitter.j2",
                                      **base_parameters.template_arguments)
        show_message("Twitter", twitter_msg)
Example #2
0
def cleanup(verbose: bool, dry_run: bool):
    console.print("\n[bright_yellow]Removing cache of parameters, images, and cleans up docker cache[/]")
    if click.confirm("Are you sure?"):
        docker_images_command_to_execute = [
            'docker',
            'images',
            '--filter',
            'label=org.apache.airflow.image',
            '--format',
            '{{.Repository}}:{{.Tag}}',
        ]
        process = run_command(
            docker_images_command_to_execute, verbose=verbose, text=True, capture_output=True
        )
        images = process.stdout.splitlines() if process and process.stdout else []
        if images:
            console.print("[light_blue]Removing images:[/]")
            for image in images:
                console.print(f"[light_blue] * {image}[/]")
            console.print()
            docker_rmi_command_to_execute = [
                'docker',
                'rmi',
                '--force',
            ]
            docker_rmi_command_to_execute.extend(images)
            run_command(docker_rmi_command_to_execute, verbose=verbose, dry_run=dry_run, check=False)
        else:
            console.print("[light_blue]No images to remote[/]\n")
        system_prune_command_to_execute = ['docker', 'system', 'prune']
        console.print("Pruning docker images")
        run_command(system_prune_command_to_execute, verbose=verbose, dry_run=dry_run, check=False)
        console.print(f"Removing build cache dir ${BUILD_CACHE_DIR}")
        if not dry_run:
            shutil.rmtree(BUILD_CACHE_DIR, ignore_errors=True)
Example #3
0
def setup_autocomplete():
    """
    Enables autocompletion of Breeze2 commands.
    Functionality: By default the generated shell scripts will be available in ./dev/breeze/autocomplete/ path
    Depending on the shell type in the machine we have to link it to the corresponding file
    """
    global NAME
    breeze_comment = "Added by Updated Airflow Breeze autocomplete setup"
    # Determine if the shell is bash/zsh/powershell. It helps to build the autocomplete path
    shell = click_completion.get_auto_shell()
    click.echo(f"Installing {shell} completion for local user")
    extra_env = {'_CLICK_COMPLETION_COMMAND_CASE_INSENSITIVE_COMPLETE': 'ON'}
    autocomplete_path = Path(
        AIRFLOW_SOURCES_DIR
    ) / ".build/autocomplete" / f"{NAME}-complete.{shell}"
    shell, path = click_completion.core.install(shell=shell,
                                                prog_name=NAME,
                                                path=autocomplete_path,
                                                append=False,
                                                extra_env=extra_env)
    click.echo(
        f"Activation command scripts are created in this autocompletion path: {autocomplete_path}"
    )
    if click.confirm(
            f"Do you want to add the above autocompletion scripts to your {shell} profile?"
    ):
        if shell == 'bash':
            script_path = Path('~').expanduser() / '.bash_completion'
            command_to_execute = f"source {autocomplete_path}"
            write_to_shell(command_to_execute, script_path, breeze_comment)
        elif shell == 'zsh':
            script_path = Path('~').expanduser() / '.zshrc'
            command_to_execute = f"source {autocomplete_path}"
            write_to_shell(command_to_execute, script_path, breeze_comment)
        elif shell == 'fish':
            # Include steps for fish shell
            script_path = Path(
                '~').expanduser() / f'.config/fish/completions/{NAME}.fish'
            with open(path) as source_file, open(script_path,
                                                 'w') as destination_file:
                for line in source_file:
                    destination_file.write(line)
        else:
            # Include steps for powershell
            subprocess.check_call([
                'powershell',
                'Set-ExecutionPolicy Unrestricted -Scope CurrentUser'
            ])
            script_path = subprocess.check_output(
                ['powershell', '-NoProfile', 'echo $profile']).strip()
            command_to_execute = f". {autocomplete_path}"
            write_to_shell(command_to_execute, script_path.decode("utf-8"),
                           breeze_comment)
    else:
        click.echo(
            f"Link for manually adding the autocompletion script to {shell} profile"
        )
Example #4
0
def setup_autocomplete(verbose: bool, dry_run: bool, force: bool):
    """
    Enables autocompletion of Breeze2 commands.
    """

    # Determine if the shell is bash/zsh/powershell. It helps to build the autocomplete path
    detected_shell = os.environ.get('SHELL')
    detected_shell = None if detected_shell is None else detected_shell.split(os.sep)[-1]
    if detected_shell not in ['bash', 'zsh', 'fish']:
        console.print(f"\n[red] The shell {detected_shell} is not supported for autocomplete![/]\n")
        sys.exit(1)
    console.print(f"Installing {detected_shell} completion for local user")
    autocomplete_path = (
        AIRFLOW_SOURCES_ROOT / "dev" / "breeze" / "autocomplete" / f"{NAME}-complete-{detected_shell}.sh"
    )
    console.print(f"[bright_blue]Activation command script is available here: {autocomplete_path}[/]\n")
    console.print(
        f"[bright_yellow]We need to add above script to your {detected_shell} profile and "
        "install 'click' package in your default python installation destination.[/]\n"
    )
    if click.confirm("Should we proceed ?"):
        run_command(['pip', 'install', '--upgrade', 'click'], verbose=True, dry_run=dry_run, check=False)
        if detected_shell == 'bash':
            script_path = str(Path('~').expanduser() / '.bash_completion')
            command_to_execute = f"source {autocomplete_path}"
            write_to_shell(command_to_execute, dry_run, script_path, force)
        elif detected_shell == 'zsh':
            script_path = str(Path('~').expanduser() / '.zshrc')
            command_to_execute = f"source {autocomplete_path}"
            write_to_shell(command_to_execute, dry_run, script_path, force)
        elif detected_shell == 'fish':
            # Include steps for fish shell
            script_path = str(Path('~').expanduser() / f'.config/fish/completions/{NAME}.fish')
            if os.path.exists(script_path) and not force:
                console.print(
                    "\n[bright_yellow]Autocompletion is already setup. Skipping. "
                    "You can force autocomplete installation by adding --force/]\n"
                )
            else:
                with open(autocomplete_path) as source_file, open(script_path, 'w') as destination_file:
                    for line in source_file:
                        destination_file.write(line)
        else:
            # Include steps for powershell
            subprocess.check_call(['powershell', 'Set-ExecutionPolicy Unrestricted -Scope CurrentUser'])
            script_path = (
                subprocess.check_output(['powershell', '-NoProfile', 'echo $profile']).decode("utf-8").strip()
            )
            command_to_execute = f". {autocomplete_path}"
            write_to_shell(command_to_execute, dry_run, script_path, force)
    else:
        console.print(
            "\nPlease follow the https://click.palletsprojects.com/en/8.1.x/shell-completion/ "
            "to setup autocompletion for breeze manually if you want to use it.\n"
        )
Example #5
0
def inter_send_email(username: str, password: str, sender_email: str,
                     receiver_email: Union[str, List], message: str):
    """
    Send email using SMTP
    """
    show_message("SMTP", message)

    click.confirm("Is the Email message ok?", abort=True)

    try:
        send_email(
            SMTP_SERVER,
            SMTP_PORT,
            username,
            password,
            sender_email,
            receiver_email,
            message,
        )
        click.secho("✅ Email sent successfully", fg="green")
    except smtplib.SMTPAuthenticationError:
        sys.exit("SMTP User authentication error, Email not sent!")
    except Exception as e:
        sys.exit(f"SMTP exception {e}")
Example #6
0
def vote(base_parameters, receiver_email: str):
    """
    Send email calling for Votes on RC
    """
    template_file = "templates/vote_email.j2"
    base_parameters.template_arguments["receiver_email"] = receiver_email
    message = render_template(template_file,
                              **base_parameters.template_arguments)
    inter_send_email(
        base_parameters.username,
        base_parameters.password,
        base_parameters.template_arguments["sender_email"],
        base_parameters.template_arguments["receiver_email"],
        message,
    )
    if click.confirm("Show Slack message for announcement?", default=True):
        base_parameters.template_arguments["slack_rc"] = False
        slack_msg = render_template("templates/slack.j2",
                                    **base_parameters.template_arguments)
        show_message("Slack", slack_msg)