Skip to content

Commit 74d6846

Browse files
authored
Merge pull request #15 from philroche/feature/support-lookup-from-binary-package-name
feat: Add support for looking up changelog based on a binary package name
2 parents 5d28840 + 4da4c56 commit 74d6846

1 file changed

Lines changed: 42 additions & 6 deletions

File tree

ubuntu_package_changelog/__init__.py

Lines changed: 42 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,53 @@ def _lp_get_changelog_url(args, lp):
1919
archive = ubuntu.main_archive
2020

2121
lp_series = ubuntu.getSeries(name_or_version=args.series)
22+
sources = _get_published_sources(archive,
23+
args.package,
24+
lp_series,
25+
pocket)
26+
if len(sources) == 0:
27+
# unable to find published sources for args.package.
28+
# Perhaps this is a binary package name so we can
29+
# do a lookup to see if there exists a source package for
30+
# args.package binary package.
31+
binaries = _get_binary_packages(archive,
32+
args.package,
33+
pocket)
34+
if len(binaries):
35+
# there were published binaries with this name.
36+
# now get the source package name so we can get the changelog
37+
source_package_name = binaries[0].source_package_name
38+
sources = _get_published_sources(archive,
39+
source_package_name,
40+
lp_series,
41+
pocket)
42+
43+
if len(sources) == 1:
44+
return sources[0].changelogUrl()
45+
else:
46+
return None
47+
48+
49+
def _get_binary_packages(archive, binary_package_name, pocket):
50+
binaries = archive.getPublishedBinaries(
51+
exact_match=True,
52+
binary_name=binary_package_name,
53+
pocket=pocket,
54+
status="Published",
55+
order_by_date=True,
56+
)
57+
return binaries
58+
59+
60+
def _get_published_sources(archive, source_package_name, lp_series, pocket):
2261
sources = archive.getPublishedSources(
2362
exact_match=True,
24-
source_name=args.package,
63+
source_name=source_package_name,
2564
pocket=pocket,
2665
distro_series=lp_series,
2766
status="Published",
2867
order_by_date=True)
29-
if len(sources) == 1:
30-
return sources[0].changelogUrl()
31-
else:
32-
return None
68+
return sources
3369

3470

3571
def _args_validate_ppa_name(value):
@@ -52,7 +88,7 @@ def _parser():
5288
parser.add_argument('pocket',
5389
choices=['Release', 'Security', 'Updates', 'Proposed', 'Backports'],
5490
help='The pocket to search for. Default: %(default)s')
55-
parser.add_argument('package', help='the source package name')
91+
parser.add_argument('package', help='the source or binary package name')
5692
return parser
5793

5894

0 commit comments

Comments
 (0)