def _output_to_dict(cmdoutput, values_mapper=None):
 if isinstance(cmdoutput, dict):
  if ((cmdoutput['retcode'] != 0) or cmdoutput['stderr']):
   raise CommandExecutionError('RabbitMQ command failed: {0}'.format(cmdoutput['stderr']))
  cmdoutput = cmdoutput['stdout']
 ret = {}
 if (values_mapper is None):
  values_mapper = (lambda string: string.split(' DCTB '))
 data_rows = _strip_listing_to_done(cmdoutput.splitlines())
 for row in data_rows:
  try:
   (key, values) = row.split(' DCTB ', 1)
  except ValueError:
   log.debug("Could not find any values for key '{0}'. Setting to '{0}' to an empty string.".format(row))
   ret[row] = ''
   continue
  ret[key] = values_mapper(values)
 return ret

def _output_to_dict ( cmdoutput , values_mapper = None ) : if isinstance ( cmdoutput , dict ) : if ( ( cmdoutput [ 'retcode' ] != 0 ) or cmdoutput [ 'stderr' ] ) : raise CommandExecutionError ( 'RabbitMQ command failed: {0}' . format ( cmdoutput [ 'stderr' ] ) ) cmdoutput = cmdoutput [ 'stdout' ] ret = { } if ( values_mapper is None ) : values_mapper = ( lambda string : string . split ( ' DCTB ' ) ) data_rows = _strip_listing_to_done ( cmdoutput . splitlines ( ) ) for row in data_rows : try : ( key , values ) = row . split ( ' DCTB ' , 1 ) except ValueError : log . debug ( "Could not find any values for key '{0}'. Setting to '{0}' to an empty string." . format ( row ) ) ret [ row ] = '' continue ret [ key ] = values_mapper ( values ) return ret
convert rabbitmqctl output to a dict of data cmdoutput: string output of rabbitmqctl commands values_mapper: function object to process the values part of each line .