| |
@@ -367,6 +367,7 @@
|
| |
except IOError as e:
|
| |
print("Download failed:")
|
| |
print(e)
|
| |
+ raise e
|
| |
|
| |
except KeyboardInterrupt:
|
| |
if os.path.isfile(path):
|
| |
@@ -383,21 +384,41 @@
|
| |
if not value:
|
| |
value = self.sources[number]
|
| |
|
| |
- self._get_file(value, directory, force, dry)
|
| |
+ try:
|
| |
+ self._get_file(value, directory, force, dry)
|
| |
+ return True
|
| |
+
|
| |
+ except IOError:
|
| |
+ return False
|
| |
|
| |
def get_patch(self, number: int, directory: str, force: bool, dry: bool, value: str = None):
|
| |
if not value:
|
| |
value = self.patches[number]
|
| |
|
| |
- self._get_file(value, directory, force, dry)
|
| |
+ try:
|
| |
+ self._get_file(value, directory, force, dry)
|
| |
+ return True
|
| |
+
|
| |
+ except IOError:
|
| |
+ return False
|
| |
|
| |
def get_sources(self, directory: str, force: bool, dry: bool):
|
| |
+ failure = False
|
| |
+
|
| |
for number, value in self.sources.items():
|
| |
- self.get_source(number, directory, force, dry, value)
|
| |
+ if self.get_source(number, directory, force, dry, value):
|
| |
+ failure = True
|
| |
+
|
| |
+ return failure
|
| |
|
| |
def get_patches(self, directory: str, force: bool, dry: bool):
|
| |
+ failure = False
|
| |
+
|
| |
for number, value in self.patches.items():
|
| |
- self.get_patch(number, directory, force, dry, value)
|
| |
+ if self.get_patch(number, directory, force, dry, value):
|
| |
+ failure = True
|
| |
+
|
| |
+ return failure
|
| |
|
| |
|
| |
def main() -> int:
|
| |
@@ -496,6 +517,8 @@
|
| |
else:
|
| |
directory = os.getcwd()
|
| |
|
| |
+ tasks = []
|
| |
+
|
| |
if args["source"]:
|
| |
numbers = split_numbers(args["source"])
|
| |
|
| |
@@ -504,10 +527,10 @@
|
| |
print("No patch with number '{}' found.".format(number))
|
| |
continue
|
| |
|
| |
- spec.get_source(number, directory, force, dry)
|
| |
+ tasks.append((spec.get_source, (number, directory, force, dry)))
|
| |
|
| |
elif args["sources"] and not args["patch"]:
|
| |
- spec.get_sources(directory, force, dry)
|
| |
+ tasks.append((spec.get_sources, (directory, force, dry)))
|
| |
|
| |
if args["patch"]:
|
| |
numbers = split_numbers(args["patch"])
|
| |
@@ -517,10 +540,21 @@
|
| |
print("No patch with number '{}' found.".format(number))
|
| |
continue
|
| |
|
| |
- spec.get_patch(number, directory, force, dry)
|
| |
+ tasks.append((spec.get_patch, (number, directory, force, dry)))
|
| |
|
| |
elif args["patches"] and not args["source"]:
|
| |
- spec.get_patches(directory, force, dry)
|
| |
+ tasks.append((spec.get_patches, (directory, force, dry)))
|
| |
+
|
| |
+ failure = False
|
| |
+
|
| |
+ for task, args in tasks:
|
| |
+ fail = task(*args)
|
| |
+
|
| |
+ if fail:
|
| |
+ failure = True
|
| |
+
|
| |
+ if failure:
|
| |
+ return 1
|
| |
|
| |
return 0
|
| |
|
| |
Exceptions thrown by requests (which are subclasses of IOError) are right now caught, but ignored. This results in a zero exit code, even if the download fails (c.f. https://bugzilla.redhat.com/show_bug.cgi?id=2096624 ).
This PR changes the download() function to re-raise any IOErrors that occur.
Additionally, the main() function is slightly refactored, to collect requested tasks and execute them in a loop. This way, any error handling (i.e. catching IOError and returning a non-zero exit code in that case) can happen in one place.