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