def RunDBA(callback):
  """Runs op on each table listed in --tables."""
  client = db_client.DBClient.Instance()
  op = options.options.op

  table = None
  if options.options.table:
    table = vf_schema.SCHEMA.GetTable(options.options.table)
    assert table, 'unrecognized table name: %s' % options.options.table
    cls = db_import.GetTableClass(table.name)

  key = None
  if options.options.hash_key and options.options.range_key:
    assert table.range_key_col
    key = db_client.DBKey(eval(options.options.hash_key), eval(options.options.range_key))
  elif options.options.hash_key:
    assert not table.range_key_col
    key = db_client.DBKey(eval(options.options.hash_key), None)

  start_key = eval(options.options.start_key) if options.options.start_key else None
  end_key = eval(options.options.end_key) if options.options.end_key else None
  range_desc = None
  if start_key and end_key:
    range_desc = db_client.RangeOperator([start_key, end_key], 'BETWEEN')
  elif start_key:
    range_desc = db_client.RangeOperator([start_key], 'GT')
  elif end_key:
    range_desc = db_client.RangeOperator([end_key], 'LT')

  user_id = None
  if options.options.user_id:
    user_id = eval(options.options.user_id)

  limit = None
  if options.options.limit:
    limit = eval(options.options.limit)

  if options.options.attributes:
    parser = AttrParser(table)
    attrs = parser.Run(options.options.attributes)
    if table and key:
      attrs[table.hash_key_col.name] = key.hash_key
      if key.range_key:
        attrs[table.range_key_col.name] = key.range_key
    logging.info('attributes: %s' % attrs)

  def _OnOp(*args, **kwargs):
    if args:
      logging.info('positional result args: %s' % pprint.pformat(args))
    if kwargs:
      logging.info('keyword result args: %s' % pprint.pformat(kwargs))
    callback()

  if op in ('query', 'update'):
    assert table, 'no table name specified for operation'
  if op in ('query'):
    assert table.range_key_col, 'Table %s is not composite' % table.name

  # Run the operation
  logging.info('executing %s' % op)
  if op == 'query':
    QueryRange(client, table, cls, key, range_desc, _OnOp)
  elif op == 'update':
    o = cls()
    o.UpdateFromKeywords(**attrs)
    o.Update(client, _OnOp)
  else:
    raise Exception('unrecognized op: %s' % op)
dataset/ETHPy150Open viewfinderco/viewfinder/backend/db/tools/dba.py/RunDBA/original