|
1 | 1 | '''Provides an object model for a Singer Catalog.''' |
2 | | - |
3 | 2 | import json |
4 | 3 | import sys |
5 | 4 |
|
6 | | -from singer.schema import Schema |
| 5 | +from . import metadata as metadata_module |
| 6 | +from .bookmarks import get_currently_syncing |
| 7 | +from .logger import get_logger |
| 8 | +from .schema import Schema |
| 9 | + |
| 10 | +LOGGER = get_logger() |
| 11 | + |
7 | 12 |
|
8 | 13 | # pylint: disable=too-many-instance-attributes |
9 | 14 | class CatalogEntry(): |
@@ -33,7 +38,9 @@ def __eq__(self, other): |
33 | 38 | return self.__dict__ == other.__dict__ |
34 | 39 |
|
35 | 40 | def is_selected(self): |
36 | | - return self.schema.selected # pylint: disable=no-member |
| 41 | + mdata = metadata_module.to_map(self.metadata) |
| 42 | + # pylint: disable=no-member |
| 43 | + return self.schema.selected or metadata_module.get(mdata, (), 'selected') |
37 | 44 |
|
38 | 45 | def to_dict(self): |
39 | 46 | result = {} |
@@ -116,3 +123,27 @@ def get_stream(self, tap_stream_id): |
116 | 123 | if stream.tap_stream_id == tap_stream_id: |
117 | 124 | return stream |
118 | 125 | return None |
| 126 | + |
| 127 | + def _shuffle_streams(self, state): |
| 128 | + currently_syncing = get_currently_syncing(state) |
| 129 | + |
| 130 | + if currently_syncing is None: |
| 131 | + return self.streams |
| 132 | + |
| 133 | + matching_index = 0 |
| 134 | + for i, catalog_entry in enumerate(self.streams): |
| 135 | + if catalog_entry.tap_stream_id == currently_syncing: |
| 136 | + matching_index = i |
| 137 | + break |
| 138 | + top_half = self.streams[matching_index:] |
| 139 | + bottom_half = self.streams[:matching_index] |
| 140 | + return top_half + bottom_half |
| 141 | + |
| 142 | + |
| 143 | + def get_selected_streams(self, state): |
| 144 | + for stream in self._shuffle_streams(state): |
| 145 | + if not stream.is_selected(): |
| 146 | + LOGGER.info('Skipping stream: %s', stream.tap_stream_id) |
| 147 | + continue |
| 148 | + |
| 149 | + yield stream |
0 commit comments