
import sys
from xml.etree import ElementTree
from xml.etree import ElementPath

def main():
    conf = ElementTree.parse(file(sys.argv[1]))
    if sys.argv[2] == 'postgresql':
        value = 'true'
    elif sys.argv[2] == 'filesystem':
        value = 'false'
    else:
        raise RuntimeError("Don't know what to do with %r" % (sys.argv[2],))
    replace(conf.getiterator(), value)
    conf.write(sys.stdout)


def replace(elements, value):
    found = False
    for ele in elements:
        if found:
            ele.tag = value
            return
        if ele.tag == 'key' and ele.text == 'UseDatabase':
            found = True
    raise RuntimeError("Failed to find <key>UseDatabase</key>")


import sys
from xml.etree import ElementTree
from xml.etree import ElementPath

def main():
    conf = ElementTree.parse(file(sys.argv[1]))
    if sys.argv[2] == 'postgresql':
        value = 'true'
    elif sys.argv[2] == 'filesystem':
        value = 'false'
    else:
        raise RuntimeError("Don't know what to do with %r" % (sys.argv[2],))

    # Here are the config changes we make - use the specified backend
    replace(conf.getiterator(), 'UseDatabase', value)
    # - and disable the response cache
    replace(conf.getiterator(), 'EnableResponseCache', 'false')
    conf.write(sys.stdout)


def replace(elements, key, value):
    found = False
    for ele in elements:
        if found:
            ele.tag = value
            return
        if ele.tag == 'key' and ele.text == key:
            found = True
    raise RuntimeError("Failed to find <key>UseDatabase</key>")

Rewrite the config to disable the response cache, too.
Rewrite the config to disable the response cache, too.

git-svn-id: 81e381228600e5752b80483efd2b45b26c451ea2@6929 e27351fd-9f3e-4f54-a53b-843176b1656c

  
  import sys
  from xml.etree import ElementTree
  from xml.etree import ElementPath
  
  def main():
      conf = ElementTree.parse(file(sys.argv[1]))
      if sys.argv[2] == 'postgresql':
          value = 'true'
      elif sys.argv[2] == 'filesystem':
          value = 'false'
      else:
          raise RuntimeError("Don't know what to do with %r" % (sys.argv[2],))
+ 
+     # Here are the config changes we make - use the specified backend
-     replace(conf.getiterator(), value)
+     replace(conf.getiterator(), 'UseDatabase', value)
+     # - and disable the response cache
+     replace(conf.getiterator(), 'EnableResponseCache', 'false')
      conf.write(sys.stdout)
  
  
- def replace(elements, value):
+ def replace(elements, key, value):
      found = False
      for ele in elements:
          if found:
              ele.tag = value
              return
-         if ele.tag == 'key' and ele.text == 'UseDatabase':
+         if ele.tag == 'key' and ele.text == key:
              found = True
      raise RuntimeError("Failed to find <key>UseDatabase</key>")
  
Rewrite the config to disable the response cache, too.
## Code Before:

import sys
from xml.etree import ElementTree
from xml.etree import ElementPath

def main():
    conf = ElementTree.parse(file(sys.argv[1]))
    if sys.argv[2] == 'postgresql':
        value = 'true'
    elif sys.argv[2] == 'filesystem':
        value = 'false'
    else:
        raise RuntimeError("Don't know what to do with %r" % (sys.argv[2],))
    replace(conf.getiterator(), value)
    conf.write(sys.stdout)


def replace(elements, value):
    found = False
    for ele in elements:
        if found:
            ele.tag = value
            return
        if ele.tag == 'key' and ele.text == 'UseDatabase':
            found = True
    raise RuntimeError("Failed to find <key>UseDatabase</key>")

## Instruction:
Rewrite the config to disable the response cache, too.
## Code After:

import sys
from xml.etree import ElementTree
from xml.etree import ElementPath

def main():
    conf = ElementTree.parse(file(sys.argv[1]))
    if sys.argv[2] == 'postgresql':
        value = 'true'
    elif sys.argv[2] == 'filesystem':
        value = 'false'
    else:
        raise RuntimeError("Don't know what to do with %r" % (sys.argv[2],))

    # Here are the config changes we make - use the specified backend
    replace(conf.getiterator(), 'UseDatabase', value)
    # - and disable the response cache
    replace(conf.getiterator(), 'EnableResponseCache', 'false')
    conf.write(sys.stdout)


def replace(elements, key, value):
    found = False
    for ele in elements:
        if found:
            ele.tag = value
            return
        if ele.tag == 'key' and ele.text == key:
            found = True
    raise RuntimeError("Failed to find <key>UseDatabase</key>")
