EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
util.py
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file util.py
1 import os
2 import contextlib
3 import sys
4 
5 try:
6  from halo import Halo
7 except:
8  Halo = None
9 
10 @contextlib.contextmanager
11 def Spinner(text, persist=True, *args, **kwargs):
12  stream = kwargs.get("stream", sys.stdout)
13  if stream.isatty() and Halo is not None:
14  spinner = Halo(text, *args, **kwargs)
15  spinner.start()
16  try:
17  yield
18  if persist:
19  spinner.succeed()
20  except:
21  if persist:
22  spinner.fail()
23  raise
24  finally:
25  if not persist:
26  spinner.stop()
27  else:
28  stream.write(text + "\n")
29  yield