diff options
author | Milosz Wasilewski <milosz.wasilewski@linaro.org> | 2016-06-10 09:48:50 +0100 |
---|---|---|
committer | Milosz Wasilewski <milosz.wasilewski@linaro.org> | 2016-06-10 09:48:50 +0100 |
commit | b391f4da9e4d5ce381924c7ba0e48f7847f9236e (patch) | |
tree | 10750ac727ffef066eac68cadc368373bd70f255 | |
parent | 8dc50d253ea8b723d36ccce1d2d7ef7ee9ad5a13 (diff) |
prepare-agenda.py: modified yaml parser to use OrderedDict
In order to preserve dict ordering in sysfs entries, which is important
for setting EAS parameters, yaml parser was updated to use OrderedDict
instead of ordinary dict.
Change-Id: Ie38b013401d7c53b0c26f785520e7947c6152532
Signed-off-by: Milosz Wasilewski <milosz.wasilewski@linaro.org>
-rwxr-xr-x | prepare-agenda.py | 20 |
1 files changed, 19 insertions, 1 deletions
diff --git a/prepare-agenda.py b/prepare-agenda.py index 061be7f..a44ef7d 100755 --- a/prepare-agenda.py +++ b/prepare-agenda.py @@ -21,6 +21,7 @@ # Author: Milosz Wasilewski <milosz.wasilewski@linaro.org> # +import collections import yaml from optparse import OptionParser @@ -29,6 +30,23 @@ SQLITE_DB_GLOBAL_PATH = "/root/db_results/" SQLITE_DB = 'sqlite_database' CONFIG = 'config' + +# Modifying the yaml parser to use an OrderedDict, rather then regular Python +# dict for mappings. This preservers the order in which the items are +# specified. See +# http://stackoverflow.com/a/21048064 + +_mapping_tag = yaml.resolver.BaseResolver.DEFAULT_MAPPING_TAG + +def dict_representer(dumper, data): + return dumper.represent_dict(data.iteritems()) + +def dict_constructor(loader, node): + return collections.OrderedDict(loader.construct_pairs(node)) + +yaml.add_representer(collections.OrderedDict, dict_representer) +yaml.add_constructor(_mapping_tag, dict_constructor) + if __name__ == '__main__': usage = "usage: %prog [OPTIONS]" @@ -49,4 +67,4 @@ if __name__ == '__main__': agenda_yaml[CONFIG][SQLITE_DB] = SQLITE_DB_GLOBAL_PATH + options.job_name + ".db" agenda.close() with open(options.agenda, 'w') as outfile: - outfile.write( yaml.dump(agenda_yaml, default_flow_style=True) ) + outfile.write( yaml.dump(agenda_yaml, default_flow_style=False) ) |