dtoc: Make GetArgs() more flexible
At present it is not possible to have arguments which include spaces. Update the function to only split the args if the property is a single string. This is a bit inconsistent, but might still be useful. Signed-off-by: Simon Glass <sjg@chromium.org> Reviewed-by: Alper Nebi Yasak <alpernebiyasak@gmail.com> Suggested-by: Alper Nebi Yasak <alpernebiyasak@gmail.com>
This commit is contained in:
parent
04fce6ff70
commit
6101253818
@ -192,8 +192,12 @@ def GetArgs(node, propname):
|
|||||||
value = GetStringList(node, propname)
|
value = GetStringList(node, propname)
|
||||||
else:
|
else:
|
||||||
value = []
|
value = []
|
||||||
lists = [v.split() for v in value]
|
if not value:
|
||||||
args = [x for l in lists for x in l]
|
args = []
|
||||||
|
elif len(value) == 1:
|
||||||
|
args = value[0].split()
|
||||||
|
else:
|
||||||
|
args = value
|
||||||
return args
|
return args
|
||||||
|
|
||||||
def GetBool(node, propname, default=False):
|
def GetBool(node, propname, default=False):
|
||||||
|
@ -63,5 +63,7 @@
|
|||||||
orig-node {
|
orig-node {
|
||||||
orig = <1 23 4>;
|
orig = <1 23 4>;
|
||||||
args = "-n first", "second", "-p", "123,456", "-x";
|
args = "-n first", "second", "-p", "123,456", "-x";
|
||||||
|
args2 = "a space", "there";
|
||||||
|
args3 = "-n first second -p 123,456 -x";
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
@ -659,8 +659,12 @@ class TestFdtUtil(unittest.TestCase):
|
|||||||
['multi-word', 'message'],
|
['multi-word', 'message'],
|
||||||
fdt_util.GetArgs(self.node, 'stringarray'))
|
fdt_util.GetArgs(self.node, 'stringarray'))
|
||||||
self.assertEqual([], fdt_util.GetArgs(self.node, 'boolval'))
|
self.assertEqual([], fdt_util.GetArgs(self.node, 'boolval'))
|
||||||
self.assertEqual(['-n', 'first', 'second', '-p', '123,456', '-x'],
|
self.assertEqual(['-n first', 'second', '-p', '123,456', '-x'],
|
||||||
fdt_util.GetArgs(node, 'args'))
|
fdt_util.GetArgs(node, 'args'))
|
||||||
|
self.assertEqual(['a space', 'there'],
|
||||||
|
fdt_util.GetArgs(node, 'args2'))
|
||||||
|
self.assertEqual(['-n', 'first', 'second', '-p', '123,456', '-x'],
|
||||||
|
fdt_util.GetArgs(node, 'args3'))
|
||||||
with self.assertRaises(ValueError) as exc:
|
with self.assertRaises(ValueError) as exc:
|
||||||
fdt_util.GetArgs(self.node, 'missing')
|
fdt_util.GetArgs(self.node, 'missing')
|
||||||
self.assertIn(
|
self.assertIn(
|
||||||
|
Loading…
Reference in New Issue
Block a user