|
3 | 3 | import os |
4 | 4 | import os.path |
5 | 5 | import tarfile |
6 | | -from distutils.util import strtobool |
7 | 6 | from gettext import gettext as _ |
8 | 7 | from glob import glob |
9 | 8 | from pathlib import Path |
@@ -43,6 +42,21 @@ def __init__(self): |
43 | 42 | super().__init__(_("Cannot export artifacts that haven't been downloaded.")) |
44 | 43 |
|
45 | 44 |
|
| 45 | +def _ensure_bool(value): |
| 46 | + if isinstance(value, bool): |
| 47 | + return value |
| 48 | + if isinstance(value, str): |
| 49 | + if value.tolower() in ["yes", "y", "true", "t", "on", "1"]: |
| 50 | + return True |
| 51 | + if value.tolower() in ["no", "n", "false", "f", "off", "0"]: |
| 52 | + return False |
| 53 | + if value == 1: |
| 54 | + return True |
| 55 | + if value == 0: |
| 56 | + return False |
| 57 | + raise ValueError("Value {value:r} does not describe a boolean.") |
| 58 | + |
| 59 | + |
46 | 60 | def _validate_fs_export(content_artifacts): |
47 | 61 | """ |
48 | 62 | Args: |
@@ -346,9 +360,7 @@ def _version_match(curr_versions, prev_versions): |
346 | 360 | def _incremental_requested(the_export): |
347 | 361 | """Figure out that a) an incremental is requested, and b) it's possible.""" |
348 | 362 | the_exporter = the_export.exporter |
349 | | - full = the_export.params.get("full", True) |
350 | | - if isinstance(full, str): |
351 | | - full = bool(strtobool(full)) |
| 363 | + full = _ensure_bool(the_export.params.get("full", True)) |
352 | 364 | starting_versions_provided = len(the_export.params.get("start_versions", [])) > 0 |
353 | 365 | last_exists = the_exporter.last_export |
354 | 366 | return (starting_versions_provided or last_exists) and not full |
|
0 commit comments