3 Top level script to run SiStrip DCS O2O. 15 from functools
import partial
17 import CondTools.SiStrip.o2o_helper
as helper
19 logDirVar =
'O2O_LOG_FOLDER' 26 o2ocmd =
"SiStripDCSPopCon.py" 27 o2ocmd +=
' --delay {delay}' 28 o2ocmd +=
' --destTags {destTags}' 29 o2ocmd +=
' --destDb {destDb}' 30 o2ocmd +=
' --inputTag {inputTag}' 31 o2ocmd +=
' --sourceDb {sourceDb}' 32 o2ocmd +=
' --condDbRead {condDbRead}' 36 cmd =
'o2o --db {db} -v run -n {jobname} "{o2ocmd}"'.
format(db=args.db, jobname=args.jobname, o2ocmd=o2ocmd)
37 logging.info(
'Start running command:\n %s' % cmd)
39 p = subprocess.Popen(cmd, shell=
True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
40 atexit.register(partial(helper.kill_subproc_noexcept, p))
42 log = p.communicate()[0]
44 logging.info(
'O2OJob %s finished successfully!' % args.jobname)
46 logging.error(
'O2OJob %s FAILED!' % args.jobname)
56 debugLabel =
'[TEST] ' if args.debug
else '' 57 with open(logfile,
'rb')
as log:
58 helper.send_mail(subject=
'%sDCS O2O Failure: %s' % (debugLabel, args.jobname),
60 send_to=args.mail_log_to,
61 send_from=args.mail_from)
65 parser = argparse.ArgumentParser(description=
'Run SiStrip DCS O2O.')
66 parser.add_argument(
'jobname', metavar=
'JOBNAME', type=str, help=
'O2O job name as in DB.')
67 parser.add_argument(
'--mail-from', default=
'trk.o2o@cern.ch', help=
'Account to send email notification.')
68 parser.add_argument(
'--mail-to', default=
'trk.o2o@cern.ch', help=
'List of O2O notification recipients.')
69 parser.add_argument(
'--mail-log-to', default=
'trk.o2o@cern.ch', help=
'List of O2O log recipients.')
70 parser.add_argument(
'--db', default=
'pro', help=
'The database for o2o job management: pro ( for prod ) or dev ( for prep ). Default: %(default)s.')
71 parser.add_argument(
'--debug', action=
"store_true", default=
False, help=
'Switch on debug mode. Default: %(default)s.')
73 args = parser.parse_args()
74 args.mail_to = args.mail_to.strip().
split(
',')
75 args.mail_log_to = args.mail_log_to.strip().
split(
',')
79 logdir = os.environ[logDirVar]
if logDirVar
in os.environ
else '/tmp' 80 if not os.path.exists(logdir):
82 logfile = os.path.join(logdir,
'SiStripsDCSO2O_%s.log' %
str(args.jobname))
83 loglevel = logging.DEBUG
if args.debug
else logging.INFO
84 helper.configLogger(logfile, loglevel)
88 helper.send_mail(
'DCS O2O Failure: %s' % args.jobname, traceback.format_exc(), args.mail_to, args.mail_from)
97 helper.send_mail(
'DCS O2O Failure: %s' % args.jobname, traceback.format_exc(), args.mail_to, args.mail_from)
101 return ' --- O2O FAILED! ---' 103 if __name__ ==
'__main__':
def split(sequence, size)
def summary(args, is_ok, logfile)