Merge ppa-dev-tools:fix-lp1997122-and-other-errors into ppa-dev-tools:main

Proposed by Bryce Harrington
Status: Merged
Merge reported by: Bryce Harrington
Merged at revision: 7e8f5569d802f02047f370475af966935a99d1a2
Proposed branch: ppa-dev-tools:fix-lp1997122-and-other-errors
Merge into: ppa-dev-tools:main
Diff against target: 126 lines (+43/-16)
3 files modified
ppa/ppa.py (+3/-1)
scripts/ppa (+34/-15)
tests/test_ppa.py (+6/-0)
Reviewer Review Type Date Requested Status
Andreas Hasenack (community) Approve
PpaDevTools Developers Pending
Canonical Server Reporter Pending
Bryce Harrington Pending
Review via email: mp+445397@code.launchpad.net

Description of the change

This is a set of some small fixes to various issues that have cropped up.
Most don't have bug reports but are easy enough to reproduce and fixes pretty obvious.

To post a comment you must log in.
Revision history for this message
Andreas Hasenack (ahasenack) :
Revision history for this message
Bryce Harrington (bryce) :
Revision history for this message
Andreas Hasenack (ahasenack) :
Revision history for this message
Andreas Hasenack (ahasenack) wrote :

+1, working as advertised, and just the regexp suggestion inline, if that makes sense to you.

review: Approve
Revision history for this message
Bryce Harrington (bryce) wrote :

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/ppa/ppa.py b/ppa/ppa.py
2index 0cccb10..f491a05 100755
3--- a/ppa/ppa.py
4+++ b/ppa/ppa.py
5@@ -551,7 +551,9 @@ def ppa_address_split(ppa_address):
6 ppa_name = rem.split('/', 1)[1]
7 elif ppa_address.startswith('http'):
8 # Only launchpad PPA urls are supported
9- m = re.search(r'https:\/\/launchpad\.net\/~([^/]+)\/\+archive\/ubuntu\/(.+)$', ppa_address)
10+ m = re.search(
11+ r'https:\/\/launchpad\.net\/~([^/]+)\/\+archive\/ubuntu\/([^/]+)(\/*|\/\+[a-z]+)$',
12+ ppa_address)
13 if not m:
14 return (None, None)
15 owner_name = m.group(1)
16diff --git a/scripts/ppa b/scripts/ppa
17index ee97f4d..8e4e5a9 100755
18--- a/scripts/ppa
19+++ b/scripts/ppa
20@@ -55,6 +55,7 @@ from inspect import currentframe
21 from textwrap import indent
22 from typing import Any
23 from distro_info import UbuntuDistroInfo
24+from lazr.restfulclient.errors import BadRequest
25
26 try:
27 from ruamel import yaml
28@@ -789,21 +790,30 @@ def command_wait(lp: Lp, config: dict[str, str]) -> int:
29 name = config.get('name')
30 the_ppa = get_ppa(lp, config)
31 waiting = True
32+ bad_request_count = 0
33 while waiting:
34- if not the_ppa.has_packages(created_since_date=created_since_date, name=name):
35- print("Nothing present in PPA. Waiting for new package uploads...")
36- # TODO: Only wait a configurable amount of time (15 min?)
37- waiting = True # config['wait_for_packages']
38- else:
39- pending_reason = the_ppa.pending_publications(
40- created_since_date=created_since_date,
41- name=name
42- )
43- waiting = bool(pending_reason)
44- if config.get('exit_on_only_build_failure', False) and all(
45- x == PendingReason.BUILD_FAILED for x in pending_reason):
46- # If exiting due to not pending, return ok, else failure
47- return 100 if pending_reason else os.EX_OK
48+ try:
49+ if not the_ppa.has_packages(created_since_date=created_since_date, name=name):
50+ print("Nothing present in PPA. Waiting for new package uploads...")
51+ # TODO: Only wait a configurable amount of time (15 min?)
52+ waiting = True # config['wait_for_packages']
53+ else:
54+ pending_reason = the_ppa.pending_publications(
55+ created_since_date=created_since_date,
56+ name=name
57+ )
58+ waiting = bool(pending_reason)
59+ if config.get('exit_on_only_build_failure', False) and all(
60+ x == PendingReason.BUILD_FAILED for x in pending_reason):
61+ # If exiting due to not pending, return ok, else failure
62+ return 100 if pending_reason else os.EX_OK
63+ except BadRequest as e:
64+ if bad_request_count < 3:
65+ warn("BadRequest from Launchpad. Retrying...")
66+ bad_request_count += 1
67+ else:
68+ error(f"Launchpad failure: {e}")
69+ return os.EX_TEMPFAIL
70 time.sleep(config['wait_seconds'])
71 return os.EX_OK
72 except PpaDoesNotExist as e:
73@@ -982,7 +992,13 @@ def main(args: argparse.Namespace) -> int:
74
75 lp = Lp('ppa-dev-tools')
76
77- config = create_config(lp, args)
78+ try:
79+ config = create_config(lp, args)
80+ except KeyboardInterrupt:
81+ return 2
82+ except ValueError as e:
83+ error(e)
84+ return os.EX_CONFIG
85 if not config:
86 return os.EX_CONFIG
87
88@@ -1002,6 +1018,7 @@ def main(args: argparse.Namespace) -> int:
89 return func(lp, config, param)
90 return func(lp, config)
91
92+
93 if __name__ == "__main__":
94 # Option handling
95 parser = create_arg_parser()
96@@ -1011,4 +1028,6 @@ if __name__ == "__main__":
97 if retval == os.EX_USAGE:
98 print()
99 parser.print_help()
100+ elif retval == 2:
101+ sys.stderr.write(" (user interrupt)\n")
102 sys.exit(retval)
103diff --git a/tests/test_ppa.py b/tests/test_ppa.py
104index 9bb76e9..7e2e4bf 100644
105--- a/tests/test_ppa.py
106+++ b/tests/test_ppa.py
107@@ -47,6 +47,10 @@ def test_address():
108 ('ppa:a/bb', ('a', 'bb')),
109 ('ppa:ç/bb', ('ç', 'bb')),
110 ('https://launchpad.net/~a/+archive/ubuntu/bb', ('a', 'bb')),
111+ ('https://launchpad.net/~a/+archive/ubuntu/bb/', ('a', 'bb')),
112+ ('https://launchpad.net/~a/+archive/ubuntu/bb////', ('a', 'bb')),
113+ ('https://launchpad.net/~a/+archive/ubuntu/bb/+packages', ('a', 'bb')),
114+ ('https://launchpad.net/~a/+archive/ubuntu/bb/+x', ('a', 'bb')),
115
116 # Expected failure cases
117 ('ppa:', (None, None)),
118@@ -65,6 +69,8 @@ def test_address():
119 ('http://launchpad.net/~a/+archive/ubuntu/bb', (None, None)),
120 ('https://example.com/~a/+archive/ubuntu/bb', (None, None)),
121 ('https://launchpad.net/~a/+archive/nobuntu/bb', (None, None)),
122+ ('https://launchpad.net/~a/+archive/ubuntu/bb/x', (None, None)),
123+ ('https://launchpad.net/~a/+archive/ubuntu/bb/+', (None, None)),
124 ])
125 def test_ppa_address_split(address, expected):
126 """Check ppa address input strings can be parsed properly."""

Subscribers

People subscribed via source and target branches

to all changes: