def add_device(device): """add device from info file""" fware_info = get_firm_by_device(device) dev_fware = device['firmware'] # Find a suitable port _port_attrs = ['machine', 'sysname', 'nodename'] _port_ids = [dev_fware.get(a).lower().split() for a in _port_attrs] port_ids = set(chain.from_iterable(_port_ids)) fware_devs = [d.lower() for d in fware_info['devices']] port = list(set(fware_devs).intersection(port_ids))[0] fware_tag = dev_fware['version'] fware_versions = [v['version'] for v in fware_info['versions']] if fware_tag not in fware_versions: try: fware_tag = fware_versions[0] except IndexError: fware_tag = "master" fware = Firmware(firmware_info=fware_info, port=port, tag=fware_tag) device_root = Path(device['path']).parent mods_out = device_root / 'frozen' with file_backups(mods_out, "*.py"): mods_out.mkdir(exist_ok=True, parents=True) fware.retrieve_license(device_root) mod_paths = fware_info['module_path'] if isinstance(mod_paths, list) and any( (i for i in mod_paths if '@' in i)): for mod_path in mod_paths: out_append, repo_path = mod_path.split('@') submod_out = mods_out / out_append / repo_path mods_out.mkdir(exist_ok=True, parents=True) fware.module_path = [Path(repo_path)] fware.retrieve_modules(submod_out) else: fware.retrieve_modules(mods_out) make_stubs(mods_out) return device