diff options
Diffstat (limited to 'debian/bin/update-modinfo')
-rwxr-xr-x | debian/bin/update-modinfo | 46 |
1 files changed, 30 insertions, 16 deletions
diff --git a/debian/bin/update-modinfo b/debian/bin/update-modinfo index ea37486..1470dd9 100755 --- a/debian/bin/update-modinfo +++ b/debian/bin/update-modinfo @@ -2,6 +2,7 @@ # Update the module information used to generate related device IDs +import itertools import json import os.path import subprocess @@ -28,34 +29,47 @@ def get_module_info(filename, attr_name): return output.rstrip('\n').split('\n') -def main(kernel_id=None): - if kernel_id is None: - kernel_dir = '/lib/modules/' + os.uname().release - elif '/' not in kernel_id: - kernel_dir = '/lib/modules/' + kernel_id +class JSONEncoderWithSet(json.JSONEncoder): + def default(self, o): + if isinstance(o, set): + return sorted(o) + return super().default(o) + + +def main(*kernel_ids): + if not kernel_ids: + kernel_dirs = '/lib/modules/' + os.uname().release else: - kernel_dir = kernel_id + kernel_dirs = [('/lib/modules/' + kernel_id + if '/' not in kernel_id + else kernel_id) + for kernel_id in kernel_ids] modinfo = {} - for name, filename in iter_modules(kernel_dir): + for name, filename in itertools.chain.from_iterable( + iter_modules(kernel_dir) for kernel_dir in kernel_dirs): # We only care about modules that might request firmware - firmware = get_module_info(filename, 'firmware') + firmware = set(get_module_info(filename, 'firmware')) if not firmware: continue # We only care about aliases generated from device IDs, which # start with <type> ":" - aliases = [alias - for alias in get_module_info(filename, 'alias') - if ':' in alias] + aliases = set(alias + for alias in get_module_info(filename, 'alias') + if ':' in alias) - modinfo[name] = { - 'alias': aliases, - 'firmware': firmware, - } + if name not in modinfo: + modinfo[name] = { + 'alias': aliases, + 'firmware': firmware, + } + else: + modinfo[name]['alias'] |= aliases + modinfo[name]['firmware'] |= firmware with open('debian/modinfo.json', 'w') as f: - json.dump(modinfo, f, indent=2, sort_keys=True) + json.dump(modinfo, f, indent=2, sort_keys=True, cls=JSONEncoderWithSet) if __name__ == '__main__': |