build: add a tool to scan extensions/ for kernel extensions
This commit is contained in:
37
tools/kexttool/kext.py
Normal file
37
tools/kexttool/kext.py
Normal file
@@ -0,0 +1,37 @@
|
||||
import yaml
|
||||
import io
|
||||
import os
|
||||
|
||||
class KextSource:
|
||||
__kext_info = {}
|
||||
__src_dir_path = ''
|
||||
|
||||
|
||||
def __init__(self, info_file):
|
||||
self.__src_dir_path = os.path.relpath(os.path.dirname(info_file), os.getcwd())
|
||||
with io.open(info_file, 'r', encoding='utf-8') as info_fp:
|
||||
self.__kext_info = yaml.safe_load(info_fp)
|
||||
|
||||
|
||||
def name(self):
|
||||
return self.__kext_info['name']
|
||||
|
||||
|
||||
def id(self):
|
||||
return self.__kext_info['id']
|
||||
|
||||
|
||||
def license(self):
|
||||
return self.__kext_info['license']
|
||||
|
||||
|
||||
def copyright(self):
|
||||
return self.__kext_info['copyright']
|
||||
|
||||
|
||||
def sources(self):
|
||||
return self.__kext_info['sources']
|
||||
|
||||
|
||||
def src_dirpath(self):
|
||||
return self.__src_dir_path
|
||||
@@ -2,4 +2,31 @@
|
||||
# vim: ft=python
|
||||
# -*- mode: python -*-
|
||||
|
||||
print('hello, world')
|
||||
import glob
|
||||
import os
|
||||
from kexttool import kext
|
||||
|
||||
cwd = os.getcwd()
|
||||
scan_arg = os.path.join(cwd, 'extensions', '**/extension.info')
|
||||
|
||||
nr_extensions = 0
|
||||
|
||||
# root_dir needs a trailing slash (i.e. /root/dir/)
|
||||
for filename in glob.iglob(scan_arg, recursive=True):
|
||||
try:
|
||||
kext_src = kext.KextSource(filename)
|
||||
except Exception as e:
|
||||
print('E: cannot read kernel extension source manifest (reason: {})'.format(e))
|
||||
continue
|
||||
|
||||
print('* {}'.format(kext_src.name()))
|
||||
print(' Bundle ID: {}'.format(kext_src.id()))
|
||||
print(' License: {}'.format(kext_src.license()))
|
||||
print(' Copyright: {}'.format(kext_src.copyright()))
|
||||
print(' Location: {}'.format(kext_src.src_dirpath()))
|
||||
print(' Sources:')
|
||||
|
||||
for src in kext_src.sources():
|
||||
print(' {}'.format(src))
|
||||
|
||||
nr_extensions = nr_extensions + 1
|
||||
|
||||
Reference in New Issue
Block a user