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 29try: 30 from pw_env_setup.colors import Color, enable_colors 31except ImportError: 32 # Load from this directory if pw_env_setup is not available. 33 from colors import Color, enable_colors # type: ignore 34 35 36_PIGWEED_BANNER = u''' 37 ▒█████▄ █▓ ▄███▒ ▒█ ▒█ ░▓████▒ ░▓████▒ ▒▓████▄ 38 ▒█░ █░ ░█▒ ██▒ ▀█▒ ▒█░ █ ▒█ ▒█ ▀ ▒█ ▀ ▒█ ▀█▌ 39 ▒█▄▄▄█░ ░█▒ █▓░ ▄▄░ ▒█░ █ ▒█ ▒███ ▒███ ░█ █▌ 40 ▒█▀ ░█░ ▓█ █▓ ░█░ █ ▒█ ▒█ ▄ ▒█ ▄ ░█ ▄█▌ 41 ▒█ ░█░ ░▓███▀ ▒█▓▀▓█░ ░▓████▒ ░▓████▒ ▒▓████▀ 42''' 43 44 45def print_banner(bootstrap, no_shell_file): 46 """Print the Pigweed or project-specific banner""" 47 enable_colors() 48 49 print(Color.green('\n WELCOME TO...')) 50 51 banner_file = os.environ.get('PW_BRANDING_BANNER', None) 52 banner_str = None 53 if banner_file: 54 try: 55 banner_str = open( 56 banner_file, 'r', encoding='utf-8', errors='replace' 57 ).read() 58 except FileNotFoundError: 59 pass 60 if banner_str: 61 print() 62 print(banner_str, end='') 63 else: 64 print(Color.magenta(_PIGWEED_BANNER), end='') 65 66 if bootstrap: 67 print( 68 Color.green( 69 '\n BOOTSTRAP! Bootstrap may take a few minutes; ' 70 'please be patient' 71 ) 72 ) 73 print( 74 Color.green( 75 ' On Windows, this stage is extremely slow (~10 minutes).\n' 76 ) 77 ) 78 else: 79 print( 80 Color.green( 81 '\n ACTIVATOR! This sets your console environment variables.\n' 82 ) 83 ) 84 85 if no_shell_file: 86 print(Color.bold_red('Error!\n')) 87 print( 88 Color.red( 89 ' Your Pigweed environment does not seem to be' 90 ' configured.' 91 ) 92 ) 93 print(Color.red(' Run bootstrap.bat to perform initial setup.')) 94 95 return 0 96 97 98def parse(): 99 """Parse command-line arguments.""" 100 parser = argparse.ArgumentParser( 101 prog="python -m pw_env_setup.windows_env_start" 102 ) 103 parser.add_argument('--bootstrap', action='store_true') 104 parser.add_argument('--no-shell-file', action='store_true') 105 return parser.parse_args() 106 107 108def main(): 109 """Script entry point.""" 110 if os.name != 'nt': 111 return 1 112 return print_banner(**vars(parse())) 113 114 115if __name__ == '__main__': 116 sys.exit(main()) 117