def start(self): self._logger.info("Starting Program Manager Server") pyfgc_name.read_name_file() pyfgc_name.read_group_file() for area in pyfgc_name.groups.keys(): self._logger.info(f"Starting AreaProgramManager({area})") self._area_pms[area] = AreaProgramManager(area, self.expected_data, self.adapter_data) while not self._run.is_set(): self._obtain_kerberos_ticket() if not self._status_srv_conn: self._get_status_srv_connection() try: fgcds = pyfgc_statussrv.get_status_all( fgc_session=self._status_srv_conn) except pyfgc.PyFgcError as e: self._logger.warning(f"Error in ProgramManagerServer: {e}") self._clean_status_srv_connection() fgcds = dict() for device, area in filter_jobs(fgcds): self._area_pms[area].add_job(fgc_job, device) time.sleep(ITERATION_STATUS_SRV_SEC)
def test_devices_gateways_consistency(): pyfgc_name.read_name_file() # Filter function def filter_fgcs(dev_dict): return dev_dict["gateway"] == "cfc-866-reth7" # Get devices controlled by certain gateway target_devices = list(filter(filter_fgcs, pyfgc_name.devices.values())) # Add one to the gateways list because the gateway is not included assert len(pyfgc_name.gateways["cfc-866-reth7"]["devices"]) + 1 == len(target_devices)
def _gen_fgc_jobs_for_groups_class(groups, class_id): pyfgc_name.read_name_file() pyfgc_name.read_group_file() for name, device in pyfgc_name.devices.items(): if device["class_id"] != class_id: continue gr = pyfgc_name.gateways[device["gateway"]]["groups"][0] if gr not in groups: continue yield name, gr
def test_data_structures_have_minimum_content(): pyfgc_name.read_name_file() pyfgc_name.read_subdevice_file() pyfgc_name.read_group_file() assert len(pyfgc_name.gateways) > 200 assert len(pyfgc_name.devices) > 4000 assert len(pyfgc_name.groups) > 50 gw_set_from_groups = set() for v in pyfgc_name.groups.values(): for g in v["gateways"]: gw_set_from_groups.add(g) assert len(pyfgc_name.gateways) == len(gw_set_from_groups)
def _resolve_from_name_file(target, namefile=None): try: pyfgc_name.read_name_file(namefile) except FileNotFoundError as e: if namefile is None: raise FileNotFoundError("Unable to find default name file") from e else: raise FileNotFoundError(f"Unable to find name file {namefile}") from e resolved_targets = pyfgc_name.build_device_tset(target) if len(resolved_targets) == 0: raise KeyError(f"Did not find device named like {target}") if len(resolved_targets) > 1: raise KeyError(f"Target {target} matches more than one device") return resolved_targets.pop()
import re from PyQt5 import QtCore import pyfgc_name try: pyfgc_name.read_name_file(filename='/Users/cghabrou/Code/cern/name') except FileNotFoundError: pyfgc_name.read_name_file() class SpareModel(QtCore.QAbstractListModel): def __init__(self, *args, devices=None, **kwargs): super().__init__(*args, **kwargs) self.default_devices = [ dev for dev, dev_obj in pyfgc_name.devices.items() if dev_obj['class_id'] == 63 ] self.devices = devices if devices else self.default_devices self.devices.sort() def data(self, index, role=QtCore.Qt.DisplayRole): if index.isValid() is False: return QtCore.QVariant() if role == QtCore.Qt.DisplayRole or role == QtCore.Qt.ItemDataRole: try: text = self.devices[index.row()] except IndexError:
type=str, nargs=1, help='Operational FGC3') parser.add_argument('spare', metavar='SPARE FGC', type=str, nargs=1, help='Spare FGC3') parser.add_argument('database', metavar='DATABASE', type=str, nargs=1, help='PRO(duction) or DEV(evelopment) database') parser.add_argument( '--del', dest='action', action='store_const', const=delete_combo_system, default=create_op_spare_combo_system, help= 'DELETE op-spare configuration (default: create op-spare configuration)' ) if __name__ == '__main__': pyfgc_name.read_name_file() parser = argparse.ArgumentParser() configure_parser(parser) args = parser.parse_args().__dict__.copy() args.pop('action')(*_get_arguments_from_cmd_line(**args))
def r_name_file(): pyfgc_name.read_name_file()
def test_non_existing_file(): with pytest.raises(FileNotFoundError): pyfgc_name.read_name_file("/a/b/c/ddddsdf/s/321423/5/6c")
def test_devices_can_be_read_by_passing_http_url(): pyfgc_name.read_name_file("http://cs-ccr-www1.cern.ch/~pclhc/etc/fgcd/name") assert len(pyfgc_name.devices) != 0
def test_devices_can_be_read_by_passing_name_file_url(): pyfgc_name.read_name_file("file:///user/pclhc/etc/fgcd/name") assert len(pyfgc_name.devices) != 0
def test_devices_can_be_read_by_passing_name_file_absolute_path(): pyfgc_name.read_name_file("/user/pclhc/etc/fgcd/name") assert len(pyfgc_name.devices) != 0
def test_devices_can_be_read_from_default_name_file_parameter(): pyfgc_name.read_name_file() assert len(pyfgc_name.devices) != 0