new_contents: #! /usr/bin/python
  #
  # Dump the rules from the ICAT to a file or to stdout.
  #
  
  import logging
  import icat
  import icat.config
  from icat.dumpfile import open_dumpfile
  try:
      import icat.dumpfile_xml
  except ImportError:
      pass
  try:
      import icat.dumpfile_yaml
  except ImportError:
      pass
  
  logging.basicConfig(level=logging.INFO)
  #logging.getLogger('suds.client').setLevel(logging.DEBUG)
  
  formats = icat.dumpfile.Backends.keys()
  if len(formats) == 0:
      raise RuntimeError("No datafile backends available.")
  
  config = icat.config.Config()
  config.add_variable('file', ("-o", "--outputfile"), 
                      dict(help="output file name or '-' for stdout"),
                      default='-')
  config.add_variable('format', ("-f", "--format"), 
                      dict(help="output file format", choices=formats),
                      default='YAML')
  conf = config.getconfig()
  
  client = icat.Client(conf.url, **conf.client_kwargs)
  if client.apiversion < '4.2.99':
      raise RuntimeError("Sorry, ICAT version %s is too old, need 4.3.0 or newer."
                         % client.apiversion)
  client.login(conf.auth, conf.credentials)
  
  
  rules = ["SELECT r FROM Rule r ORDER BY r.id INCLUDE r.grouping"]
  
  with open_dumpfile(client, conf.file, conf.format, 'w') as dumpfile:
      dumpfile.writedata(rules)
  
subject: Add dumprules.py.