forked from analogdevicesinc/ai8x-synthesis
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patheprint.py
36 lines (29 loc) · 1.16 KB
/
eprint.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
###################################################################################################
# Copyright (C) Maxim Integrated Products, Inc. All Rights Reserved.
#
# Maxim Integrated Products, Inc. Default Copyright Notice:
# https://www.maximintegrated.com/en/aboutus/legal/copyrights.html
###################################################################################################
"""
Print error message to stderr, and stdout as well if needed
"""
import sys
def eprint(*args, error=True, prefix=True, **kwargs):
"""
Print message to stderr, and stdout as well IF stdout was overridden.
Add a `prefix` if set (and `error` chooses which).
"""
if prefix:
pfx = 'ERROR:' if error else 'WARNING:'
if sys.stdout != sys.__stdout__:
print(pfx, *args, **kwargs)
print(pfx, *args, file=sys.stderr, **kwargs)
else:
if sys.stdout != sys.__stdout__:
print(*args, **kwargs)
print(*args, file=sys.stderr, **kwargs)
def eprint_noprefix(*args, **kwargs):
"""
Print message to stderr, and stdout as well IF stdout was overridden.
"""
eprint(*args, prefix=False, **kwargs)