Created
August 13, 2023 00:49
-
-
Save developer-sdk/3ede5192967e9bcbc66838bb9c8d8988 to your computer and use it in GitHub Desktop.
ansi color code 제외
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def escape_ansi_color_pattern(ansi_text: str) -> str: | |
# 7-bit C1 ANSI sequences | |
ansi_escape = re.compile(r''' | |
\x1B # ESC | |
(?: # 7-bit C1 Fe (except CSI) | |
[@-Z\\-_] | |
| # or [ for CSI, followed by a control sequence | |
\[ | |
[0-?]* # Parameter bytes | |
[ -/]* # Intermediate bytes | |
[@-~] # Final byte | |
) | |
''', re.VERBOSE) | |
result = ansi_escape.sub('', ansi_text) | |
return result | |
if __name__ == '__main__': | |
stderr = r"""[31m╷[0m[0m | |
[31m│[0m [0m[1m[31mError: [0m[0m[1mError creating openstack_networking_port_v2: Bad request with: [POST https://network.openstack.io/v2.0/ports], error message: {"NeutronError": {"type": "HTTPBadRequest", "message": "Invalid input for network_id. Reason: 'a' is not a valid UUID.", "detail": ""}}[0m | |
[31m│[0m [0m | |
[31m│[0m [0m[0m with openstack_networking_port_v2.a, | |
[31m│[0m [0m on instance.tf line 1, in resource "openstack_networking_port_v2" "a": | |
[31m│[0m [0m 1: resource "openstack_networking_port_v2" "a" [4m{[0m[0m | |
[31m│[0m [0m | |
[31m╵[0m[0m""" | |
# print(stderr) | |
escape_error = escape_ansi_color_pattern(stderr) | |
errors = escape_error.split("\n") | |
error = "" | |
if len(errors) > 2: | |
error = errors[1] | |
print(error) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment