Example #1
0
    def deploy(self, promote=False, quiet=False):
        # type: (bool, bool, bool) -> None
        """ Deploy the code to AppEngine.

        Args:
            promote (bool):
                Migrate the traffic to the deployed version.
            quiet (bool):
                Pass ``--quiet`` flag to gcloud command
        """
        args = [
            '--promote' if promote else '--no-promote',
            '--version {}'.format(self.app_version),
            '--project {}'.format(self.app_id),
        ]

        if quiet:
            args += ['--quiet']

        cmd = 'gcloud app deploy {args} {deployables}'.format(
            deployables=fs.wrap_paths(self.deployables), args=' '.join(args))

        if context.get('pretend', False):
            log.info("Would deploy version <35>{ver}<32> to <35>{app}".format(
                ver=self.app_version, app=self.app_id))
            shell.cprint('<90>{}', cmd)
        else:
            log.info("Deploying version <35>{ver}<32> to <35>{app}".format(
                ver=self.app_version,
                app=self.app_id,
            ))
            shell.run(cmd)
Example #2
0
    def get_value(self, field: Field, quick: bool) -> Any:
        """ Ask user the question represented by this instance.

        Args:
            field (Field):
                The field we're asking the user to provide the value for.
            quick (bool):
                Enable quick mode. In quick mode, the form will reduce the
                number of question asked by using defaults wherever possible.
                This can greatly reduce the number of interactions required on
                the user part, but will obviously limit the user choices. This
                should probably be enabled only by a specific user action
                (like passing a ``--quick`` flag etc.).

        Returns:
            The user response converted to a python type using the
            :py:attr:`cliform.core.Field.type` converter.
        """
        if callable(field.default):
            default = field.default(self)
        else:
            default = field.default

        if quick and default is not None:
            return default

        shell.cprint('<90>{}', field.help)

        while True:
            try:
                answer = click.prompt(field.pretty_prompt, default=default)
                return field.type(answer)
            except ValueError:
                shell.cprint("<31>Unsupported value")
Example #3
0
    def set_pretend(     # pylint: disable=missing-docstring
        ctx: click.Context,
        param: Union[click.Option, click.Parameter],
        value: Any
    ) -> Any:
        from peltak.core import context
        from peltak.core import shell

        context.set('pretend', value or False)
        if value:
            shell.cprint('<90>{}', _pretend_msg())
Example #4
0
def changelog_cli(ctx: click.Context, start_rev: str, end_rev: str,
                  title: str) -> None:
    """ Generate changelog from commit messages. """
    if ctx.invoked_subcommand:
        return

    from peltak.core import shell
    from . import logic

    changelog = logic.changelog(start_rev=start_rev,
                                end_rev=end_rev,
                                title=title)
    shell.cprint(changelog)
Example #5
0
def extract_from_files(files: List[str]) -> List[Todo]:
    todos: List[Todo] = []

    for path in files:
        file_todos = _process_file(path)
        todos += file_todos

        if context.get('verbose') >= 1:
            if len(file_todos) > 0:
                shell.cprint(
                    "    <33>{:2} <32>TODOs in <90>{}".format(len(file_todos), path)
                )
            else:
                shell.cprint("    <32>No TODOs in <90>{}".format(path))

    return todos
Example #6
0
def choose_branch(exclude: Optional[Iterable[str]] = None) -> str:
    """ Show the user a menu to pick a branch from the existing ones.

    Args:
        exclude (list[str]):
            List of branch names to exclude from the menu. By default it will
            exclude master and develop branches. To show all branches pass an
            empty array here.

    Returns:
        str: The name of the branch chosen by the user. If the user inputs an
        invalid choice, he will be asked again (and again) until he picks a
        a valid branch.
    """
    if exclude is None:
        master = conf.get('git.master_branch', 'master')
        develop = conf.get('git.devel_branch', 'develop')
        exclude = {master, develop}

    branches = list(set(git.branches()) - set(exclude))

    # Print the menu
    for i, branch_name in enumerate(branches):
        shell.cprint('<90>[{}] <33>{}'.format(i + 1, branch_name))

    # Get a valid choice from the user
    choice = 0
    while choice < 1 or choice > len(branches):
        prompt = "Pick a base branch from the above [1-{}]".format(
            len(branches))
        choice = click.prompt(prompt, value_proc=int)  # type: ignore
        if not (1 <= choice <= len(branches)):
            fmt = "Invalid choice {}, you must pick a number between {} and {}"
            log.err(fmt.format(choice, 1, len(branches)))

    return branches[choice - 1]
Example #7
0
def _render_todos(todos: List[Todo]) -> None:
    print('\n')
    for file_path, file_todos in itertools.groupby(todos,
                                                   key=lambda x: x.file):
        shell.cprint(f"<92>{file_path}\n")
        for todo in sorted(file_todos, key=lambda x: x.lines.start):
            if context.get('verbose') >= 1:
                shell.cprint(
                    f"<36>{todo.pretty_timestamp}  <33>{todo.author}<0>\n"
                    f"<95>{todo.file}:{todo.lines}  <90>{todo.sha1}<0>\n\n"
                    f"{textwrap.indent(todo.color_text, '  ')}\n\n")
            else:
                shell.cprint(
                    f"    <95>:{todo.lines}  <36>{todo.pretty_timestamp}  "
                    f"<33>{todo.author_email}  <90>{todo.sha1}<0><0>\n\n"
                    f"{textwrap.indent(todo.color_text, '        ')}\n")
        print()

    log.info(f"Found <33>{len(todos)}<32> TODOs")
Example #8
0
def test_formatting_works(p_fmt, msg, args, kw, expected):
    shell.cprint(msg, *args, **kw)

    p_fmt.assert_called_once_with(expected)
Example #9
0
def test_clears_formatting_at_the_end_of_each_call(p_fmt, msg, expected):
    shell.cprint(msg)

    p_fmt.assert_called_once_with(expected)