Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-04-10 08:39:01

0001 import sys
0002 import time
0003 
0004 from pandacommon.pandalogger import logger_utils
0005 from pandacommon.pandautils.thread_utils import GenericThread
0006 from pandaserver.config import panda_config
0007 from pandaserver.configurator import Configurator as configurator_module
0008 from pandaserver.configurator.Configurator import (
0009     Configurator,
0010     NetworkConfigurator,
0011     SchedconfigJsonDumper,
0012     SWTagsDumper,
0013 )
0014 
0015 # logger
0016 base_logger = configurator_module._logger
0017 
0018 
0019 # main
0020 def main(argv=tuple(), tbuf=None, **kwargs):
0021     requester_id = GenericThread().get_full_id(__name__, sys.modules[__name__].__file__)
0022 
0023     # instantiate TB
0024     if tbuf is None:
0025         from pandaserver.taskbuffer.TaskBuffer import taskBuffer
0026 
0027         taskBuffer.init(
0028             panda_config.dbhost,
0029             panda_config.dbpasswd,
0030             nDBConnection=1,
0031             useTimeout=True,
0032             requester=requester_id,
0033         )
0034     else:
0035         taskBuffer = tbuf
0036 
0037     # If no argument, call the basic configurator
0038     if len(argv) == 1:
0039         _logger = logger_utils.make_logger(base_logger, "Configurator")
0040         t1 = time.time()
0041         configurator = Configurator(taskBuffer=taskBuffer, log_stream=_logger)
0042 
0043         if not configurator.retrieve_data():
0044             _logger.error("Data was not retrieved correctly")
0045             return
0046 
0047         if not configurator.run():
0048             _logger.error("Configurator loop FAILED")
0049         t2 = time.time()
0050         _logger.debug(f"Configurator run took {t2 - t1}s")
0051 
0052     # If --network argument, call the network configurator
0053     elif len(argv) == 2 and argv[1].lower() == "--network":
0054         _logger = logger_utils.make_logger(base_logger, "NetworkConfigurator")
0055         t1 = time.time()
0056         network_configurator = NetworkConfigurator(taskBuffer=taskBuffer, log_stream=_logger)
0057         if not network_configurator.retrieve_data():
0058             _logger.error("Data was not retrieved correctly")
0059             return
0060         if not network_configurator.run():
0061             _logger.error("Configurator loop FAILED")
0062         t2 = time.time()
0063         _logger.debug(f" run took {t2 - t1}s")
0064 
0065     # If --json_dump
0066     elif len(argv) == 2 and argv[1].lower() == "--json_dump":
0067         _logger = logger_utils.make_logger(base_logger, "SchedconfigJsonDumper")
0068         t1 = time.time()
0069         json_dumper = SchedconfigJsonDumper(taskBuffer=taskBuffer, log_stream=_logger)
0070         out_msg = json_dumper.run()
0071         _logger.debug(f"Json_dumper finished with {out_msg}")
0072         t2 = time.time()
0073         _logger.debug(f" run took {t2 - t1}s")
0074 
0075     # If --sw_tags
0076     elif len(argv) == 2 and argv[1].lower() == "--sw_tags":
0077         _logger = logger_utils.make_logger(base_logger, "SWTagsDumper")
0078         t1 = time.time()
0079         sw_tag_collector = SWTagsDumper(taskBuffer=taskBuffer, log_stream=_logger)
0080         out_msg = sw_tag_collector.run()
0081         _logger.debug(f"sw_tag_collector finished with {out_msg}")
0082         t2 = time.time()
0083         _logger.debug(f" run took {t2 - t1}s")
0084 
0085     else:
0086         base_logger.error("Configurator being called with wrong arguments. Use either no arguments or --network or --json_dump")
0087 
0088     # stop taskBuffer if created inside this script
0089     if tbuf is None:
0090         taskBuffer.cleanup(requester=requester_id)
0091 
0092 
0093 if __name__ == "__main__":
0094     main(argv=sys.argv)