• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# -*- coding: utf-8 -*-
2
3# Copyright 2020 The Pigweed Authors
4#
5# Licensed under the Apache License, Version 2.0 (the "License"); you may not
6# use this file except in compliance with the License. You may obtain a copy of
7# the License at
8#
9#     https://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14# License for the specific language governing permissions and limitations under
15# the License.
16"""Prints the env_setup banner for cmd.exe.
17
18This is done from Python as activating colors and printing ASCII art are not
19easy to do in cmd.exe. Activated colors also don't persist in the parent
20process.
21"""
22
23from __future__ import print_function
24
25import argparse
26import os
27import sys
28
29from .colors import Color, enable_colors  # type: ignore
30
31_PIGWEED_BANNER = u'''
32 ▒█████▄   █▓  ▄███▒  ▒█    ▒█ ░▓████▒ ░▓████▒ ▒▓████▄
33  ▒█░  █░ ░█▒ ██▒ ▀█▒ ▒█░ █ ▒█  ▒█   ▀  ▒█   ▀  ▒█  ▀█▌
34  ▒█▄▄▄█░ ░█▒ █▓░ ▄▄░ ▒█░ █ ▒█  ▒███    ▒███    ░█   █▌
35  ▒█▀     ░█░ ▓█   █▓ ░█░ █ ▒█  ▒█   ▄  ▒█   ▄  ░█  ▄█▌
36  ▒█      ░█░ ░▓███▀   ▒█▓▀▓█░ ░▓████▒ ░▓████▒ ▒▓████▀
37'''
38
39
40def print_banner(bootstrap, no_shell_file):
41    """Print the Pigweed or project-specific banner"""
42    enable_colors()
43
44    print(Color.green('\n  WELCOME TO...'))
45    print(Color.magenta(_PIGWEED_BANNER))
46
47    if bootstrap:
48        print(
49            Color.green('\n  BOOTSTRAP! Bootstrap may take a few minutes; '
50                        'please be patient'))
51        print(
52            Color.green(
53                '  On Windows, this stage is extremely slow (~10 minutes).\n'))
54    else:
55        print(
56            Color.green(
57                '\n  ACTIVATOR! This sets your console environment variables.\n'
58            ))
59
60        if no_shell_file:
61            print(Color.bold_red('Error!\n'))
62            print(
63                Color.red('  Your Pigweed environment does not seem to be'
64                          ' configured.'))
65            print(Color.red('  Run bootstrap.bat to perform initial setup.'))
66
67    return 0
68
69
70def parse():
71    """Parse command-line arguments."""
72    parser = argparse.ArgumentParser()
73    parser.add_argument('--bootstrap', action='store_true')
74    parser.add_argument('--no-shell-file', action='store_true')
75    return parser.parse_args()
76
77
78def main():
79    """Script entry point."""
80    if os.name != 'nt':
81        return 1
82    return print_banner(**vars(parse()))
83
84
85if __name__ == '__main__':
86    sys.exit(main())
87