build: add subcommands to kexttool
This commit is contained in:
@@ -1,12 +1,28 @@
|
|||||||
import yaml
|
import yaml
|
||||||
import io
|
import io
|
||||||
import os
|
import os
|
||||||
|
import glob
|
||||||
|
|
||||||
class KextSource:
|
class KextSource:
|
||||||
__kext_info = {}
|
__kext_info = {}
|
||||||
__src_dir_path = ''
|
__src_dir_path = ''
|
||||||
|
|
||||||
|
|
||||||
|
def scan(path):
|
||||||
|
result = []
|
||||||
|
scan_arg = os.path.join(path, '**/extension.yaml')
|
||||||
|
|
||||||
|
for filename in glob.iglob(scan_arg, recursive=True):
|
||||||
|
try:
|
||||||
|
kext_src = KextSource(filename)
|
||||||
|
except Exception as e:
|
||||||
|
continue
|
||||||
|
|
||||||
|
result.append(kext_src)
|
||||||
|
|
||||||
|
return result
|
||||||
|
|
||||||
|
|
||||||
def __init__(self, info_file):
|
def __init__(self, info_file):
|
||||||
self.__src_dir_path = os.path.relpath(os.path.dirname(info_file), os.getcwd())
|
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:
|
with io.open(info_file, 'r', encoding='utf-8') as info_fp:
|
||||||
|
|||||||
32
tools/kexttool/scan.py
Normal file
32
tools/kexttool/scan.py
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
import glob
|
||||||
|
import os
|
||||||
|
from kexttool import kext
|
||||||
|
|
||||||
|
def list_all(pretty=False):
|
||||||
|
cwd = os.getcwd()
|
||||||
|
scan_arg = os.path.join(cwd, 'extensions', '**/extension.yaml')
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
|
if pretty:
|
||||||
|
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))
|
||||||
|
else:
|
||||||
|
print('\033[1;96m* \033[0;1m{}\033[0m ({})'.format(kext_src.id(), kext_src.src_dirpath()))
|
||||||
|
|
||||||
|
nr_extensions = nr_extensions + 1
|
||||||
19
tools/kexttool/select.py
Normal file
19
tools/kexttool/select.py
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
import inquirer
|
||||||
|
import os
|
||||||
|
from kexttool import kext
|
||||||
|
|
||||||
|
|
||||||
|
def select_kexts():
|
||||||
|
all_kexts = [ k.id() for k in kext.KextSource.scan(os.path.join(os.getcwd(), 'extensions')) ]
|
||||||
|
if len(all_kexts) == 0:
|
||||||
|
print('No kernel extensions available.')
|
||||||
|
return
|
||||||
|
|
||||||
|
questions = [
|
||||||
|
inquirer.Checkbox('kexts',
|
||||||
|
message="Select kexts to include in the kernel image",
|
||||||
|
choices=all_kexts,
|
||||||
|
)
|
||||||
|
]
|
||||||
|
answers = inquirer.prompt(questions)
|
||||||
|
print(answers["kexts"])
|
||||||
@@ -3,30 +3,25 @@
|
|||||||
# -*- mode: python -*-
|
# -*- mode: python -*-
|
||||||
|
|
||||||
import glob
|
import glob
|
||||||
|
import inquirer
|
||||||
import os
|
import os
|
||||||
from kexttool import kext
|
import sys
|
||||||
|
from kexttool import kext, scan, select
|
||||||
|
|
||||||
cwd = os.getcwd()
|
|
||||||
scan_arg = os.path.join(cwd, 'extensions', '**/extension.yaml')
|
|
||||||
|
|
||||||
nr_extensions = 0
|
if len(sys.argv) < 2:
|
||||||
|
print('usage: {} <command>'.format(sys.argv[0]))
|
||||||
|
exit(0)
|
||||||
|
|
||||||
# root_dir needs a trailing slash (i.e. /root/dir/)
|
cmd = sys.argv[1]
|
||||||
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()))
|
commands = {
|
||||||
print(' Bundle ID: {}'.format(kext_src.id()))
|
'select': select.select_kexts,
|
||||||
print(' License: {}'.format(kext_src.license()))
|
'list': scan.list_all
|
||||||
print(' Copyright: {}'.format(kext_src.copyright()))
|
}
|
||||||
print(' Location: {}'.format(kext_src.src_dirpath()))
|
|
||||||
print(' Sources:')
|
|
||||||
|
|
||||||
for src in kext_src.sources():
|
if cmd not in commands:
|
||||||
print(' {}'.format(src))
|
print('E: unknown command \'{}\''.format(cmd))
|
||||||
|
exit(-1)
|
||||||
|
|
||||||
nr_extensions = nr_extensions + 1
|
commands[cmd]()
|
||||||
|
|||||||
Reference in New Issue
Block a user