Exemplo n.º 1
0
def add_firmware(firm):
    """add firmware from info file"""
    ports = firm['devices']
    path = Path(firm['path']).parent
    versions = []
    updated_firm = firm.copy()
    for p in ports:
        fware = Firmware(port=p, firmware_info=firm)
        licenses = firm.get('licenses', [])
        for file in licenses:
            repo, file_path = file.split(':')
            fware.retrieve_license(path, repository=repo, repo_path=file_path)
        compat = fware.get_compatible_tags()
        for cmp in compat:
            prev_compat = next(
                (v for v in versions if v['version'] == cmp['version']), None)
            if prev_compat:
                always_merger.merge(prev_compat, cmp)
            else:
                versions.append(cmp)
    updated_firm['versions'] = versions
    for vers in versions:
        devices = vers.get('devices')
        if len(vers['devices']) >= 0:
            v_dir = path / vers['git_tag']
            dev_dirs = [Path(v_dir / dev) for dev in devices]
            [d.mkdir(exist_ok=True, parents=True) for d in dev_dirs]
    new = update_file(firm, updated_firm)
    fware_index = INFO['firmware'].index(firm)
    INFO['firmware'].pop(fware_index)
    INFO['firmware'].append(new)
    return new
Exemplo n.º 2
0
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