From 89139428ab71bd93674bf637ada2f8e7817d1be2 Mon Sep 17 00:00:00 2001 From: Ajax Date: Wed, 15 Mar 2017 16:44:58 +0100 Subject: [PATCH] Add 'dump' sub-action for `sibyl config` --- sibyl/actions/config.py | 28 ++++++++++++++++------------ sibyl/config.py | 16 ++++++++++++++++ 2 files changed, 32 insertions(+), 12 deletions(-) diff --git a/sibyl/actions/config.py b/sibyl/actions/config.py index 7c99477..c829279 100644 --- a/sibyl/actions/config.py +++ b/sibyl/actions/config.py @@ -25,22 +25,26 @@ class ActionConfig(Action): _name_ = "config" _desc_ = "Configuration management" - _args_ = [(("-V", "--value"), {"help": "Return the value of a specific option"}), + _args_ = [ + (("-V", "--value"), {"help": "Return the value of a specific option"}), + (("-d", "--dump"), {"help": "Dump the current configuration", + "action": "store_true"}), ] def run(self): - if not self.args.value: - self.show() - exit(0) - - if self.args.value.endswith("_keys") and hasattr(config, - self.args.value[:-5]): - val = getattr(config, self.args.value[:-5]).keys() - elif hasattr(config, self.args.value): - val = getattr(config, self.args.value) + if self.args.dump: + print "\n".join(config.dump()) + elif self.args.value: + if self.args.value.endswith("_keys") and hasattr(config, + self.args.value[:-5]): + val = getattr(config, self.args.value[:-5]).keys() + elif hasattr(config, self.args.value): + val = getattr(config, self.args.value) + else: + val = "ERROR" + print val else: - val = "ERROR" - print val + self.show() def show(self): # Configuration files diff --git a/sibyl/config.py b/sibyl/config.py index 416da23..4ee6bbe 100644 --- a/sibyl/config.py +++ b/sibyl/config.py @@ -71,6 +71,22 @@ def parse_files(self, files): for name in cparser.options("tests"): self.config["tests"][name] = cparser.get("tests", name) + def dump(self): + """Dump the current configuration as a config file""" + out = [] + + # Find + out.append("[find]") + out.append("jit_engine = %s" % ",".join(self.config["jit_engine"])) + + # Tests + out.append("") + out.append("[tests]") + for name, path in self.config["tests"].iteritems(): + out.append("%s = %s" % (name, path)) + + return out + @property def jit_engine(self): """Name of engine to use for jit"""