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
diff --git a/ppa/ppa.py b/ppa/ppa.py
index 0cccb10..f491a05 100755
--- a/ppa/ppa.py
+++ b/ppa/ppa.py
@@ -551,7 +551,9 @@ def ppa_address_split(ppa_address):
551 ppa_name = rem.split('/', 1)[1]551 ppa_name = rem.split('/', 1)[1]
552 elif ppa_address.startswith('http'):552 elif ppa_address.startswith('http'):
553 # Only launchpad PPA urls are supported553 # Only launchpad PPA urls are supported
554 m = re.search(r'https:\/\/launchpad\.net\/~([^/]+)\/\+archive\/ubuntu\/(.+)$', ppa_address)554 m = re.search(
555 r'https:\/\/launchpad\.net\/~([^/]+)\/\+archive\/ubuntu\/([^/]+)(\/*|\/\+[a-z]+)$',
556 ppa_address)
555 if not m:557 if not m:
556 return (None, None)558 return (None, None)
557 owner_name = m.group(1)559 owner_name = m.group(1)
diff --git a/scripts/ppa b/scripts/ppa
index ee97f4d..8e4e5a9 100755
--- a/scripts/ppa
+++ b/scripts/ppa
@@ -55,6 +55,7 @@ from inspect import currentframe
55from textwrap import indent55from textwrap import indent
56from typing import Any56from typing import Any
57from distro_info import UbuntuDistroInfo57from distro_info import UbuntuDistroInfo
58from lazr.restfulclient.errors import BadRequest
5859
59try:60try:
60 from ruamel import yaml61 from ruamel import yaml
@@ -789,21 +790,30 @@ def command_wait(lp: Lp, config: dict[str, str]) -> int:
789 name = config.get('name')790 name = config.get('name')
790 the_ppa = get_ppa(lp, config)791 the_ppa = get_ppa(lp, config)
791 waiting = True792 waiting = True
793 bad_request_count = 0
792 while waiting:794 while waiting:
793 if not the_ppa.has_packages(created_since_date=created_since_date, name=name):795 try:
794 print("Nothing present in PPA. Waiting for new package uploads...")796 if not the_ppa.has_packages(created_since_date=created_since_date, name=name):
795 # TODO: Only wait a configurable amount of time (15 min?)797 print("Nothing present in PPA. Waiting for new package uploads...")
796 waiting = True # config['wait_for_packages']798 # TODO: Only wait a configurable amount of time (15 min?)
797 else:799 waiting = True # config['wait_for_packages']
798 pending_reason = the_ppa.pending_publications(800 else:
799 created_since_date=created_since_date,801 pending_reason = the_ppa.pending_publications(
800 name=name802 created_since_date=created_since_date,
801 )803 name=name
802 waiting = bool(pending_reason)804 )
803 if config.get('exit_on_only_build_failure', False) and all(805 waiting = bool(pending_reason)
804 x == PendingReason.BUILD_FAILED for x in pending_reason):806 if config.get('exit_on_only_build_failure', False) and all(
805 # If exiting due to not pending, return ok, else failure807 x == PendingReason.BUILD_FAILED for x in pending_reason):
806 return 100 if pending_reason else os.EX_OK808 # If exiting due to not pending, return ok, else failure
809 return 100 if pending_reason else os.EX_OK
810 except BadRequest as e:
811 if bad_request_count < 3:
812 warn("BadRequest from Launchpad. Retrying...")
813 bad_request_count += 1
814 else:
815 error(f"Launchpad failure: {e}")
816 return os.EX_TEMPFAIL
807 time.sleep(config['wait_seconds'])817 time.sleep(config['wait_seconds'])
808 return os.EX_OK818 return os.EX_OK
809 except PpaDoesNotExist as e:819 except PpaDoesNotExist as e:
@@ -982,7 +992,13 @@ def main(args: argparse.Namespace) -> int:
982992
983 lp = Lp('ppa-dev-tools')993 lp = Lp('ppa-dev-tools')
984994
985 config = create_config(lp, args)995 try:
996 config = create_config(lp, args)
997 except KeyboardInterrupt:
998 return 2
999 except ValueError as e:
1000 error(e)
1001 return os.EX_CONFIG
986 if not config:1002 if not config:
987 return os.EX_CONFIG1003 return os.EX_CONFIG
9881004
@@ -1002,6 +1018,7 @@ def main(args: argparse.Namespace) -> int:
1002 return func(lp, config, param)1018 return func(lp, config, param)
1003 return func(lp, config)1019 return func(lp, config)
10041020
1021
1005if __name__ == "__main__":1022if __name__ == "__main__":
1006 # Option handling1023 # Option handling
1007 parser = create_arg_parser()1024 parser = create_arg_parser()
@@ -1011,4 +1028,6 @@ if __name__ == "__main__":
1011 if retval == os.EX_USAGE:1028 if retval == os.EX_USAGE:
1012 print()1029 print()
1013 parser.print_help()1030 parser.print_help()
1031 elif retval == 2:
1032 sys.stderr.write(" (user interrupt)\n")
1014 sys.exit(retval)1033 sys.exit(retval)
diff --git a/tests/test_ppa.py b/tests/test_ppa.py
index 9bb76e9..7e2e4bf 100644
--- a/tests/test_ppa.py
+++ b/tests/test_ppa.py
@@ -47,6 +47,10 @@ def test_address():
47 ('ppa:a/bb', ('a', 'bb')),47 ('ppa:a/bb', ('a', 'bb')),
48 ('ppa:ç/bb', ('ç', 'bb')),48 ('ppa:ç/bb', ('ç', 'bb')),
49 ('https://launchpad.net/~a/+archive/ubuntu/bb', ('a', 'bb')),49 ('https://launchpad.net/~a/+archive/ubuntu/bb', ('a', 'bb')),
50 ('https://launchpad.net/~a/+archive/ubuntu/bb/', ('a', 'bb')),
51 ('https://launchpad.net/~a/+archive/ubuntu/bb////', ('a', 'bb')),
52 ('https://launchpad.net/~a/+archive/ubuntu/bb/+packages', ('a', 'bb')),
53 ('https://launchpad.net/~a/+archive/ubuntu/bb/+x', ('a', 'bb')),
5054
51 # Expected failure cases55 # Expected failure cases
52 ('ppa:', (None, None)),56 ('ppa:', (None, None)),
@@ -65,6 +69,8 @@ def test_address():
65 ('http://launchpad.net/~a/+archive/ubuntu/bb', (None, None)),69 ('http://launchpad.net/~a/+archive/ubuntu/bb', (None, None)),
66 ('https://example.com/~a/+archive/ubuntu/bb', (None, None)),70 ('https://example.com/~a/+archive/ubuntu/bb', (None, None)),
67 ('https://launchpad.net/~a/+archive/nobuntu/bb', (None, None)),71 ('https://launchpad.net/~a/+archive/nobuntu/bb', (None, None)),
72 ('https://launchpad.net/~a/+archive/ubuntu/bb/x', (None, None)),
73 ('https://launchpad.net/~a/+archive/ubuntu/bb/+', (None, None)),
68])74])
69def test_ppa_address_split(address, expected):75def test_ppa_address_split(address, expected):
70 """Check ppa address input strings can be parsed properly."""76 """Check ppa address input strings can be parsed properly."""

Subscribers

People subscribed via source and target branches

to all changes: