Revision eac9b7b8
b/lib/utils/text.py | ||
---|---|---|
654 | 654 |
return [line for line in map(lambda s: s.strip(), text.splitlines()) |
655 | 655 |
# Ignore empty lines and comments |
656 | 656 |
if line and not line.startswith("#")] |
657 |
|
|
658 |
|
|
659 |
def FormatKeyValue(data): |
|
660 |
"""Formats a dictionary as "key=value" parameters. |
|
661 |
|
|
662 |
The keys are sorted to have a stable order. |
|
663 |
|
|
664 |
@type data: dict |
|
665 |
@rtype: list of string |
|
666 |
|
|
667 |
""" |
|
668 |
return ["%s=%s" % (key, value) for (key, value) in sorted(data.items())] |
b/test/ganeti.utils.text_unittest.py | ||
---|---|---|
639 | 639 |
]) |
640 | 640 |
|
641 | 641 |
|
642 |
class TestFormatKeyValue(unittest.TestCase): |
|
643 |
def test(self): |
|
644 |
self.assertEqual(utils.FormatKeyValue({}), []) |
|
645 |
self.assertEqual(utils.FormatKeyValue({1: 2}), ["1=2"]) |
|
646 |
self.assertEqual(utils.FormatKeyValue({ |
|
647 |
"zzz": "0", |
|
648 |
"aaa": "1", |
|
649 |
}), |
|
650 |
["aaa=1", "zzz=0"]) |
|
651 |
|
|
652 |
|
|
642 | 653 |
if __name__ == "__main__": |
643 | 654 |
testutils.GanetiTestProgram() |
Also available in: Unified diff