@gen.engine
def Grep(args, callback):
  assert len(args) >= 2
  pattern = re.compile(args[0])
  files = args[1:]

  bucket = store = None
  for f in files:
    # Parse file name and extract bucket and relative path.
    resolved = store_utils.ParseFullPath(f)
    assert resolved is not None, 'Cannot determine bucket from %s' % f
    b, path = resolved
    assert bucket is None or bucket == b, 'Input files must all be in the same bucket'

    if store is None:
      # Initialize ObjectStore for this bucket.
      bucket = b
      store = ObjectStore.GetInstance(bucket)

    # Read file and iterate over each line.
    contents = yield gen.Task(store_utils.GetFileContents, store, path)
    for line in contents.split('\n'):
      if pattern.search(line):
        print '%s:%s' % (f, line)

  callback()
Grep a set of files.
dataset/ETHPy150Open viewfinderco/viewfinder/backend/storage/tools/s3util.py/Grep