new patch, just using settings.string_list (requires patch to cliapp to work, also attached)
with that passing additional settings to debootstrap looks like this: -D "components=main,contrib" -D "keyring=KEYRING"
From d35b1962d62bebd1fa30558bde148e6f752ed3a4 Mon Sep 17 00:00:00 2001 From: Jan Gerber <j...@mailb.org> Date: Sun, 3 May 2015 14:48:34 +0200 Subject: add -D to pass additional settings to debootstrap some examples: -D "components=main,contrib" -D "keyring=KEYRING" diff --git a/vmdebootstrap b/vmdebootstrap index 49c21c8..aa45b9f 100755 --- a/vmdebootstrap +++ b/vmdebootstrap @@ -83,6 +83,10 @@ class VmDebootstrap(cliapp.Application): # pylint: disable=too-many-public-meth self.settings.string( ['variant'], 'select debootstrap variant it not using the default') + self.settings.string_list( + ['debootstrap-setting', 'D'], + 'pass additional options to debootstrap (i.e. "components=main,contrib") ' + 'check debootstrap --help for valid options'), self.settings.boolean( ['extlinux'], 'install extlinux?', @@ -445,6 +449,8 @@ class VmDebootstrap(cliapp.Application): # pylint: disable=too-many-public-meth if self.settings['variant']: args.append('--variant') args.append(self.settings['variant']) + for opt in self.settings['debootstrap-setting']: + args.append('--%s' % opt) args += [self.settings['distribution'], rootdir, self.settings['mirror']] logging.debug(" ".join(args)) diff --git a/vmdebootstrap.8.in b/vmdebootstrap.8.in index 80df9bc..f3ada4a 100644 --- a/vmdebootstrap.8.in +++ b/vmdebootstrap.8.in @@ -29,7 +29,7 @@ vmdebootstrap \- install basic Debian system into virtual disk image [\-\-serial-console | \-\-no-serial-console] [\-\-sudo |\-\-no-sudo] [\-\-owner=OWNER] [\-\-bootsize=BOOTSIZE] [\-\-boottype=FSTYPE] [\-\-roottype=FSTYPE] [\-\-foreign=PATH] [\-\-variant=VARIANT] [\-\-no-extlinux] [\-\-squash] [\-\-configure-apt] -[\-\-grub] [\-\-apt-mirror] [\-\-pkglist] +[\-\-grub] [\-\-apt-mirror] [\-\-pkglist] [\-D, \-\-debootstrap\-setting] .SH DESCRIPTION .B vmdebootstrap installs a basic Debian system into a virtual disk image, @@ -231,6 +231,9 @@ complete and grub-install will be called in the image. Output a list of package names installed inside the image. Useful if you need to track the relevant source packages used inside the image for licence compliance. +.IP \-D, \-\-debootstrap\-setting +Pass additional options to debootstrap (i.e. -D "components=main,contrib") +check debootstrap \-\-help for valid options .SH Configuration files and settings: .IP \-\-dump-config write out the entire current configuration -- 2.2.1.209.g41e5f3a
From 47d70acc54da4f26c43a1443590c2e5441c0ec47 Mon Sep 17 00:00:00 2001 From: Jan Gerber <j...@mailb.org> Date: Wed, 6 May 2015 19:05:36 +0200 Subject: Allow comma in StringListSetting values - Escape values with comma with double quotes in config syntax. - Don't split values passed as arguments. diff --git a/cliapp/settings.py b/cliapp/settings.py index c272a78..d9e5ba7 100644 --- a/cliapp/settings.py +++ b/cliapp/settings.py @@ -105,30 +105,41 @@ class StringListSetting(Setting): self, names, [], help_text, metavar=metavar, group=group, hidden=hidden) self.default = default + self._strings = self.default or [] self.using_default_value = True def default_metavar(self): return self.names[0].upper() def get_value(self): - if self._string_value.strip(): - return [s.strip() for s in self._string_value.split(',')] - else: - return self.default + return self._strings def set_value(self, strings): - self._string_value = ','.join(strings) + self._strings = strings self.using_default_value = False def has_value(self): return self.value != [] def parse_value(self, string): - self.value = [s.strip() for s in string.split(',')] + values = [] + value = '' + inside_quote = False + for c in string: + if c == '"': + inside_quote = not inside_quote + elif c == ',' and not inside_quote: + values.append(value) + value = '' + else: + value += c + if value: + values.append(value) + self.value = [v.strip() for v in values] def format(self): # pragma: no cover - return ', '.join(self.value) - + values = ['"%s"' % v if ',' in v else v for v in self.value] + return ', '.join(values) class ChoiceSetting(Setting): diff --git a/cliapp/settings_tests.py b/cliapp/settings_tests.py index e1c4fa8..9284eec 100644 --- a/cliapp/settings_tests.py +++ b/cliapp/settings_tests.py @@ -278,14 +278,17 @@ foo = yeehaa [config] foo = yeehaa bar = ping, pong +comma = ping, pong, "foo,bar" ''') self.settings.string_list(['foo'], 'foo help') self.settings.string_list(['bar'], 'bar help') + self.settings.string_list(['comma'], 'comma help') self.settings.config_files = ['whatever.conf'] self.settings.load_configs(open_file=mock_open) self.assertEqual(self.settings['foo'], ['yeehaa']) self.assertEqual(self.settings['bar'], ['ping', 'pong']) + self.assertEqual(self.settings['comma'], ['ping', 'pong', 'foo,bar']) def test_handles_defaults_with_config_files(self): @@ -330,9 +333,9 @@ bar = ping, pong self.settings.string_list(['bar'], 'bar help', default=['bar']) self.settings.config_files = ['whatever.conf'] self.settings.load_configs(open_file=mock_open) - self.settings.parse_args(['--foo=red', '--bar=blue', '--bar=white']) + self.settings.parse_args(['--foo=red', '--bar=blue', '--bar=white,comma']) self.assertEqual(self.settings['foo'], 'red') - self.assertEqual(self.settings['bar'], ['blue', 'white']) + self.assertEqual(self.settings['bar'], ['blue', 'white,comma']) def test_load_configs_raises_error_for_unknown_variable(self): -- 2.2.1.209.g41e5f3a