Merge ppa-dev-tools:error-handling-cleanup into ppa-dev-tools:main
- Git
- lp:ppa-dev-tools
- error-handling-cleanup
- Merge into main
Status: | Merged |
---|---|
Merged at revision: | 03b736c6a37efe9f7fd81238c7a6ec451d7e5018 |
Proposed branch: | ppa-dev-tools:error-handling-cleanup |
Merge into: | ppa-dev-tools:main |
Diff against target: |
385 lines (+65/-36) 2 files modified
ppa/ppa.py (+10/-10) scripts/ppa (+55/-26) |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Athos Ribeiro (community) | Approve | ||
Canonical Server Reporter | Pending | ||
Review via email: mp+461580@code.launchpad.net |
Commit message
Description of the change
Several cleanups relating to exception handling and error exit codes.
These aren't fixing specific issues that have come up in practice, but rather were noticed in recent refactoring and code cleanup efforts on other branches. I think these are worth getting reviewed and landed first.
Bryce Harrington (bryce) wrote : | # |
Thanks Athos, that's a good idea. I've added it defined as EX_KEYBOARD_
$ git merge --ff-only error-handling-
Updating 1a457e7..03b736c
Fast-forward
ppa/ppa.py | 20 +++++++
scripts/ppa | 81 +++++++
2 files changed, 65 insertions(+), 36 deletions(-)
$ git push
Total 0 (delta 0), reused 0 (delta 0), pack-reused 0
To git+ssh:
1a457e7..03b736c main -> main
Preview Diff
1 | diff --git a/ppa/ppa.py b/ppa/ppa.py | |||
2 | index bb28c21..5fd8056 100755 | |||
3 | --- a/ppa/ppa.py | |||
4 | +++ b/ppa/ppa.py | |||
5 | @@ -35,7 +35,7 @@ class PendingReason(enum.Enum): | |||
6 | 35 | BUILD_MISSING = enum.auto() # Build was expected, but missing | 35 | BUILD_MISSING = enum.auto() # Build was expected, but missing |
7 | 36 | 36 | ||
8 | 37 | 37 | ||
10 | 38 | class PpaDoesNotExist(BaseException): | 38 | class PpaNotFoundError(Exception): |
11 | 39 | """Exception indicating a requested PPA could not be found.""" | 39 | """Exception indicating a requested PPA could not be found.""" |
12 | 40 | 40 | ||
13 | 41 | def __init__(self, ppa_name, owner_name, message=None): | 41 | def __init__(self, ppa_name, owner_name, message=None): |
14 | @@ -124,7 +124,7 @@ class Ppa: | |||
15 | 124 | 124 | ||
16 | 125 | :rtype: archive | 125 | :rtype: archive |
17 | 126 | :returns: The Launchpad archive object. | 126 | :returns: The Launchpad archive object. |
19 | 127 | :raises PpaDoesNotExist: Raised if a PPA does not exist in Launchpad. | 127 | :raises PpaNotFoundError: Raised if a PPA does not exist in Launchpad. |
20 | 128 | """ | 128 | """ |
21 | 129 | if not self._service: | 129 | if not self._service: |
22 | 130 | raise AttributeError("Ppa object not connected to the Launchpad service") | 130 | raise AttributeError("Ppa object not connected to the Launchpad service") |
23 | @@ -132,7 +132,7 @@ class Ppa: | |||
24 | 132 | owner = self._service.people[self.owner_name] | 132 | owner = self._service.people[self.owner_name] |
25 | 133 | return owner.getPPAByName(name=self.ppa_name) | 133 | return owner.getPPAByName(name=self.ppa_name) |
26 | 134 | except NotFound: | 134 | except NotFound: |
28 | 135 | raise PpaDoesNotExist(self.ppa_name, self.owner_name) | 135 | raise PpaNotFoundError(self.ppa_name, self.owner_name) |
29 | 136 | 136 | ||
30 | 137 | @lru_cache | 137 | @lru_cache |
31 | 138 | def exists(self) -> bool: | 138 | def exists(self) -> bool: |
32 | @@ -140,7 +140,7 @@ class Ppa: | |||
33 | 140 | try: | 140 | try: |
34 | 141 | self.archive | 141 | self.archive |
35 | 142 | return True | 142 | return True |
37 | 143 | except PpaDoesNotExist: | 143 | except PpaNotFoundError: |
38 | 144 | return False | 144 | return False |
39 | 145 | 145 | ||
40 | 146 | @property | 146 | @property |
41 | @@ -189,7 +189,7 @@ class Ppa: | |||
42 | 189 | self.ppa_description = description | 189 | self.ppa_description = description |
43 | 190 | try: | 190 | try: |
44 | 191 | archive = self.archive | 191 | archive = self.archive |
46 | 192 | except PpaDoesNotExist as e: | 192 | except PpaNotFoundError as e: |
47 | 193 | print(e) | 193 | print(e) |
48 | 194 | return False | 194 | return False |
49 | 195 | archive.description = description | 195 | archive.description = description |
50 | @@ -243,7 +243,7 @@ class Ppa: | |||
51 | 243 | """ | 243 | """ |
52 | 244 | try: | 244 | try: |
53 | 245 | return [proc.name for proc in self.archive.processors] | 245 | return [proc.name for proc in self.archive.processors] |
55 | 246 | except PpaDoesNotExist as e: | 246 | except PpaNotFoundError as e: |
56 | 247 | sys.stderr.write(e) | 247 | sys.stderr.write(e) |
57 | 248 | return None | 248 | return None |
58 | 249 | 249 | ||
59 | @@ -268,7 +268,7 @@ class Ppa: | |||
60 | 268 | try: | 268 | try: |
61 | 269 | self.archive.setProcessors(processors=procs) | 269 | self.archive.setProcessors(processors=procs) |
62 | 270 | return True | 270 | return True |
64 | 271 | except PpaDoesNotExist as e: | 271 | except PpaNotFoundError as e: |
65 | 272 | sys.stderr.write(e) | 272 | sys.stderr.write(e) |
66 | 273 | return False | 273 | return False |
67 | 274 | 274 | ||
68 | @@ -345,7 +345,7 @@ class Ppa: | |||
69 | 345 | self.archive.getPublishedBinaries( | 345 | self.archive.getPublishedBinaries( |
70 | 346 | created_since_date=created_since_date, status="Published", | 346 | created_since_date=created_since_date, status="Published", |
71 | 347 | binary_name=name)) | 347 | binary_name=name)) |
73 | 348 | except PpaDoesNotExist as e: | 348 | except PpaNotFoundError as e: |
74 | 349 | print(e) | 349 | print(e) |
75 | 350 | return None | 350 | return None |
76 | 351 | # elif series: | 351 | # elif series: |
77 | @@ -386,7 +386,7 @@ class Ppa: | |||
78 | 386 | created_since_date=created_since_date, | 386 | created_since_date=created_since_date, |
79 | 387 | status="Published", | 387 | status="Published", |
80 | 388 | source_name=name)) | 388 | source_name=name)) |
82 | 389 | except PpaDoesNotExist as e: | 389 | except PpaNotFoundError as e: |
83 | 390 | print(e) | 390 | print(e) |
84 | 391 | return None | 391 | return None |
85 | 392 | 392 | ||
86 | @@ -403,7 +403,7 @@ class Ppa: | |||
87 | 403 | """ | 403 | """ |
88 | 404 | try: | 404 | try: |
89 | 405 | return self.archive.lp_delete() | 405 | return self.archive.lp_delete() |
91 | 406 | except PpaDoesNotExist as e: | 406 | except PpaNotFoundError as e: |
92 | 407 | print(e) | 407 | print(e) |
93 | 408 | return True | 408 | return True |
94 | 409 | except BadRequest: | 409 | except BadRequest: |
95 | diff --git a/scripts/ppa b/scripts/ppa | |||
96 | index 76c32c5..2d2937e 100755 | |||
97 | --- a/scripts/ppa | |||
98 | +++ b/scripts/ppa | |||
99 | @@ -82,7 +82,7 @@ from ppa.ppa import ( | |||
100 | 82 | get_ppa, | 82 | get_ppa, |
101 | 83 | ppa_address_split, | 83 | ppa_address_split, |
102 | 84 | Ppa, | 84 | Ppa, |
104 | 85 | PpaDoesNotExist, | 85 | PpaNotFoundError, |
105 | 86 | PendingReason | 86 | PendingReason |
106 | 87 | ) | 87 | ) |
107 | 88 | from ppa.ppa_group import PpaGroup, PpaAlreadyExists | 88 | from ppa.ppa_group import PpaGroup, PpaAlreadyExists |
108 | @@ -94,6 +94,8 @@ from ppa.trigger import get_triggers, show_triggers | |||
109 | 94 | import ppa.debug | 94 | import ppa.debug |
110 | 95 | from ppa.debug import dbg, warn, error | 95 | from ppa.debug import dbg, warn, error |
111 | 96 | 96 | ||
112 | 97 | EX_KEYBOARD_INTERRUPT = 130 | ||
113 | 98 | |||
114 | 97 | 99 | ||
115 | 98 | def UNIMPLEMENTED(): | 100 | def UNIMPLEMENTED(): |
116 | 99 | """Marks functionality that's not yet been coded""" | 101 | """Marks functionality that's not yet been coded""" |
117 | @@ -482,6 +484,12 @@ def create_config(lp: Lp, args: argparse.Namespace) -> dict[str, Any]: | |||
118 | 482 | # Assume defaults | 484 | # Assume defaults |
119 | 483 | dbg("Using default config since no config file found at {config_path}") | 485 | dbg("Using default config since no config file found at {config_path}") |
120 | 484 | config = dict(DEFAULT_CONFIG) | 486 | config = dict(DEFAULT_CONFIG) |
121 | 487 | except OSError as err: | ||
122 | 488 | error(f"Could not open {config_path}: {str(err)}") | ||
123 | 489 | return None | ||
124 | 490 | except YAMLError as err: | ||
125 | 491 | error(f"Invalid config file {config_path}: {str(err)}") | ||
126 | 492 | return None | ||
127 | 485 | 493 | ||
128 | 486 | # Map all non-empty elements from argparse Namespace into config dict | 494 | # Map all non-empty elements from argparse Namespace into config dict |
129 | 487 | config.update({k: v for k, v in vars(args).items() if v is not None}) | 495 | config.update({k: v for k, v in vars(args).items() if v is not None}) |
130 | @@ -538,6 +546,9 @@ def command_create(lp: Lp, config: dict[str, str]) -> int: | |||
131 | 538 | :rtype: int | 546 | :rtype: int |
132 | 539 | :returns: Status code OK (0) on success, non-zero on error. | 547 | :returns: Status code OK (0) on success, non-zero on error. |
133 | 540 | """ | 548 | """ |
134 | 549 | if not lp: | ||
135 | 550 | return os.EX_UNAVAILABLE | ||
136 | 551 | |||
137 | 541 | # Take description from stdin if it's not a tty | 552 | # Take description from stdin if it's not a tty |
138 | 542 | description = config.get('description') | 553 | description = config.get('description') |
139 | 543 | if not description and not sys.stdin.isatty(): | 554 | if not description and not sys.stdin.isatty(): |
140 | @@ -599,9 +610,9 @@ def command_create(lp: Lp, config: dict[str, str]) -> int: | |||
141 | 599 | return os.EX_NOUSER | 610 | return os.EX_NOUSER |
142 | 600 | except PpaAlreadyExists as e: | 611 | except PpaAlreadyExists as e: |
143 | 601 | warn(o2str(e.message)) | 612 | warn(o2str(e.message)) |
145 | 602 | return 3 | 613 | return os.EX_CANTCREAT |
146 | 603 | except KeyboardInterrupt: | 614 | except KeyboardInterrupt: |
148 | 604 | return 2 | 615 | return EX_KEYBOARD_INTERRUPT |
149 | 605 | print("Unhandled error") | 616 | print("Unhandled error") |
150 | 606 | return 1 | 617 | return 1 |
151 | 607 | 618 | ||
152 | @@ -614,6 +625,9 @@ def command_credentials(lp: Lp, config: dict[str, str]) -> int: | |||
153 | 614 | :rtype: int | 625 | :rtype: int |
154 | 615 | :returns: Status code OK (0) on success, non-zero on error. | 626 | :returns: Status code OK (0) on success, non-zero on error. |
155 | 616 | """ | 627 | """ |
156 | 628 | if not lp: | ||
157 | 629 | return os.EX_UNAVAILABLE | ||
158 | 630 | |||
159 | 617 | try: | 631 | try: |
160 | 618 | credentials_filename = config.get( | 632 | credentials_filename = config.get( |
161 | 619 | 'credentials_filename', | 633 | 'credentials_filename', |
162 | @@ -623,7 +637,7 @@ def command_credentials(lp: Lp, config: dict[str, str]) -> int: | |||
163 | 623 | print(f"Launchpad credentials written to {credentials_filename}") | 637 | print(f"Launchpad credentials written to {credentials_filename}") |
164 | 624 | return os.EX_OK | 638 | return os.EX_OK |
165 | 625 | except KeyboardInterrupt: | 639 | except KeyboardInterrupt: |
167 | 626 | return 2 | 640 | return EX_KEYBOARD_INTERRUPT |
168 | 627 | print("Unhandled error") | 641 | print("Unhandled error") |
169 | 628 | return 1 | 642 | return 1 |
170 | 629 | 643 | ||
171 | @@ -635,6 +649,9 @@ def command_desc(lp: Lp, config: dict[str, str]) -> int: | |||
172 | 635 | :rtype: int | 649 | :rtype: int |
173 | 636 | :returns: Status code OK (0) on success, non-zero on error. | 650 | :returns: Status code OK (0) on success, non-zero on error. |
174 | 637 | """ | 651 | """ |
175 | 652 | if not lp: | ||
176 | 653 | return os.EX_UNAVAILABLE | ||
177 | 654 | |||
178 | 638 | if not sys.stdin.isatty(): | 655 | if not sys.stdin.isatty(): |
179 | 639 | description = sys.stdin.read() | 656 | description = sys.stdin.read() |
180 | 640 | else: | 657 | else: |
181 | @@ -652,7 +669,7 @@ def command_desc(lp: Lp, config: dict[str, str]) -> int: | |||
182 | 652 | 669 | ||
183 | 653 | return the_ppa.set_description(description) | 670 | return the_ppa.set_description(description) |
184 | 654 | except KeyboardInterrupt: | 671 | except KeyboardInterrupt: |
186 | 655 | return 2 | 672 | return EX_KEYBOARD_INTERRUPT |
187 | 656 | print("Unhandled error") | 673 | print("Unhandled error") |
188 | 657 | return 1 | 674 | return 1 |
189 | 658 | 675 | ||
190 | @@ -665,6 +682,9 @@ def command_destroy(lp: Lp, config: dict[str, str]) -> int: | |||
191 | 665 | :rtype: int | 682 | :rtype: int |
192 | 666 | :returns: Status code OK (0) on success, non-zero on error. | 683 | :returns: Status code OK (0) on success, non-zero on error. |
193 | 667 | """ | 684 | """ |
194 | 685 | if not lp: | ||
195 | 686 | return os.EX_UNAVAILABLE | ||
196 | 687 | |||
197 | 668 | try: | 688 | try: |
198 | 669 | the_ppa = get_ppa(lp, config) | 689 | the_ppa = get_ppa(lp, config) |
199 | 670 | if not config.get('dry_run'): | 690 | if not config.get('dry_run'): |
200 | @@ -672,7 +692,7 @@ def command_destroy(lp: Lp, config: dict[str, str]) -> int: | |||
201 | 672 | the_ppa.destroy() | 692 | the_ppa.destroy() |
202 | 673 | return os.EX_OK | 693 | return os.EX_OK |
203 | 674 | except KeyboardInterrupt: | 694 | except KeyboardInterrupt: |
205 | 675 | return 2 | 695 | return EX_KEYBOARD_INTERRUPT |
206 | 676 | print("Unhandled error") | 696 | print("Unhandled error") |
207 | 677 | return 1 | 697 | return 1 |
208 | 678 | 698 | ||
209 | @@ -694,7 +714,7 @@ def command_list(lp: Lp, config: dict[str, str], filter_func=None) -> int: | |||
210 | 694 | # - filter_older: Ones older than a given date | 714 | # - filter_older: Ones older than a given date |
211 | 695 | # - Status of the PPAs | 715 | # - Status of the PPAs |
212 | 696 | if not lp: | 716 | if not lp: |
214 | 697 | return 1 | 717 | return os.EX_UNAVAILABLE |
215 | 698 | 718 | ||
216 | 699 | owner_name = config.get('owner_name') | 719 | owner_name = config.get('owner_name') |
217 | 700 | if not owner_name: | 720 | if not owner_name: |
218 | @@ -710,7 +730,7 @@ def command_list(lp: Lp, config: dict[str, str], filter_func=None) -> int: | |||
219 | 710 | print(p.address) | 730 | print(p.address) |
220 | 711 | return os.EX_OK | 731 | return os.EX_OK |
221 | 712 | except KeyboardInterrupt: | 732 | except KeyboardInterrupt: |
223 | 713 | return 2 | 733 | return EX_KEYBOARD_INTERRUPT |
224 | 714 | print("Unhandled error") | 734 | print("Unhandled error") |
225 | 715 | return 1 | 735 | return 1 |
226 | 716 | 736 | ||
227 | @@ -723,12 +743,15 @@ def command_exists(lp: Lp, config: dict[str, str]) -> int: | |||
228 | 723 | :rtype: int | 743 | :rtype: int |
229 | 724 | :returns: Status code OK (0) on success, non-zero on error. | 744 | :returns: Status code OK (0) on success, non-zero on error. |
230 | 725 | """ | 745 | """ |
231 | 746 | if not lp: | ||
232 | 747 | return os.EX_UNAVAILABLE | ||
233 | 748 | |||
234 | 726 | try: | 749 | try: |
235 | 727 | the_ppa = get_ppa(lp, config) | 750 | the_ppa = get_ppa(lp, config) |
236 | 728 | if the_ppa.archive is not None: | 751 | if the_ppa.archive is not None: |
237 | 729 | return os.EX_OK | 752 | return os.EX_OK |
238 | 730 | except KeyboardInterrupt: | 753 | except KeyboardInterrupt: |
240 | 731 | return 2 | 754 | return EX_KEYBOARD_INTERRUPT |
241 | 732 | return 1 | 755 | return 1 |
242 | 733 | 756 | ||
243 | 734 | 757 | ||
244 | @@ -740,6 +763,9 @@ def command_set(lp: Lp, config: dict[str, str]) -> int: | |||
245 | 740 | :rtype: int | 763 | :rtype: int |
246 | 741 | :returns: Status code OK (0) on success, non-zero on error. | 764 | :returns: Status code OK (0) on success, non-zero on error. |
247 | 742 | """ | 765 | """ |
248 | 766 | if not lp: | ||
249 | 767 | return os.EX_UNAVAILABLE | ||
250 | 768 | |||
251 | 743 | try: | 769 | try: |
252 | 744 | the_ppa = get_ppa(lp, config) | 770 | the_ppa = get_ppa(lp, config) |
253 | 745 | 771 | ||
254 | @@ -772,14 +798,14 @@ def command_set(lp: Lp, config: dict[str, str]) -> int: | |||
255 | 772 | else: | 798 | else: |
256 | 773 | error(f"Insufficient authorization to modify PPA '{the_ppa.name}'.") | 799 | error(f"Insufficient authorization to modify PPA '{the_ppa.name}'.") |
257 | 774 | return os.EX_NOPERM | 800 | return os.EX_NOPERM |
259 | 775 | except PpaDoesNotExist as e: | 801 | except PpaNotFoundError as e: |
260 | 776 | print(e) | 802 | print(e) |
262 | 777 | return 1 | 803 | return os.EX_NOTFOUND |
263 | 778 | except ValueError as e: | 804 | except ValueError as e: |
264 | 779 | print(f"Error: {e}") | 805 | print(f"Error: {e}") |
265 | 780 | return os.EX_USAGE | 806 | return os.EX_USAGE |
266 | 781 | except KeyboardInterrupt: | 807 | except KeyboardInterrupt: |
268 | 782 | return 2 | 808 | return EX_KEYBOARD_INTERRUPT |
269 | 783 | print("Unhandled error") | 809 | print("Unhandled error") |
270 | 784 | return 1 | 810 | return 1 |
271 | 785 | 811 | ||
272 | @@ -792,6 +818,9 @@ def command_show(lp: Lp, config: dict[str, str]) -> int: | |||
273 | 792 | :rtype: int | 818 | :rtype: int |
274 | 793 | :returns: Status code OK (0) on success, non-zero on error. | 819 | :returns: Status code OK (0) on success, non-zero on error. |
275 | 794 | """ | 820 | """ |
276 | 821 | if not lp: | ||
277 | 822 | return os.EX_UNAVAILABLE | ||
278 | 823 | |||
279 | 795 | distro = None | 824 | distro = None |
280 | 796 | series = None | 825 | series = None |
281 | 797 | arch = None | 826 | arch = None |
282 | @@ -833,11 +862,11 @@ def command_show(lp: Lp, config: dict[str, str]) -> int: | |||
283 | 833 | total_downloads += binary.getDownloadCount() | 862 | total_downloads += binary.getDownloadCount() |
284 | 834 | print("downloads: %d" % (total_downloads)) | 863 | print("downloads: %d" % (total_downloads)) |
285 | 835 | return os.EX_OK | 864 | return os.EX_OK |
287 | 836 | except PpaDoesNotExist as e: | 865 | except PpaNotFoundError as e: |
288 | 837 | print(e) | 866 | print(e) |
290 | 838 | return 1 | 867 | return os.EX_NOTFOUND |
291 | 839 | except KeyboardInterrupt: | 868 | except KeyboardInterrupt: |
293 | 840 | return 2 | 869 | return EX_KEYBOARD_INTERRUPT |
294 | 841 | print("Unhandled error") | 870 | print("Unhandled error") |
295 | 842 | return 1 | 871 | return 1 |
296 | 843 | 872 | ||
297 | @@ -863,7 +892,7 @@ def command_wait(lp: Lp, config: dict[str, str]) -> int: | |||
298 | 863 | :returns: Status code OK (0) on success, non-zero on error. | 892 | :returns: Status code OK (0) on success, non-zero on error. |
299 | 864 | """ | 893 | """ |
300 | 865 | if not lp: | 894 | if not lp: |
302 | 866 | return 1 | 895 | return os.EX_UNAVAILABLE |
303 | 867 | 896 | ||
304 | 868 | try: | 897 | try: |
305 | 869 | wait_max_age_hours = config.get('wait_max_age_hours') | 898 | wait_max_age_hours = config.get('wait_max_age_hours') |
306 | @@ -904,14 +933,14 @@ def command_wait(lp: Lp, config: dict[str, str]) -> int: | |||
307 | 904 | return os.EX_TEMPFAIL | 933 | return os.EX_TEMPFAIL |
308 | 905 | time.sleep(config['wait_seconds']) | 934 | time.sleep(config['wait_seconds']) |
309 | 906 | return os.EX_OK | 935 | return os.EX_OK |
311 | 907 | except PpaDoesNotExist as e: | 936 | except PpaNotFoundError as e: |
312 | 908 | print(e) | 937 | print(e) |
314 | 909 | return 1 | 938 | return os.EX_NOTFOUND |
315 | 910 | except ValueError as e: | 939 | except ValueError as e: |
316 | 911 | print(f"Error: {e}") | 940 | print(f"Error: {e}") |
317 | 912 | return os.EX_USAGE | 941 | return os.EX_USAGE |
318 | 913 | except KeyboardInterrupt: | 942 | except KeyboardInterrupt: |
320 | 914 | return 2 | 943 | return EX_KEYBOARD_INTERRUPT |
321 | 915 | print("Unhandled error") | 944 | print("Unhandled error") |
322 | 916 | return 1 | 945 | return 1 |
323 | 917 | 946 | ||
324 | @@ -925,7 +954,7 @@ def command_tests(lp: Lp, config: dict[str, str]) -> int: | |||
325 | 925 | :returns: Status code OK (0) on success, non-zero on error. | 954 | :returns: Status code OK (0) on success, non-zero on error. |
326 | 926 | """ | 955 | """ |
327 | 927 | if not lp: | 956 | if not lp: |
329 | 928 | return 1 | 957 | return os.EX_UNAVAILABLE |
330 | 929 | 958 | ||
331 | 930 | apt_repository = None | 959 | apt_repository = None |
332 | 931 | if config.get("show_rdepends"): | 960 | if config.get("show_rdepends"): |
333 | @@ -934,7 +963,7 @@ def command_tests(lp: Lp, config: dict[str, str]) -> int: | |||
334 | 934 | apt_repository = Repository(cache_dir=local_dists_path) | 963 | apt_repository = Repository(cache_dir=local_dists_path) |
335 | 935 | except FileNotFoundError as e: | 964 | except FileNotFoundError as e: |
336 | 936 | error(f'Missing checkout\n{LOCAL_REPOSITORY_MIRRORING_DIRECTIONS}: {e}') | 965 | error(f'Missing checkout\n{LOCAL_REPOSITORY_MIRRORING_DIRECTIONS}: {e}') |
338 | 937 | return 1 | 966 | return os.EX_NOTFOUND |
339 | 938 | 967 | ||
340 | 939 | releases = config.get('releases', None) | 968 | releases = config.get('releases', None) |
341 | 940 | if releases is None: | 969 | if releases is None: |
342 | @@ -956,7 +985,7 @@ def command_tests(lp: Lp, config: dict[str, str]) -> int: | |||
343 | 956 | the_ppa = get_ppa(lp, config) | 985 | the_ppa = get_ppa(lp, config) |
344 | 957 | if not the_ppa.exists(): | 986 | if not the_ppa.exists(): |
345 | 958 | error(f"PPA {the_ppa.name} does not exist for user {the_ppa.owner_name}") | 987 | error(f"PPA {the_ppa.name} does not exist for user {the_ppa.owner_name}") |
347 | 959 | return 1 | 988 | return os.EX_NOTFOUND |
348 | 960 | 989 | ||
349 | 961 | architectures = config.get('architectures', ARCHES_AUTOPKGTEST) | 990 | architectures = config.get('architectures', ARCHES_AUTOPKGTEST) |
350 | 962 | if isinstance(architectures, str): | 991 | if isinstance(architectures, str): |
351 | @@ -1035,7 +1064,7 @@ def command_tests(lp: Lp, config: dict[str, str]) -> int: | |||
352 | 1035 | 1064 | ||
353 | 1036 | return os.EX_OK | 1065 | return os.EX_OK |
354 | 1037 | except KeyboardInterrupt: | 1066 | except KeyboardInterrupt: |
356 | 1038 | return 2 | 1067 | return EX_KEYBOARD_INTERRUPT |
357 | 1039 | print("Unhandled error") | 1068 | print("Unhandled error") |
358 | 1040 | return 1 | 1069 | return 1 |
359 | 1041 | 1070 | ||
360 | @@ -1068,7 +1097,7 @@ def main(args: argparse.Namespace) -> int: | |||
361 | 1068 | lp = create_lp('ppa-dev-tools', args) | 1097 | lp = create_lp('ppa-dev-tools', args) |
362 | 1069 | config = create_config(lp, args) | 1098 | config = create_config(lp, args) |
363 | 1070 | except KeyboardInterrupt: | 1099 | except KeyboardInterrupt: |
365 | 1071 | return 2 | 1100 | return EX_KEYBOARD_INTERRUPT |
366 | 1072 | except ValueError as e: | 1101 | except ValueError as e: |
367 | 1073 | error(e) | 1102 | error(e) |
368 | 1074 | return os.EX_CONFIG | 1103 | return os.EX_CONFIG |
369 | @@ -1086,7 +1115,7 @@ def main(args: argparse.Namespace) -> int: | |||
370 | 1086 | func, param = COMMANDS[command] | 1115 | func, param = COMMANDS[command] |
371 | 1087 | except KeyError: | 1116 | except KeyError: |
372 | 1088 | parser.error(f"No such command {args.command}") | 1117 | parser.error(f"No such command {args.command}") |
374 | 1089 | return 1 | 1118 | return os.EX_USAGE |
375 | 1090 | if param: | 1119 | if param: |
376 | 1091 | return func(lp, config, param) | 1120 | return func(lp, config, param) |
377 | 1092 | return func(lp, config) | 1121 | return func(lp, config) |
378 | @@ -1101,6 +1130,6 @@ if __name__ == "__main__": | |||
379 | 1101 | if retval == os.EX_USAGE: | 1130 | if retval == os.EX_USAGE: |
380 | 1102 | print() | 1131 | print() |
381 | 1103 | parser.print_help() | 1132 | parser.print_help() |
383 | 1104 | elif retval == 2: | 1133 | elif retval == EX_KEYBOARD_INTERRUPT: |
384 | 1105 | sys.stderr.write(" (user interrupt)\n") | 1134 | sys.stderr.write(" (user interrupt)\n") |
385 | 1106 | sys.exit(retval) | 1135 | sys.exit(retval) |
Thanks, Bryce.
This LGTM.
I left a small comment nitpick regarding moving a magic number to a variable so it is more readable.