2019-09-04 16:43:12 -03:00
|
|
|
#!/usr/bin/python3
|
2011-12-03 17:02:47 +02:00
|
|
|
#
|
|
|
|
# Copyright (C) 2011, Stefano Rivera <stefanor@ubuntu.com>
|
|
|
|
#
|
|
|
|
# Permission to use, copy, modify, and/or distribute this software for any
|
|
|
|
# purpose with or without fee is hereby granted, provided that the above
|
|
|
|
# copyright notice and this permission notice appear in all copies.
|
|
|
|
#
|
|
|
|
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
|
|
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
|
|
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
|
|
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
|
|
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
|
|
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
|
|
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
|
|
|
2023-01-30 23:10:31 +01:00
|
|
|
# pylint: disable=invalid-name
|
|
|
|
# pylint: enable=invalid-name
|
|
|
|
|
2023-01-31 13:33:18 +01:00
|
|
|
import argparse
|
2011-12-06 00:24:11 +02:00
|
|
|
import collections
|
2011-12-03 17:02:47 +02:00
|
|
|
import gzip
|
|
|
|
import json
|
|
|
|
import os
|
|
|
|
import time
|
2019-09-04 16:43:12 -03:00
|
|
|
import urllib.request
|
2011-12-03 17:02:47 +02:00
|
|
|
|
2018-10-12 18:54:07 -04:00
|
|
|
from ubuntutools import getLogger
|
2023-01-30 21:28:47 +01:00
|
|
|
from ubuntutools.lp.lpapicache import Distribution, Launchpad, PackageNotFoundException
|
2023-01-30 19:45:36 +01:00
|
|
|
|
2021-02-01 18:26:13 -05:00
|
|
|
Logger = getLogger()
|
2011-12-03 17:02:47 +02:00
|
|
|
|
2023-01-30 19:45:36 +01:00
|
|
|
DATA_URL = "http://qa.ubuntuwire.org/ubuntu-seeded-packages/seeded.json.gz"
|
2011-12-03 17:02:47 +02:00
|
|
|
|
|
|
|
|
2011-12-06 00:24:11 +02:00
|
|
|
def load_index(url):
|
2023-01-30 19:45:36 +01:00
|
|
|
"""Download a new copy of the image contents index, if necessary,
|
2011-12-04 00:09:51 +02:00
|
|
|
and read it.
|
2023-01-30 19:45:36 +01:00
|
|
|
"""
|
|
|
|
cachedir = os.path.expanduser("~/.cache/ubuntu-dev-tools")
|
2023-01-30 23:10:31 +01:00
|
|
|
seeded = os.path.join(cachedir, "seeded.json.gz")
|
2011-12-03 17:02:47 +02:00
|
|
|
|
2023-01-30 23:10:31 +01:00
|
|
|
if not os.path.isfile(seeded) or time.time() - os.path.getmtime(seeded) > 60 * 60 * 2:
|
2011-12-03 17:02:47 +02:00
|
|
|
if not os.path.isdir(cachedir):
|
|
|
|
os.makedirs(cachedir)
|
2023-01-30 23:10:31 +01:00
|
|
|
urllib.request.urlretrieve(url, seeded)
|
2011-12-03 17:02:47 +02:00
|
|
|
|
2012-06-20 22:28:35 +02:00
|
|
|
try:
|
2023-01-30 23:10:31 +01:00
|
|
|
with gzip.open(seeded, "r") as f:
|
2012-06-20 22:28:35 +02:00
|
|
|
return json.load(f)
|
2023-01-31 15:51:29 +01:00
|
|
|
except Exception as e: # pylint: disable=broad-except
|
2023-01-30 19:45:36 +01:00
|
|
|
Logger.error(
|
|
|
|
"Unable to parse seed data: %s. Deleting cached data, please try again.", str(e)
|
|
|
|
)
|
2023-01-30 23:10:31 +01:00
|
|
|
os.unlink(seeded)
|
2023-01-31 16:58:24 +01:00
|
|
|
return None
|
2011-12-03 17:02:47 +02:00
|
|
|
|
|
|
|
|
2011-12-06 00:24:11 +02:00
|
|
|
def resolve_binaries(sources):
|
2023-01-30 19:45:36 +01:00
|
|
|
"""Return a dict of source:binaries for all binary packages built by
|
2011-12-06 00:24:11 +02:00
|
|
|
sources
|
2023-01-30 19:45:36 +01:00
|
|
|
"""
|
|
|
|
archive = Distribution("ubuntu").getArchive()
|
2011-12-06 00:24:11 +02:00
|
|
|
binaries = {}
|
|
|
|
for source in sources:
|
|
|
|
try:
|
|
|
|
spph = archive.getSourcePackage(source)
|
2019-09-04 16:43:12 -03:00
|
|
|
except PackageNotFoundException as e:
|
2011-12-06 00:24:11 +02:00
|
|
|
Logger.error(str(e))
|
|
|
|
continue
|
2023-01-30 19:45:36 +01:00
|
|
|
binaries[source] = sorted(set(bpph.getPackageName() for bpph in spph.getBinaries()))
|
2011-12-06 00:24:11 +02:00
|
|
|
|
|
|
|
return binaries
|
|
|
|
|
|
|
|
|
|
|
|
def present_on(appearences):
|
2023-01-30 19:45:36 +01:00
|
|
|
"""Format a list of (flavor, type) tuples into a human-readable string"""
|
2011-12-06 00:24:11 +02:00
|
|
|
present = collections.defaultdict(set)
|
|
|
|
for flavor, type_ in appearences:
|
|
|
|
present[flavor].add(type_)
|
2019-09-04 16:43:12 -03:00
|
|
|
for flavor, types in present.items():
|
2011-12-06 00:24:11 +02:00
|
|
|
if len(types) > 1:
|
2023-01-30 19:45:36 +01:00
|
|
|
types.discard("supported")
|
2023-01-31 19:32:58 +01:00
|
|
|
output = [f" {flavor}: {', '.join(sorted(types))}" for flavor, types in present.items()]
|
2011-12-08 00:27:58 +02:00
|
|
|
output.sort()
|
2023-01-30 19:45:36 +01:00
|
|
|
return "\n".join(output)
|
2011-12-06 00:24:11 +02:00
|
|
|
|
|
|
|
|
|
|
|
def output_binaries(index, binaries):
|
2023-01-30 19:45:36 +01:00
|
|
|
"""Print binaries found in index"""
|
2011-12-06 00:24:11 +02:00
|
|
|
for binary in binaries:
|
|
|
|
if binary in index:
|
2023-01-31 11:13:07 +01:00
|
|
|
Logger.info("%s is seeded in:", binary)
|
2018-10-12 18:54:07 -04:00
|
|
|
Logger.info(present_on(index[binary]))
|
2011-12-06 00:24:11 +02:00
|
|
|
else:
|
2023-01-31 11:13:07 +01:00
|
|
|
Logger.info("%s is not seeded (and may not exist).", binary)
|
2011-12-06 00:24:11 +02:00
|
|
|
|
|
|
|
|
|
|
|
def output_by_source(index, by_source):
|
2023-01-30 19:45:36 +01:00
|
|
|
"""Logger.Info(binaries found in index. Grouped by source"""
|
2019-09-04 16:43:12 -03:00
|
|
|
for source, binaries in by_source.items():
|
2011-12-06 00:24:11 +02:00
|
|
|
seen = False
|
2012-07-18 12:28:35 +02:00
|
|
|
if not binaries:
|
2023-01-30 19:45:36 +01:00
|
|
|
Logger.info(
|
|
|
|
"Status unknown: No binary packages built by the latest "
|
2023-01-31 11:13:07 +01:00
|
|
|
"%s.\nTry again using -b and the expected binary packages.",
|
|
|
|
source,
|
2023-01-30 19:45:36 +01:00
|
|
|
)
|
2012-07-18 12:28:35 +02:00
|
|
|
continue
|
2011-12-06 00:24:11 +02:00
|
|
|
for binary in binaries:
|
|
|
|
if binary in index:
|
|
|
|
seen = True
|
2023-01-31 11:13:07 +01:00
|
|
|
Logger.info("%s (from %s) is seeded in:", binary, source)
|
2018-10-12 18:54:07 -04:00
|
|
|
Logger.info(present_on(index[binary]))
|
2011-12-06 00:24:11 +02:00
|
|
|
if not seen:
|
2023-01-31 11:13:07 +01:00
|
|
|
Logger.info("%s's binaries are not seeded.", source)
|
2011-12-06 00:24:11 +02:00
|
|
|
|
|
|
|
|
2011-12-03 17:02:47 +02:00
|
|
|
def main():
|
2023-01-30 19:45:36 +01:00
|
|
|
"""Query which images the specified packages are on"""
|
2023-01-31 13:33:18 +01:00
|
|
|
parser = argparse.ArgumentParser(usage="%(prog)s [options] package...")
|
|
|
|
parser.add_argument(
|
2023-01-30 19:45:36 +01:00
|
|
|
"-b",
|
|
|
|
"--binary",
|
|
|
|
default=False,
|
|
|
|
action="store_true",
|
|
|
|
help="Binary packages are being specified, not source packages (fast)",
|
|
|
|
)
|
2023-01-31 13:33:18 +01:00
|
|
|
parser.add_argument(
|
2023-01-30 19:45:36 +01:00
|
|
|
"-u",
|
|
|
|
"--data-url",
|
|
|
|
metavar="URL",
|
|
|
|
default=DATA_URL,
|
|
|
|
help="URL for the seeded packages index. Default: UbuntuWire",
|
|
|
|
)
|
2023-01-31 13:33:18 +01:00
|
|
|
parser.add_argument("packages", metavar="package", nargs="+", help=argparse.SUPPRESS)
|
|
|
|
args = parser.parse_args()
|
2011-12-03 17:02:47 +02:00
|
|
|
|
2012-04-12 18:23:00 +02:00
|
|
|
# Login anonymously to LP
|
|
|
|
Launchpad.login_anonymously()
|
|
|
|
|
2023-01-31 13:33:18 +01:00
|
|
|
index = load_index(args.data_url)
|
|
|
|
if args.binary:
|
|
|
|
output_binaries(index, args.packages)
|
2011-12-03 17:02:47 +02:00
|
|
|
else:
|
2023-01-31 13:33:18 +01:00
|
|
|
binaries = resolve_binaries(args.packages)
|
2011-12-06 00:24:11 +02:00
|
|
|
output_by_source(index, binaries)
|
2011-12-03 17:02:47 +02:00
|
|
|
|
|
|
|
|
2023-01-30 19:45:36 +01:00
|
|
|
if __name__ == "__main__":
|
2011-12-03 17:02:47 +02:00
|
|
|
main()
|