Support source package too

This commit is contained in:
Felix Yan 2020-09-16 18:57:50 +08:00
parent 819a8461a4
commit b620ed4e90
No known key found for this signature in database
GPG key ID: 786C63F330D7CB92
3 changed files with 24 additions and 4 deletions

View file

@ -618,8 +618,11 @@ Check APT repository
This enables you to track the update of an arbitary APT repository, without needing of apt and an updated local APT database. This enables you to track the update of an arbitary APT repository, without needing of apt and an updated local APT database.
apt pkg
Name of the APT package. Name of the APT binary package.
source_pkg
Name of the APT source package.
mirror mirror
URL of the repository (defaults to http://deb.debian.org/debian/) URL of the repository (defaults to http://deb.debian.org/debian/)
@ -636,6 +639,8 @@ arch
strip_release strip_release
Strip the release part. Strip the release part.
Note that either pkg or source_pkg needs to be specified (but not both) or the item name will be used as package.
Manually updating Manually updating
~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~
:: ::

View file

@ -22,13 +22,19 @@ async def get_url(url):
return data.decode('utf-8') return data.decode('utf-8')
async def get_version(name, conf, *, cache, **kwargs): async def get_version(name, conf, *, cache, **kwargs):
pkg = conf.get('apt') or name source_pkg = conf.get('source_pkg')
pkg = conf.get('pkg')
mirror = conf.get('mirror', "http://deb.debian.org/debian/") mirror = conf.get('mirror', "http://deb.debian.org/debian/")
suite = conf.get('suite', 'sid') suite = conf.get('suite', 'sid')
repo = conf.get('repo', 'main') repo = conf.get('repo', 'main')
arch = conf.get('arch', 'amd64') arch = conf.get('arch', 'amd64')
strip_release = conf.get('strip_release', False) strip_release = conf.get('strip_release', False)
if source_pkg and pkg:
raise GetVersionError('Setting both source_pkg and pkg is ambigious')
elif not source_pkg and not pkg:
pkg = name
apt_release = await cache.get(APT_RELEASE_URL % (mirror, suite), get_url) apt_release = await cache.get(APT_RELEASE_URL % (mirror, suite), get_url)
for suffix in APT_PACKAGES_SUFFIX_PREFER: for suffix in APT_PACKAGES_SUFFIX_PREFER:
packages_path = APT_PACKAGES_PATH % (repo, arch, suffix) packages_path = APT_PACKAGES_PATH % (repo, arch, suffix)
@ -41,7 +47,9 @@ async def get_version(name, conf, *, cache, **kwargs):
pkg_found = False pkg_found = False
for line in apt_packages.split("\n"): for line in apt_packages.split("\n"):
if line == "Package: " + pkg: if pkg and line == "Package: " + pkg:
pkg_found = True
if source_pkg and line == "Source: " + source_pkg:
pkg_found = True pkg_found = True
if pkg_found and line.startswith("Version: "): if pkg_found and line.startswith("Version: "):
version = line[9:] version = line[9:]

View file

@ -12,6 +12,13 @@ async def test_apt(get_version):
"source": "apt", "source": "apt",
}) == "0.1.7-1" }) == "0.1.7-1"
@flaky(max_runs=10)
async def test_apt_source_pkg(get_version):
assert await get_version("test", {
"source": "apt",
"source_pkg": "golang-github-dataence-porter2",
}) == "0.0~git20150829.56e4718-2"
@flaky(max_runs=10) @flaky(max_runs=10)
async def test_apt_strip_release(get_version): async def test_apt_strip_release(get_version):
assert await get_version("sigrok-firmware-fx2lafw", { assert await get_version("sigrok-firmware-fx2lafw", {