Edit instance config from mdk info
authorFrederic Massart <fred@moodle.com>
Fri, 1 Feb 2013 04:12:24 +0000 (12:12 +0800)
committerFrederic Massart <fred@moodle.com>
Fri, 1 Feb 2013 04:12:24 +0000 (12:12 +0800)
extra/bash_completion
moodle-info.py

index db29685..9483198 100644 (file)
@@ -99,7 +99,7 @@ function _moodle() {
                 fi
                 ;;
             info)
-                OPTS="--list --var"
+                OPTS="--list --var --edit"
                 if [[ "${COMP_CWORD}" == 2 && "$CUR" != -* ]]; then
                     OPTS="$OPTS $($BIN info -ln)"
                 elif [[ "${COMP_CWORD}" == 3 && ("$PREV" == "--list" || "$PREV" == "-l") ]]; then
index 8d3190a..6f48e0b 100755 (executable)
@@ -35,7 +35,8 @@ parser.add_argument('-l', '--list', action='store_true', help='list the instance
 parser.add_argument('-i', '--integration', action='store_true', help='used with --list, only display integration instances', dest='integration')
 parser.add_argument('-s', '--stable', action='store_true', help='used with --list, only display stable instances', dest='stable')
 parser.add_argument('-n', '--name-only', action='store_true', help='used with --list, only display instances name', dest='nameonly')
-parser.add_argument('-v', '--var', metavar='var', default=None, nargs='?', help='variable to output. Does not work with --list.')
+parser.add_argument('-v', '--var', metavar='var', default=None, nargs='?', help='variable to output or edit')
+parser.add_argument('-e', '--edit', metavar='value', nargs='?', help='value to set to the variable (--var). This value will be set in the config file of the instance. Prepend the value with i: or b: to set as int or boolean. DO NOT use names used by MDK (identifier, stablebranch, ...).', dest='edit')
 parser.add_argument('name', metavar='name', default=None, nargs='?', help='name of the instance')
 args = parser.parse_args()
 
@@ -60,9 +61,23 @@ else:
         debug('This is not a Moodle instance')
         sys.exit(1)
 
-    # Printing variable
+    # Printing/Editing variable.
     if args.var != None:
-        print M.get(args.var)
+        # Edit a value.
+        if args.edit != None:
+            val = args.edit
+            if val.startswith('b:'):
+                val = True if val[2:].lower() in ['1', 'true'] else False
+            elif val.startswith('i:'):
+                try:
+                    val = int(val[2:])
+                except ValueError:
+                    # Not a valid int, let's consider it a string.
+                    pass
+            M.updateConfig(args.var, val)
+            debug('Set $CFG->%s to %s on %s' % (args.var, str(val), M.get('identifier')))
+        else:
+            print M.get(args.var)
 
     # Printing info
     else: