diff options
author | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2023-06-06 13:23:49 +0200 |
---|---|---|
committer | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2023-06-06 15:45:57 +0200 |
commit | a3b227d28a823d59e3281109f5369d0f63b40f62 (patch) | |
tree | 2d6ee89c3df9c4bdb457b261b6447f83edf8673b /src/ukify/ukify.py | |
parent | test_ukify: pass through path to addon stub (diff) | |
download | systemd-a3b227d28a823d59e3281109f5369d0f63b40f62.tar.xz systemd-a3b227d28a823d59e3281109f5369d0f63b40f62.zip |
ukify: add 'build' verb
The old syntax with linux + initrds as positional arguments is still accepted,
but a warning is emitted. We should remove the support for this after the
next release or so.
Adding a single verb by itself is not very useful, but opens the door to adding
other verbs.
Diffstat (limited to '')
-rwxr-xr-x | src/ukify/ukify.py | 43 |
1 files changed, 34 insertions, 9 deletions
diff --git a/src/ukify/ukify.py b/src/ukify/ukify.py index 88189d272d..a9c21601df 100755 --- a/src/ukify/ukify.py +++ b/src/ukify/ukify.py @@ -438,7 +438,7 @@ def call_systemd_measure(uki, linux, opts): def join_initrds(initrds): - if len(initrds) == 0: + if not initrds: return None if len(initrds) == 1: return initrds[0] @@ -820,7 +820,10 @@ class ConfigItem: else: conv = lambda s:s - if self.nargs == '*': + # This is a bit ugly, but --initrd is the only option which is specified + # with multiple args on the command line and a space-separated list in the + # config file. + if self.name == '--initrd': value = [conv(v) for v in value.split()] else: value = conv(value) @@ -840,8 +843,17 @@ class ConfigItem: return (section_name, key, value) +VERBS = ('build',) + CONFIG_ITEMS = [ ConfigItem( + 'positional', + metavar = 'VERB', + nargs = '*', + help = f"operation to perform ({','.join(VERBS)})", + ), + + ConfigItem( '--version', action = 'version', version = f'ukify {__version__}', @@ -854,20 +866,18 @@ CONFIG_ITEMS = [ ), ConfigItem( - 'linux', - metavar = 'LINUX', + '--linux', type = pathlib.Path, - nargs = '?', help = 'vmlinuz file [.linux section]', config_key = 'UKI/Linux', ), ConfigItem( - 'initrd', - metavar = 'INITRD…', + '--initrd', + metavar = 'INITRD', type = pathlib.Path, - nargs = '*', - help = 'initrd files [.initrd section]', + action = 'append', + help = 'initrd file [part of .initrd section]', config_key = 'UKI/Initrd', config_push = ConfigItem.config_list_prepend, ), @@ -1199,6 +1209,20 @@ def parse_args(args=None): p = create_parser() opts = p.parse_args(args) + # Figure out which syntax is being used, one of: + # ukify verb --arg --arg --arg + # ukify linux initrd… + if len(opts.positional) == 1 and opts.positional[0] in VERBS: + opts.verb = opts.positional[0] + elif opts.linux or opts.initrd: + raise ValueError('--linux/--initrd options cannot be used with positional arguments') + else: + print("Assuming obsolete commandline syntax with no verb. Please use 'build'.") + if opts.positional: + opts.linux = pathlib.Path(opts.positional[0]) + opts.initrd = [pathlib.Path(arg) for arg in opts.positional[1:]] + opts.verb = 'build' + # Check that --pcr-public-key=, --pcr-private-key=, and --phases= # have either the same number of arguments are are not specified at all. n_pcr_pub = None if opts.pcr_public_keys is None else len(opts.pcr_public_keys) @@ -1219,6 +1243,7 @@ def parse_args(args=None): def main(): opts = parse_args() check_inputs(opts) + assert opts.verb == 'build' make_uki(opts) |