From aa220334d88d2ec5389fe9adbb648efd28dd90ae Mon Sep 17 00:00:00 2001 From: Frederic Massart Date: Mon, 1 Jul 2013 11:16:46 +0800 Subject: [PATCH] Config show can display objects --- lib/commands/config.py | 41 +++++++++++++++++++++++------------------ 1 file changed, 23 insertions(+), 18 deletions(-) diff --git a/lib/commands/config.py b/lib/commands/config.py index 4de8e3c..9023d9a 100644 --- a/lib/commands/config.py +++ b/lib/commands/config.py @@ -90,32 +90,37 @@ class ConfigCommand(Command): _description = 'Manage your configuration' _loadWorkplace = False + def dictDisplay(self, data, ident=0): + for name in sorted(data.keys()): + setting = data[name] + if type(setting) != dict: + print u'{0:<20}: {1}'.format(u' ' * ident + name, setting) + else: + print u' ' * ident + '[%s]' % name + self.dictDisplay(setting, ident + 2) + + def flatDisplay(self, data, parent=''): + for name in sorted(data.keys()): + setting = data[name] + if type(setting) != dict: + print u'%s: %s' % (parent + name, setting) + else: + self.flatDisplay(setting, parent + name + u'.') + def run(self, args): if args.action == 'list': - def show_list(settings, ident): - for name in sorted(settings.keys()): - setting = settings[name] - if type(setting) != dict: - print u'{0:<20}: {1}'.format(u' ' * ident + name, setting) - else: - print u' ' * ident + '[%s]' % name - show_list(setting, ident + 2) - show_list(self.C.get(), 0) + self.dictDisplay(self.C.get(), 0) elif args.action == 'flatlist': - def show_list(settings, parent=''): - for name in sorted(settings.keys()): - setting = settings[name] - if type(setting) != dict: - print u'%s: %s' % (parent + name, setting) - else: - show_list(setting, parent + name + u'.') - show_list(self.C.get()) + self.flatDisplay(self.C.get()) elif args.action == 'show': setting = self.C.get(args.setting) if setting != None: - print setting + if type(setting) == dict: + self.flatDisplay(setting, args.setting + u'.') + else: + print setting elif args.action == 'set': setting = args.setting -- 2.11.0