Config can be listed as a flat list
authorFred <fmcell@gmail.com>
Sun, 11 Nov 2012 09:14:49 +0000 (17:14 +0800)
committerFred <fmcell@gmail.com>
Sun, 11 Nov 2012 11:02:19 +0000 (19:02 +0800)
moodle-config.py

index 822d176..2c65bda 100755 (executable)
@@ -29,7 +29,7 @@ from lib.config import C
 
 # Arguments
 parser = argparse.ArgumentParser(description='Manage your configuration')
-parser.add_argument('command', metavar='command', choices=['list', 'show', 'set'], help='the action to perform')
+parser.add_argument('command', metavar='command', choices=['flatlist', 'list', 'show', 'set'], help='the action to perform')
 parser.add_argument('arguments', metavar='arguments', default=None, nargs='*', help='arguments for the command')
 args = parser.parse_args()
 
@@ -41,9 +41,17 @@ if args.command == 'list':
             else:
                 print u' ' * ident + '[%s]' % name
                 show_list(setting, ident + 2)
-
     show_list(C.get(), 0)
 
+elif args.command == 'flatlist':
+    def show_list(settings, parent = ''):
+        for name, setting in settings.items():
+            if type(setting) != dict:
+                print u'%s: %s' % (parent + name, setting)
+            else:
+                show_list(setting, parent + name + u'.')
+    show_list(C.get())
+
 elif args.command == 'show':
     if len(args.arguments) != 1:
         debug('Too few/many arguments. One needed: moodle config show settingName')