log.py
Go to the documentation of this file.
1 # License: Apache 2.0. See LICENSE file in root directory.
2 # Copyright(c) 2021 Intel Corporation. All Rights Reserved.
3 
4 import sys
5 
6 
7 # Set up the default output system; if not a terminal, disable colors!
8 def _stream_has_color( stream ):
9  if not hasattr(stream, "isatty"):
10  return False
11  if not stream.isatty():
12  return False # auto color only on TTYs
13  try:
14  import curses
15  curses.setupterm()
16  return curses.tigetnum( "colors" ) > 2
17  except:
18  # guess false in case of error
19  return False
20 
21 _have_color = '--color' in sys.argv
22 if _have_color:
23  sys.argv.remove( '--color' )
24 else:
25  _have_color = _stream_has_color( sys.stdout )
26 if _have_color:
27  red = '\033[91m'
28  yellow = '\033[93m'
29  gray = '\033[90m'
30  reset = '\033[0m'
31  cr = '\033[G'
32  clear_eos = '\033[J'
33  clear_eol = '\033[K'
34  _progress = ''
35  def out( *args, sep = ' ', end = '\n' ):
36  global _progress
37  clear_to_eol = end and end[-1] == '\n' and len(_progress) > 0
38  if clear_to_eol:
39  print( *args, sep = sep, end = clear_eol + end )
40  progress( *_progress )
41  else:
42  print( *args, sep = sep, end = end )
43  def progress(*args):
44  global _progress
45  sys.stdout.write( '\0337' ) # save cursor
46  print( *args, end = clear_eol )
47  sys.stdout.write( '\0338' ) # restore cursor
48  _progress = args
49 else:
50  red = yellow = gray = reset = cr = clear_eos = ''
51  def out( *args, sep = ' ', end = '\n' ):
52  print( *args, sep = sep, end = end )
53  def progress(*args):
54  print( *args )
55 
57  global _have_color
58  return _have_color
59 
60 
61 def quiet_on():
62  global out
63  def out(*args):
64  pass
65 
66 
67 _verbose_on = False
68 def v(*args):
69  pass
70 def verbose_on():
71  global v, _verbose_on
72  def v(*args):
73  global gray, reset
74  out( gray + '-V-', *args, reset )
75  _verbose_on = True
77  global _verbose_on
78  return _verbose_on
79 
80 
81 _debug_on = False
82 _debug_indent = ''
83 def d(*args):
84  # Return whether info was output
85  return False
86 def debug_on():
87  global d, _debug_on, _debug_indent
88  def d( *args ):
89  global gray, reset
90  out( gray, '-D- ', _debug_indent, sep = '', end = '' ) # continue in next statement
91  out( *args, end = reset + '\n' )
92  return True
93  _debug_on = True
95  global _debug_on
96  return _debug_on
97 if '--debug' in sys.argv:
98  sys.argv.remove( '--debug' )
99  debug_on()
100 def debug_indent( n = 1, indentation = ' ' ):
101  global _debug_indent
102  _debug_indent += n * indentation
103 def debug_unindent( n = 1, indentation = ' ' ):
104  global _debug_indent
105  _debug_indent = _debug_indent[:-n * len(indentation)]
106 
107 
108 def i( *args ):
109  out( '-I-', *args)
110 
111 
112 def f( *args ):
113  out( '-F-', *args )
114  sys.exit(1)
115 
116 
117 # We track the number of errors
118 _n_errors = 0
119 def e( *args ):
120  global red, reset
121  out( red + '-E-' + reset, *args )
122  global _n_errors
123  _n_errors = _n_errors + 1
124 
125 def n_errors():
126  global _n_errors
127  return _n_errors
128 
130  global _n_errors
131  _n_errors = 0
132 
133 
134 # We track the number of warnings
135 _n_warnings = 0
136 def w(*args):
137  global red, reset
138  out( yellow + '-W-' + reset, *args )
139  global _n_warnings
140  _n_warnings = _n_warnings + 1
141 
143  global _n_warnings
144  return _n_warnings
145 
147  global _n_warnings
148  _n_warnings = 0
149 
def n_warnings()
Definition: log.py:142
def d(args)
Definition: log.py:83
def w(args)
Definition: log.py:136
def progress(args)
Definition: log.py:43
def is_debug_on()
Definition: log.py:94
def is_color_on()
Definition: log.py:56
def n_errors()
Definition: log.py:125
def debug_indent(n=1, indentation=' ')
Definition: log.py:100
def _stream_has_color(stream)
Definition: log.py:8
def debug_on()
Definition: log.py:86
def out(args, sep=' ', end='\n')
Definition: log.py:35
static std::string print(const transformation &tf)
def reset_errors()
Definition: log.py:129
def verbose_on()
Definition: log.py:70
def debug_unindent(n=1, indentation=' ')
Definition: log.py:103
def i(args)
Definition: log.py:108
def e(args)
Definition: log.py:119
def quiet_on()
Definition: log.py:61
def is_verbose_on()
Definition: log.py:76
def f(args)
Definition: log.py:112
def v(args)
Definition: log.py:68
def reset_warnings()
Definition: log.py:146


librealsense2
Author(s): Sergey Dorodnicov , Doron Hirshberg , Mark Horn , Reagan Lopez , Itay Carpis
autogenerated on Mon May 3 2021 02:47:21