| OLD | NEW |
| 1 # Copyright 2016 The Chromium Authors. All rights reserved. | 1 # Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
| 4 | 4 |
| 5 """Fetches entities and iterate over and process them.""" | 5 """Fetches entities and iterate over and process them.""" |
| 6 | 6 |
| 7 import os | 7 import os |
| 8 | 8 |
| 9 import remote_api # pylint: disable=W | 9 import remote_api # pylint: disable=W |
| 10 | 10 |
| (...skipping 18 matching lines...) Expand all Loading... |
| 29 app_id, | 29 app_id, |
| 30 fields=None, | 30 fields=None, |
| 31 filter_func=None, | 31 filter_func=None, |
| 32 batch_size=_DEFAULT_BATCH_SIZE, | 32 batch_size=_DEFAULT_BATCH_SIZE, |
| 33 batch_run=False): # pragma: no cover. | 33 batch_run=False): # pragma: no cover. |
| 34 """Iterates entities queried by query. | 34 """Iterates entities queried by query. |
| 35 | 35 |
| 36 Args: | 36 Args: |
| 37 query (ndb.Query): The query to fetch entities. | 37 query (ndb.Query): The query to fetch entities. |
| 38 app_id (str): App engine app id. | 38 app_id (str): App engine app id. |
| 39 fields (list): Field names of an datastore model entity to be projected | 39 fields (list or None): Field names of an datastore model entity to be |
| 40 to a dict. If None provided, return the entities instead of projected | 40 projected to a dict. If None provided, return the entities instead of |
| 41 dict. | 41 projected dict. |
| 42 filter_func (function): A function that does in memory filtering. | 42 filter_func (function): A function that does in memory filtering. |
| 43 batch_size (int): The number of entities to query at one time. | 43 batch_size (int): The number of entities to query at one time. |
| 44 batch_run (bool): If True, iterate batches of entities, if | 44 batch_run (bool): If True, iterate batches of entities, if |
| 45 False, iterate each entity. | 45 False, iterate each entity. |
| 46 | 46 |
| 47 An exmaple is available in crash_printer/print_crash.py. | 47 An exmaple is available in crash_printer/print_crash.py. |
| 48 """ | 48 """ |
| 49 remote_api.EnableRemoteApi(app_id) | 49 remote_api.EnableRemoteApi(app_id) |
| 50 | 50 |
| 51 cursor = None | 51 cursor = None |
| (...skipping 12 matching lines...) Expand all Loading... |
| 64 if batch_run: | 64 if batch_run: |
| 65 yield entities | 65 yield entities |
| 66 else: | 66 else: |
| 67 for entity in entities: | 67 for entity in entities: |
| 68 yield entity | 68 yield entity |
| 69 | 69 |
| 70 if not more: | 70 if not more: |
| 71 break | 71 break |
| 72 | 72 |
| 73 cursor = next_cursor | 73 cursor = next_cursor |
| OLD | NEW |