Fix for x86_64 build fail
[platform/upstream/connectedhomeip.git] / third_party / pigweed / repo / pw_cli / py / pw_cli / branding.py
1 # Copyright 2020 The Pigweed Authors
2 #
3 # Licensed under the Apache License, Version 2.0 (the "License"); you may not
4 # use this file except in compliance with the License. You may obtain a copy of
5 # the License at
6 #
7 #     https://www.apache.org/licenses/LICENSE-2.0
8 #
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11 # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12 # License for the specific language governing permissions and limitations under
13 # the License.
14 """Facilities for accessing the current Pigweed branding"""
15
16 from typing import Optional
17 from pathlib import Path
18
19 import pw_cli.env
20 import pw_cli.color
21
22 _memoized_banner: Optional[str] = None
23
24 # This is the default banner for Pigweed.
25 _PIGWEED_BANNER = '''
26  ▒█████▄   █▓  ▄███▒  ▒█    ▒█ ░▓████▒ ░▓████▒ ▒▓████▄
27   ▒█░  █░ ░█▒ ██▒ ▀█▒ ▒█░ █ ▒█  ▒█   ▀  ▒█   ▀  ▒█  ▀█▌
28   ▒█▄▄▄█░ ░█▒ █▓░ ▄▄░ ▒█░ █ ▒█  ▒███    ▒███    ░█   █▌
29   ▒█▀     ░█░ ▓█   █▓ ░█░ █ ▒█  ▒█   ▄  ▒█   ▄  ░█  ▄█▌
30   ▒█      ░█░ ░▓███▀   ▒█▓▀▓█░ ░▓████▒ ░▓████▒ ▒▓████▀
31 '''
32
33
34 def banner():
35     global _memoized_banner  # pylint: disable=global-statement
36     if _memoized_banner is not None:
37         return _memoized_banner
38
39     parsed_env = pw_cli.env.pigweed_environment()
40
41     # Take the banner from the file PW_BRANDING_BANNER; or use the default.
42     banner_filename = parsed_env.PW_BRANDING_BANNER
43     _memoized_banner = (Path(banner_filename).read_text()
44                         if banner_filename else _PIGWEED_BANNER)
45
46     # Color the banner if requested.
47     banner_color = parsed_env.PW_BRANDING_BANNER_COLOR
48     if banner_color != '':
49         _memoized_banner = getattr(
50             pw_cli.color.colors(),
51             banner_color,
52             str,
53         )(_memoized_banner)
54
55     return _memoized_banner