Gets a list of exported paths, ordered by timestamp (ascending). The two patterns are necessary since glob doesn't support general regexes that are required for stricter matches that avoid temporary files. Args: glob_pattern (string): Input to tf.gfile.Glob. regex_pattern (string): R
(glob_pattern, regex_pattern)
| 24 | |
| 25 | |
| 26 | def export_paths(glob_pattern, regex_pattern): |
| 27 | """Gets a list of exported paths, ordered by timestamp (ascending). |
| 28 | |
| 29 | The two patterns are necessary since glob doesn't support general regexes that |
| 30 | are required for stricter matches that avoid temporary files. |
| 31 | |
| 32 | Args: |
| 33 | glob_pattern (string): Input to tf.gfile.Glob. |
| 34 | regex_pattern (string): Regular expression for additional filtering. This |
| 35 | should have a match group named "timestamp". |
| 36 | |
| 37 | Returns: |
| 38 | Filenames sorted by timestamp (later paths at the end). |
| 39 | """ |
| 40 | matcher = re.compile(regex_pattern) |
| 41 | filtered_exports = [] # (int timestamp, string path) pairs |
| 42 | |
| 43 | for filename in tf.gfile.Glob(glob_pattern): |
| 44 | match = matcher.match(filename) |
| 45 | if match: |
| 46 | # Gets the timestamp as an integer, instead of comparing it lexically. |
| 47 | timestamp = int(match.groupdict().get("timestamp", "0")) |
| 48 | filtered_exports.append((timestamp, filename)) |
| 49 | |
| 50 | return [filename for timestamp, filename in sorted(filtered_exports)] |
| 51 | |
| 52 | |
| 53 | def latest_export_path(glob_pattern, regex_pattern): |
no test coverage detected
searching dependent graphs…