Skip to content

blag.quickstart

Helper methods for blag's quickstart command.

copy_default_theme()

Copy default theme into current directory.

The default theme contains the 'templates', 'content' and 'static' directories shipped with blag.

It will not overwrite existing files.

Source code in blag/quickstart.py
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
def copy_default_theme() -> None:
    """Copy default theme into current directory.

    The default theme contains the 'templates', 'content' and 'static'
    directories shipped with blag.

    It will not overwrite existing files.

    """
    print("Copying default theme...")
    for dir_ in "templates", "content", "static":
        print(f"  Copying {dir_}...")
        try:
            shutil.copytree(
                os.path.join(blag.__path__[0], dir_),
                dir_,
            )
        except FileExistsError:
            print(f"  {dir_} already exist. Skipping.")

get_input(question, default)

Prompt for user input.

This is a wrapper around the input-builtin. It will show the default answer in the prompt and -- if no answer was given -- use the default.

Parameters:

Name Type Description Default
question str

the question the user is presented

required
default str

the default value that will be used if no answer was given

required

Returns:

Type Description
str

the answer

Source code in blag/quickstart.py
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
def get_input(question: str, default: str) -> str:
    """Prompt for user input.

    This is a wrapper around the input-builtin. It will show the default answer
    in the prompt and -- if no answer was given -- use the default.

    Parameters
    ----------
    question
        the question the user is presented
    default
        the default value that will be used if no answer was given

    Returns
    -------
    str
        the answer

    """
    reply = input(f"{question} [{default}]: ")
    if not reply:
        reply = default
    return reply

quickstart(args)

Quickstart.

This method asks the user some questions and generates a configuration file that is needed in order to run blag. Additionally, it creates the content and static directories with some initial content, to get the user started.

Parameters:

Name Type Description Default
args Namespace | None

not used

required
Source code in blag/quickstart.py
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
def quickstart(args: argparse.Namespace | None) -> None:
    """Quickstart.

    This method asks the user some questions and generates a configuration file
    that is needed in order to run blag. Additionally, it creates the content
    and static directories with some initial content, to get the user started.

    Parameters
    ----------
    args
        not used

    """
    base_url = get_input(
        "Hostname (and path) to the root?",
        "https://example.com/",
    )
    title = get_input(
        "Title of your website?",
        "My little blog",
    )
    description = get_input(
        "Description of your website?",
        "John Doe's Blog",
    )
    author = get_input(
        "Author of your website",
        "John Doe",
    )

    config = configparser.ConfigParser()
    config["main"] = {
        "base_url": base_url,
        "title": title,
        "description": description,
        "author": author,
    }
    with open("config.ini", "w") as fh:
        config.write(fh)

    copy_default_theme()