Skip to content

Commit

Permalink
1. add command line option -p/--print-level optioon for ostap sc…
Browse files Browse the repository at this point in the history
…ript for better contol of the global print level
  • Loading branch information
VanyaBelyaev committed Jul 10, 2024
1 parent a5246b6 commit e967ecc
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 16 deletions.
1 change: 1 addition & 0 deletions ReleaseNotes/release_notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
1. add `sync_dirs` function into `ostap.io.files` module to syncronize the directories
1. add `UseWeb` & 'useWeb' contetx managers for setting the WebDispaly into `ostap.plotting.canvas` module
1. add command line option `-w/--web` optioon for `ostap` script to alolow defien Web-Distplay
1. add command line option `-p/--print-level` optioon for `ostap` script for better contol of the global print level

## Backward incompatible

Expand Down
62 changes: 46 additions & 16 deletions ostap/core/run_ostap.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,14 +119,34 @@ def __call__(self, parser, namespace, values, option_string=None):
"-q" , "--quiet" ,
dest = 'Quiet' ,
action = 'store_true' ,
help = "Quite processing [default: %(default)s]" ,
default = _cnf.quiet )
help = "Quite processing, same as --print-level=5 [default: %(default)s]" ,
default = _cnf.quiet )
egroup1.add_argument (
"--silent" ,
dest = 'Silent' ,
action = 'store_true' ,
help = "Verbose processing, same as --print-level=4 [default: %(default)s]" ,
default = _cnf.verbose )
egroup1.add_argument (
"--verbose" ,
dest = 'Verbose' ,
action = 'store_true' ,
help = "Verbose processing [default: %(default)s]" ,
help = "Verbose processing, same as --print-level=1 [default: %(default)s]" ,
default = _cnf.verbose )
egroup1.add_argument (
"--debug" ,
dest = 'Debug' ,
action = 'store_true' ,
help = "Debug processing, same as --print-level=2 [default: %(default)s]" ,
default = False )
egroup1.add_argument (
"-p" , "--print-level" ,
dest = 'Level' ,
choices = range ( -1 , 8 ) ,
type = int ,
help = "Printout level [default: %(default)s]" ,
default = -1 )

#
parser.add_argument (
"files" ,
Expand Down Expand Up @@ -265,18 +285,29 @@ def __call__(self, parser, namespace, values, option_string=None):
# =============================================================================
## suppress extra prints from logging
# =============================================================================
if arguments.Quiet :

import logging
logger.info ( '(silent) Interactive Ostap session (steroid-enhanced PyROOT)')
logging.disable ( logging.WARNING - 1 )
import logging

else:

import logging
level = logging.DEBUG-5 if arguments.Verbose else logging.INFO-1
logging.disable ( level )
level = logging.INFO - 2

if arguments.Quiet :
logger.info ( '(silent) Interactive Ostap session (steroid-enhanced PyROOT)')
level = logging.WARNING - 1
elif arguments.Debug : level = logging.DEBUG - 2
elif arguments.Verbose : level = logging.VERBOSE - 2
elif 0 == arguments.Level : level = 1
elif 1 == arguments.Level : level = logging.VERBOSE - 2
elif 2 == arguments.Level : level = logging.DEBUG - 2
elif 3 == arguments.Level : level = logging.INFO - 2
elif 4 == arguments.Level : level = logging.ATTENTION - 2
elif 5 == arguments.Level : level = logging.WARNING - 2
elif 6 == arguments.Level : level = logging.ERROR - 2
elif 7 <= arguments.Level : level = logging.CRITICAL - 2


logging.disable ( level )

if level <= logging.INFO :

from ostap import banner
logger.info ( "Welcome to Ostap\n" + banner )
logger.info ( __doc__ )
Expand All @@ -287,7 +318,7 @@ def __call__(self, parser, namespace, values, option_string=None):
logger.info ( 'Arguments : ')
for _k in sorted ( _keys ) : logger.info ( ' %15s : %-s ' % ( _k , _vars[_k] ) )
del _keys,_vars,_k,level

# =============================================================================
if arguments.Config :
from ostap.utils.basic import get_env as ostap_getenv
Expand Down Expand Up @@ -365,11 +396,10 @@ def _end_profile_ ( prof ) :
# =============================================================================
import ostap.core.startup


# =============================================================================
## import everything from ostap
# =============================================================================
if arguments.Quiet :
if arguments.Quiet :
from ostap.logger.utils import mute
with mute () :
from ostap.core.load_ostap import *
Expand Down

0 comments on commit e967ecc

Please sign in to comment.