Commit f0137d46 authored by Benjamin Schwenker's avatar Benjamin Schwenker
Browse files

added module bg_net/report_to_webserver.py and enabled upload of reports to webserver in KEK VPN

parent fb81ecf7
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# BGNet (Background prediction with neural nets for Belle II at SuperKEKB)
# Author: The BGNet developers
#
# See git log for contributors and copyright holders.
# This file is licensed under MIT licence, see LICENSE.md.
"""
report_to_webserver.py
======================
Module for copying bgnet reports to webserver in KEK VPN
"""
import os
class ReportsToWebServer():
"""
Class to push list of bgnet reports to webserver inside KEK VPN
Usage: ReportsToWebServer(reports, cred_path).copy()
Parameters
----------
reports : list
list of filepathes to pdf reports
cred_path : str
path to file with user credentials
"""
def __init__(self, reports, report_day, shift, skbsrv_cred, connectVPN=None):
"""Constructor."""
super(ReportsToWebServer, self).__init__()
#: Path to (cisco) vpn client to connect
self.reports = reports
#: Report day of type datetime.datetime
self.report_day = report_day
#: Report on shift, just a string
self.shift = shift
#: Path to file with user credentials
self.skbsrv_cred = skbsrv_cred
#: Object for making VPN connection
self.connectVPN = connectVPN
def copy(self):
"""Copy reports to webserver"""
self.connectVPN.connect()
base_folder = "/home/benjamin/public_html/bgnet_reports/{}-{}-{}_{}".format(self.report_day.year, self.report_day.month, self.report_day.day, self.shift)
os.system("sshpass -f {} ssh benjamin@130.87.225.93 'mkdir -p {}'".format(self.skbsrv_cred, base_folder))
for report in self.reports:
os.system('sshpass -f {} scp {} benjamin@130.87.225.93:{}'.format(self.skbsrv_cred, report, base_folder))
self.connectVPN.disconnect()
return
......@@ -55,8 +55,10 @@ import bg_net.beam_life as beam_life
import bg_net.hitrate as hitrate
import bg_net.report_utils
import bg_net.report_to_elog
from bg_net.report_to_webserver import ReportsToWebServer
import bg_net.archiver.indexer_utils as indexer_utils
from bg_net.archiver.skb_naming import get_unit
import bg_net.archiver.connect_vpn as connect_vpn
import os
import yaml
......@@ -103,11 +105,14 @@ def parse_args():
add_arg('--elog', action='store_true', help='Upload report to elog')
add_arg('--rocketchat', action='store_true', help='Post rocketchat message')
add_arg('--elog_cred', default=None, type=str, help='Path to elog credentials file')
add_arg('--skbsrv_cred', default=None, type=str, help='Path to skbsrv credentials file')
add_arg('--b2rc_cred', default=None, type=str, help='Path to b2rc credentials file')
add_arg('--report_path', default='./report_archive', type=str, help='Path for ouput reports')
add_arg('--latest_day', action='store_true', help='Make report for latest (most recent) day in archive')
add_arg('--config_path', type=str, default='./configs', help='Path to directory with model configs')
add_arg('--shift', type=str, default='24h', help='Mode for daily reporting, defined values: 8h, 16h, 24h')
add_arg('--vpn_cmd', type=str, default='/opt/cisco/anyconnect/bin/vpn', help="Shell command to create VPN connection to KEK")
add_arg('--vpn_cred', type=str, default='', help="Path to user credentials for VPN")
return parser.parse_args()
......@@ -1076,16 +1081,21 @@ def main():
credFileElog=args.elog_cred,
credFileb2rc=args.b2rc_cred
).uploadToElog()
if success:
logging.info("Uploaded reports: \n" + ", ".join(attachments))
logging.info("Link to eLog: {}".format("https://elog.belle2.org/elog/Bkg+analysis/"))
else:
logging.info('No upload to eLog')
logging.info("Created reports: \n" + ", ".join(attachments))
else:
logging.info("Created reports: \n" + ", ".join(attachments))
if args.skbsrv_cred:
logging.info("Uploading reports to skbsrv server")
connectVPN = connect_vpn.ConnectVPN(cmd=args.vpn_cmd, cred_path=args.vpn_cred)
ReportsToWebServer(attachments, start, args.shift, args.skbsrv_cred, connectVPN).copy()
if __name__ == '__main__':
main()
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment