pkgrepo.py revision 3447
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainen# CDDL HEADER START
1a0ece3e873e3864269ed7eaed957dc10c56d25fTimo Sirainen# The contents of this file are subject to the terms of the
e0c3d5460d1cc0c440cb7723c8c2eef8d0afe9b9Timo Sirainen# Common Development and Distribution License (the "License").
5ca745ae8e9903ef5265360e4c882e9314595020Timo Sirainen# You may not use this file except in compliance with the License.
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainen# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
c2cda8cd0043443566efc5da30f79865508a1947Timo Sirainen# See the License for the specific language governing permissions
8cb72c59d5ea4e9e5f638d7ec840bb853f5a188eTimo Sirainen# and limitations under the License.
8cb72c59d5ea4e9e5f638d7ec840bb853f5a188eTimo Sirainen# When distributing Covered Code, include this CDDL HEADER in each
8cb72c59d5ea4e9e5f638d7ec840bb853f5a188eTimo Sirainen# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
8cb72c59d5ea4e9e5f638d7ec840bb853f5a188eTimo Sirainen# If applicable, add the following below this CDDL HEADER, with the
8cb72c59d5ea4e9e5f638d7ec840bb853f5a188eTimo Sirainen# fields enclosed by brackets "[]" replaced with your own identifying
8cb72c59d5ea4e9e5f638d7ec840bb853f5a188eTimo Sirainen# information: Portions Copyright [yyyy] [name of copyright owner]
8cb72c59d5ea4e9e5f638d7ec840bb853f5a188eTimo Sirainen# CDDL HEADER END
8cb72c59d5ea4e9e5f638d7ec840bb853f5a188eTimo Sirainen# Copyright (c) 2010, 2016, Oracle and/or its affiliates. All rights reserved.
e2ce8d4a6ac5d82a906178148453e7613fab9ba0Timo Sirainen# pkgrepo exit codes
e2ce8d4a6ac5d82a906178148453e7613fab9ba0Timo Sirainen# listing constants
cd56a23e21f1df3f79648cf07e2f4385e2fadebbTimo SirainenLISTING_FORMATS = ("default", "json", "json-formatted", "tsv")
cd56a23e21f1df3f79648cf07e2f4385e2fadebbTimo Sirainendiff_type_f = {MINUS: "- ", PLUS: "+ ", COMMON: ""}
c28f6aa0b70af4811c9ace9114fe827c2f503455Timo Sirainenimport pkg.client.transport.transport as transport
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainen """To be called at program finish."""
46ce4d9273e6df12ef1912bbdb1c8b84b104f394Timo Sirainen """Emit an error message prefixed by the command name """
862ec874f9373e3e499e237d3b9f71fdf1413feeTimo Sirainen # If we get passed something like an Exception, we can convert
862ec874f9373e3e499e237d3b9f71fdf1413feeTimo Sirainen # it down to a string.
862ec874f9373e3e499e237d3b9f71fdf1413feeTimo Sirainen # If the message starts with whitespace, assume that it should come
862ec874f9373e3e499e237d3b9f71fdf1413feeTimo Sirainen # *before* the command-name prefix.
5af5137f6dc0c9f358b7813e941e26f7bd735b3aTimo Sirainen # This has to be a constant value as we can't reliably get our actual
5af5137f6dc0c9f358b7813e941e26f7bd735b3aTimo Sirainen # program name on all platforms.
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainen progtrack = pkg.client.progress.QuietProgressTracker()
7662010b03ffe5f2a6ecf4b4eb220d1c65efea76Timo Sirainen pkg.client.progress.FancyUNIXProgressTracker()
7662010b03ffe5f2a6ecf4b4eb220d1c65efea76Timo Sirainen except pkg.client.progress.ProgressTrackerException:
c0435c854a0e7246373b9752d163095cc4fbe985Timo Sirainen pkg.client.progress.CommandLineProgressTracker()
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainendef usage(usage_error=None, cmd=None, retcode=2, full=False):
0a49b316fc729e5d57268ffa63c7122ac73f994cTimo Sirainen """Emit a usage message and optionally prefix it with a more
0a49b316fc729e5d57268ffa63c7122ac73f994cTimo Sirainen specific error message. Causes program to exit.
71aed7ba87b5fd5e96e97a22d89ac025b883d60aTimo Sirainen # The full usage message isn't desired.
71aed7ba87b5fd5e96e97a22d89ac025b883d60aTimo Sirainen logger.error(_("Try `pkgrepo --help or -?' for more "
0a49b316fc729e5d57268ffa63c7122ac73f994cTimo Sirainen "information."))
51e1a1c280ccb461a15827f7987d09cb9708b6e3Timo Sirainen pkgrepo [options] command [cmd_options] [operands]
463f6ea04af934a68facaca0ff089bc306de3f98Timo Sirainen pkgrepo create [--version ver] uri_or_path
463f6ea04af934a68facaca0ff089bc306de3f98Timo Sirainen pkgrepo add-publisher -s repo_uri_or_path publisher ...
463f6ea04af934a68facaca0ff089bc306de3f98Timo Sirainen pkgrepo remove-publisher [-n] [--synchronous] -s repo_uri_or_path
0b6924ad1943fe5c6917fc49f675d8f316b0d939Timo Sirainen publisher ...
0b6924ad1943fe5c6917fc49f675d8f316b0d939Timo Sirainen pkgrepo get [-F format] [-p publisher ...] -s repo_uri_or_path
0b6924ad1943fe5c6917fc49f675d8f316b0d939Timo Sirainen [--key ssl_key ... --cert ssl_cert ...] [section/property ...]
0b6924ad1943fe5c6917fc49f675d8f316b0d939Timo Sirainen pkgrepo info [-F format] [-H] [-p publisher ...] -s repo_uri_or_path
0b6924ad1943fe5c6917fc49f675d8f316b0d939Timo Sirainen [--key ssl_key ... --cert ssl_cert ...]
0b6924ad1943fe5c6917fc49f675d8f316b0d939Timo Sirainen pkgrepo list [-F format] [-H] [-p publisher ...] -s repo_uri_or_path
0b6924ad1943fe5c6917fc49f675d8f316b0d939Timo Sirainen [--key ssl_key ... --cert ssl_cert ...] [pkg_fmri_pattern ...]
0b6924ad1943fe5c6917fc49f675d8f316b0d939Timo Sirainen pkgrepo contents [-m] [-t action_type ...] -s repo_uri_or_path
0b6924ad1943fe5c6917fc49f675d8f316b0d939Timo Sirainen [--key ssl_key ... --cert ssl_cert ...] [pkg_fmri_pattern ...]
0b6924ad1943fe5c6917fc49f675d8f316b0d939Timo Sirainen pkgrepo rebuild [-p publisher ...] -s repo_uri_or_path [--key ssl_key ...
463f6ea04af934a68facaca0ff089bc306de3f98Timo Sirainen --cert ssl_cert ...] [--no-catalog] [--no-index]
4334b9b032298defd4d3906f5357698ff016ead0Timo Sirainen pkgrepo refresh [-p publisher ...] -s repo_uri_or_path [--key ssl_key ...
4334b9b032298defd4d3906f5357698ff016ead0Timo Sirainen --cert ssl_cert ...] [--no-catalog] [--no-index]
4334b9b032298defd4d3906f5357698ff016ead0Timo Sirainen pkgrepo remove [-n] [-p publisher ...] -s repo_uri_or_path
4334b9b032298defd4d3906f5357698ff016ead0Timo Sirainen pkg_fmri_pattern ...
4334b9b032298defd4d3906f5357698ff016ead0Timo Sirainen pkgrepo set [-p publisher ...] -s repo_uri_or_path
4334b9b032298defd4d3906f5357698ff016ead0Timo Sirainen section/property[+|-]=[value] ... or
4334b9b032298defd4d3906f5357698ff016ead0Timo Sirainen section/property[+|-]=([value]) ...
4334b9b032298defd4d3906f5357698ff016ead0Timo Sirainen pkgrepo verify [-d] [-p publisher ...] [-i ignored_dep_file ...]
82ea464c113f43aaa2b2e23de334cf3081c332beTimo Sirainen [--disable verification ...] -s repo_uri_or_path
82ea464c113f43aaa2b2e23de334cf3081c332beTimo Sirainen pkgrepo fix [-v] [-p publisher ...] -s repo_uri_or_path
82ea464c113f43aaa2b2e23de334cf3081c332beTimo Sirainen pkgrepo diff [-vq] [--strict] [--parsable] [-p publisher ...]
82ea464c113f43aaa2b2e23de334cf3081c332beTimo Sirainen -s first_repo_uri_or_path [--key ssl_key ... --cert ssl_cert ...]
82ea464c113f43aaa2b2e23de334cf3081c332beTimo Sirainen -s second_repo_uri_or_path [--key ssl_key ... --cert ssl_cert ...]
82ea464c113f43aaa2b2e23de334cf3081c332beTimo Sirainen pkgrepo version
82ea464c113f43aaa2b2e23de334cf3081c332beTimo Sirainen Displays a usage message."""))
82ea464c113f43aaa2b2e23de334cf3081c332beTimo Sirainen """Option exception. """
82ea464c113f43aaa2b2e23de334cf3081c332beTimo Sirainen """Parse the repository location provided and attempt to transform it
82ea464c113f43aaa2b2e23de334cf3081c332beTimo Sirainen into a valid repository URI.
ba55ec8fdf79301bfce9838d773250cef9486178Timo Sirainen return publisher.RepositoryURI(misc.parse_uri(uri))
82ea464c113f43aaa2b2e23de334cf3081c332beTimo Sirainen usage(_("At least one package pattern must be provided."),
82ea464c113f43aaa2b2e23de334cf3081c332beTimo Sirainen # Get repository object.
82ea464c113f43aaa2b2e23de334cf3081c332beTimo Sirainen usage(_("A package repository location must be provided "
82ea464c113f43aaa2b2e23de334cf3081c332beTimo Sirainen repo = get_repo(conf, read_only=False, subcommand=subcommand)
89a89730a1dd98edb5c16a5b65f693389eb81124Timo Sirainen # Find matching packages.
89a89730a1dd98edb5c16a5b65f693389eb81124Timo Sirainen matching, refs = repo.get_matching_fmris(pargs, pubs=pubs)
e0fab14602b73ff590b2a9c5d9e67e2dfb5d1f9eTimo Sirainen # Don't make any changes; display list of packages to be
66967e15d8ed35f30493dd9694a0aabe1a266f9dTimo Sirainen # removed and exit.
66967e15d8ed35f30493dd9694a0aabe1a266f9dTimo Sirainen packages = set(f for m in matching.values() for f in m)
66967e15d8ed35f30493dd9694a0aabe1a266f9dTimo Sirainen logger.info(_("{count:d} package(s) will be removed:\n"
e0fab14602b73ff590b2a9c5d9e67e2dfb5d1f9eTimo Sirainen _("Removing packages for publisher {0} ...").format(pub))
e0fab14602b73ff590b2a9c5d9e67e2dfb5d1f9eTimo Sirainen repo.remove_packages(packages[pub], progtrack=progtrack,
66967e15d8ed35f30493dd9694a0aabe1a266f9dTimo Sirainen # Add a newline between each publisher.
66967e15d8ed35f30493dd9694a0aabe1a266f9dTimo Sirainendef get_repo(conf, allow_invalid=False, read_only=True, subcommand=None):
66967e15d8ed35f30493dd9694a0aabe1a266f9dTimo Sirainen """Return the repository object for current program configuration.
66967e15d8ed35f30493dd9694a0aabe1a266f9dTimo Sirainen 'allow_invalid' specifies whether potentially corrupt repositories are
66967e15d8ed35f30493dd9694a0aabe1a266f9dTimo Sirainen allowed; should only be True if performing a rebuild operation."""
e0fab14602b73ff590b2a9c5d9e67e2dfb5d1f9eTimo Sirainen usage(_("Network repositories are not currently supported "
a2738cdb6d2733fb3e186331d68009421a19ea00Timo Sirainen raise sr.RepositoryInvalidError(str(repo_uri))
fb502495e9306fe51e9d2c0019e622a98e9803abTimo Sirainen return sr.Repository(allow_invalid=allow_invalid, read_only=read_only,
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainendef setup_transport(repo_uri, subcommand=None, prefix=None, verbose=False,
9e095dd6a77097356aca8216356d4d71ef1bea45Timo Sirainen remote_prefix=True, ssl_key=None, ssl_cert=None):
4334b9b032298defd4d3906f5357698ff016ead0Timo Sirainen usage(_("No repository location specified."), cmd=subcommand)
0a0cd45a633112a2ae6aad801c1e6afe53ab95deTimo Sirainen incoming_dir = tempfile.mkdtemp(dir=temp_root)
c09f9f95db314e7482c95e502e1c56ed6c555797Timo Sirainen # Create transport and transport config.
d66ef20c30fee728899ee168c75fcc5ff8fbdac1Timo Sirainen xport, xport_cfg = transport.setup_transport()
c09f9f95db314e7482c95e502e1c56ed6c555797Timo Sirainen xport_cfg.add_cache(cache_dir, readonly=False)
e4c81823af1fc43ca3f2ce9eb4af7fc8f57b13a5Timo Sirainen # Configure target publisher.
2524ef7b34965a1b1895d6140fd8296bf57c78d2Timo Sirainen src_pub = transport.setup_publisher(str(repo_uri), pub, xport,
0892446b45c195461bb7be6599f02d97e1e2c9b2Timo Sirainen xport_cfg, remote_prefix=remote_prefix, ssl_key=ssl_key,
fb502495e9306fe51e9d2c0019e622a98e9803abTimo Sirainen """Add publisher(s) to the specified repository."""
c09f9f95db314e7482c95e502e1c56ed6c555797Timo Sirainen usage(_("No repository location specified."), cmd=subcommand)
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainen usage(_("Network repositories are not currently supported "
e0fab14602b73ff590b2a9c5d9e67e2dfb5d1f9eTimo Sirainen usage(_("At least one publisher must be specified"),
e0fab14602b73ff590b2a9c5d9e67e2dfb5d1f9eTimo Sirainen error(_("Invalid publisher prefix '{0}'").format(pfx),
a215abacb2d2d1e1bcd475756aab809038ae4277Timo Sirainen repo = get_repo(conf, read_only=False, subcommand=subcommand)
61e6367a259e2473f33df42fda8ceeb3b8b48416Timo Sirainen # Elide the publishers that already exist, but retain the order
61e6367a259e2473f33df42fda8ceeb3b8b48416Timo Sirainen # publishers were specified in.
61e6367a259e2473f33df42fda8ceeb3b8b48416Timo Sirainen # Tricky logic; _set_pub will happily add new publishers if necessary
61e6367a259e2473f33df42fda8ceeb3b8b48416Timo Sirainen # and not set any properties if you didn't specify any.
61e6367a259e2473f33df42fda8ceeb3b8b48416Timo Sirainen rval = _set_pub(conf, subcommand, {}, new_pubs, repo)
66dc739bb67d678770e1b7a7bc75f4f6f9523d2aTimo Sirainen # No publisher existed previously, so set the default publisher
61e6367a259e2473f33df42fda8ceeb3b8b48416Timo Sirainen # to be the first new one that was added.
61e6367a259e2473f33df42fda8ceeb3b8b48416Timo Sirainen # Some of the publishers that were requested for addition
61e6367a259e2473f33df42fda8ceeb3b8b48416Timo Sirainen # were already known.
61e6367a259e2473f33df42fda8ceeb3b8b48416Timo Sirainen error(_("specified publisher(s) already exist: {0}").format(
61e6367a259e2473f33df42fda8ceeb3b8b48416Timo Sirainen """Remove publisher(s) from a repository"""
785ee8becdb11e41abaaf64c28eb3923215d1f27Timo Sirainen opts, pargs = getopt.getopt(args, "ns:", ["synchronous"])
785ee8becdb11e41abaaf64c28eb3923215d1f27Timo Sirainen usage(_("No repository location specified."), cmd=subcommand)
785ee8becdb11e41abaaf64c28eb3923215d1f27Timo Sirainen usage(_("Network repositories are not currently supported "
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainen usage(_("At least one publisher must be specified"),
463f6ea04af934a68facaca0ff089bc306de3f98Timo Sirainen error(_("Invalid publisher prefix(es):\n {0}").format(
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainen repo = get_repo(conf, read_only=False, subcommand=subcommand)
20344c0e814139e3c365fbb9287478f91512089eTimo Sirainen # Publishers left if remove succeeds.
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainen left = [pfx for pfx in repo.publishers if pfx not in pargs]
dd62b77c932d1b518f2a3e4bf80e36542becc256Timo Sirainen error(_("The following publisher(s) could not be found:\n "
dd62b77c932d1b518f2a3e4bf80e36542becc256Timo Sirainen "{0}").format("\n ".join(noexisting)), cmd=subcommand)
e3fc1874694a8ddba9552ec23f9952f74f33d1d5Timo Sirainen logger.info(_("\'{pfx}\'\t({num} package(s))").format(
e3fc1874694a8ddba9552ec23f9952f74f33d1d5Timo Sirainen defaultpfx = repo.cfg.get_property("publisher", "prefix")
e3fc1874694a8ddba9552ec23f9952f74f33d1d5Timo Sirainen repo.remove_publisher(existing, repo_path, synch)
c0435c854a0e7246373b9752d163095cc4fbe985Timo Sirainen # Change the repository publisher/prefix property, if necessary.
601f5f14c6cde28f0e0c6ca7c5d735315d3d48dfTimo Sirainen " Setting 'publisher/prefix' to '{0}',"
4334b9b032298defd4d3906f5357698ff016ead0Timo Sirainen " The 'publisher/prefix' property has been"
602a0434db30d8e3292d1c161a803d96a879a74fTimo Sirainen """Create a package repository at the given location."""
52041ed691a26ca80e4e805765e9f55ec097c8f1Martti Rannanjärvi opts, pargs = getopt.getopt(args, "s:", ["version="])
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainen # This option is currently private and allows creating a
07e4875d250e7a7157cd99132aafc773cf3cdf83Timo Sirainen # repository with a specific format based on version.
52041ed691a26ca80e4e805765e9f55ec097c8f1Martti Rannanjärvi usage(_("Version must be an integer value."),
07e4875d250e7a7157cd99132aafc773cf3cdf83Timo Sirainen usage(_("Only one repository location may be specified."),
252db51b6c0a605163326b3ea5d09e9936ca3b29Timo Sirainen usage(_("No repository location specified."), cmd=subcommand)
52041ed691a26ca80e4e805765e9f55ec097c8f1Martti Rannanjärvi usage(_("Network repositories are not currently supported "
a85c629c5d75a5fd9489ba14d5d4f54f3cddd591Aki Tuomi # Attempt to create a repository at the specified location. Allow
a85c629c5d75a5fd9489ba14d5d4f54f3cddd591Aki Tuomi # whatever exceptions are raised to bubble up.
01f4ee4a0243f3fe9af763e1a540cd5cff0d63f5Timo Sirainen sr.repository_create(repo_uri, version=version)
4b9f99761df5014c659cd87fddaf6854af428cfcTimo Sirainen """Display repository properties."""
a85c629c5d75a5fd9489ba14d5d4f54f3cddd591Aki Tuomi opts, pargs = getopt.getopt(args, "F:Hp:s:", ["key=", "cert="])
d28179fd78550a58be44dcb1e3e830ab7d33172dTimo Sirainen # Setup transport so configuration can be retrieved.
d28179fd78550a58be44dcb1e3e830ab7d33172dTimo Sirainen usage(_("A package repository location must be provided "
d28179fd78550a58be44dcb1e3e830ab7d33172dTimo Sirainen xport, xpub, tmp_dir = setup_transport(conf.get("repo_uri"),
923115fd382904fa13bb09bf307bf2835b52df60Timo Sirainen subcommand=subcommand, ssl_key=key, ssl_cert=cert)
252db51b6c0a605163326b3ea5d09e9936ca3b29Timo Sirainen # Get properties.
e0c3d5460d1cc0c440cb7723c8c2eef8d0afe9b9Timo Sirainen return _get_pub(conf, subcommand, xport, xpub, omit_headers,
e0c3d5460d1cc0c440cb7723c8c2eef8d0afe9b9Timo Sirainen return _get_repo(conf, subcommand, xport, xpub, omit_headers,
6f08b98ac63c25b747120d0c8f8e319b4e26ab0fTimo Sirainendef _get_repo(conf, subcommand, xport, xpub, omit_headers, out_format, pargs):
e0c3d5460d1cc0c440cb7723c8c2eef8d0afe9b9Timo Sirainen """Display repository properties."""
6f08b98ac63c25b747120d0c8f8e319b4e26ab0fTimo Sirainen # Configuration index is indexed by section name and property name.
e0c3d5460d1cc0c440cb7723c8c2eef8d0afe9b9Timo Sirainen # Retrieve and flatten it to simplify listing process.
e0c3d5460d1cc0c440cb7723c8c2eef8d0afe9b9Timo Sirainen cfg_idx = stat_idx.get("repository", {}).get("configuration", {})
e0c3d5460d1cc0c440cb7723c8c2eef8d0afe9b9Timo Sirainen # Set minimum widths for section and property name columns by using the
e0c3d5460d1cc0c440cb7723c8c2eef8d0afe9b9Timo Sirainen # length of the column headers.
e0c3d5460d1cc0c440cb7723c8c2eef8d0afe9b9Timo Sirainen max_sname_len = max(max_sname_len, len(sname))
e0c3d5460d1cc0c440cb7723c8c2eef8d0afe9b9Timo Sirainen max_pname_len = max(max_pname_len, len(pname))
7b42d6cbee8186195d8c5e66078043a0fa1f25c1Timo Sirainen # SECTION PROPERTY VALUE
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainen # <sec_1> <prop_1> <prop_1_value>
7a77b948806106b46a33f3e6a3869657f49877fdTimo Sirainen # <sec_2> <prop_2> <prop_2_value>
7b42d6cbee8186195d8c5e66078043a0fa1f25c1Timo Sirainen "section" : [("default", "json", "tsv"), _("SECTION"), ""],
7b42d6cbee8186195d8c5e66078043a0fa1f25c1Timo Sirainen "property" : [("default", "json", "tsv"), _("PROPERTY"), ""],
b7651d283ca261015ef3c445f1f27f340f0864e2Timo Sirainen "value" : [("default", "json", "tsv"), _("VALUE"), ""],
7b42d6cbee8186195d8c5e66078043a0fa1f25c1Timo Sirainen desired_field_order = (_("SECTION"), _("PROPERTY"), _("VALUE"))
51e1a1c280ccb461a15827f7987d09cb9708b6e3Timo Sirainen # Default output formatting.
7b42d6cbee8186195d8c5e66078043a0fa1f25c1Timo Sirainen def_fmt = "{0:" + str(max_sname_len) + "} {1:" + str(max_pname_len) + \
89e195dfb5c4b0efd9b9f459771a4467674e5b1fTimo Sirainen if found or (not req_props and out_format == "default"):
89e195dfb5c4b0efd9b9f459771a4467674e5b1fTimo Sirainen # print without trailing newline.
89e195dfb5c4b0efd9b9f459771a4467674e5b1fTimo Sirainen sys.stdout.write(misc.get_listing(desired_field_order,
89e195dfb5c4b0efd9b9f459771a4467674e5b1fTimo Sirainen field_data, gen_listing(), out_format, def_fmt,
a0b6b441fc679e562e79be0fb2819ffc24ab5b74Timo Sirainen # Don't pollute other output formats.
a0b6b441fc679e562e79be0fb2819ffc24ab5b74Timo Sirainendef _get_matching_pubs(subcommand, pubs, xport, xpub, out_format="default",
a0b6b441fc679e562e79be0fb2819ffc24ab5b74Timo Sirainen # Retrieve publisher information.
89e195dfb5c4b0efd9b9f459771a4467674e5b1fTimo Sirainen pub_data = [p for p in pub_data if p.prefix in found]
f5982bb5b0a704e88fa2b44b0b74e365d13103b9Timo Sirainen # Assign transport information.
f5982bb5b0a704e88fa2b44b0b74e365d13103b9Timo Sirainen # Establish initial return value and perform early exit if appropriate.
f5982bb5b0a704e88fa2b44b0b74e365d13103b9Timo Sirainen # Don't pollute other output formats.
f5982bb5b0a704e88fa2b44b0b74e365d13103b9Timo Sirainen err_msg = _("no matching publishers found in "
f5982bb5b0a704e88fa2b44b0b74e365d13103b9Timo Sirainen return EXIT_OOPS, None, None
68a4946b12583b88fa802e52ebee45cd96056772Timo Sirainendef _get_pub(conf, subcommand, xport, xpub, omit_headers, out_format, pubs,
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainen """Display publisher properties."""
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainen rval, found, pub_data = _get_matching_pubs(subcommand, pubs, xport,
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainen # Set minimum widths for section and property name columns by using the
f5982bb5b0a704e88fa2b44b0b74e365d13103b9Timo Sirainen # length of the column headers and data.
f5982bb5b0a704e88fa2b44b0b74e365d13103b9Timo Sirainen [len(_("PUBLISHER"))] + [len(p) for p in found]
f5982bb5b0a704e88fa2b44b0b74e365d13103b9Timo Sirainen # For each requested publisher, retrieve the requested property data.
f5982bb5b0a704e88fa2b44b0b74e365d13103b9Timo Sirainen "publisher": {
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainen "registration-uri": pub_repo.registration_uri,
f5982bb5b0a704e88fa2b44b0b74e365d13103b9Timo Sirainen "legal-uris": [],
3785910c303507db5f629684e6dde2cc7f83668eTimo Sirainen "mirrors": [],
4106a25399703eb6cbb166dcbd5bb932cb2f7ad2Timo Sirainen "origins": [],
4106a25399703eb6cbb166dcbd5bb932cb2f7ad2Timo Sirainen "related-uris": [],
c06f4017027263cf3a08becc551f5126409e2a83Timo Sirainen # Determine possible set of properties and lengths.
c06f4017027263cf3a08becc551f5126409e2a83Timo Sirainen max_sname_len = max(max_sname_len, len(sname))
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainen max_pname_len = max(max_pname_len, len(pname))
c06f4017027263cf3a08becc551f5126409e2a83Timo Sirainen # Determine properties to display.
90b8f131849540fa374aede95edd86d47d35c09dTimo Sirainen # PUBLISHER SECTION PROPERTY VALUE
c06f4017027263cf3a08becc551f5126409e2a83Timo Sirainen # <pub_1> <sec_1> <prop_1> <prop_1_value>
c06f4017027263cf3a08becc551f5126409e2a83Timo Sirainen # <pub_1> <sec_2> <prop_2> <prop_2_value>
c09f9f95db314e7482c95e502e1c56ed6c555797Timo Sirainen "publisher" : [("default", "json", "tsv"), _("PUBLISHER"), ""],
c09f9f95db314e7482c95e502e1c56ed6c555797Timo Sirainen "section" : [("default", "json", "tsv"), _("SECTION"), ""],
c09f9f95db314e7482c95e502e1c56ed6c555797Timo Sirainen "property" : [("default", "json", "tsv"), _("PROPERTY"), ""],
c09f9f95db314e7482c95e502e1c56ed6c555797Timo Sirainen "value" : [("default", "json", "tsv"), _("VALUE"), ""],
90b8f131849540fa374aede95edd86d47d35c09dTimo Sirainen desired_field_order = (_("PUBLISHER"), _("SECTION"), _("PROPERTY"),
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainen # Default output formatting.
252db51b6c0a605163326b3ea5d09e9936ca3b29Timo Sirainen def_fmt = "{0:" + str(max_pubname_len) + "} {1:" + str(max_sname_len) + \
fa39c427573ada77265b833db687ca7e854794a1Timo Sirainen if found or (not req_props and out_format == "default"):
fa39c427573ada77265b833db687ca7e854794a1Timo Sirainen # print without trailing newline.
6d404348751c19ac37cfb42375abdd3c5f298e30Timo Sirainen sys.stdout.write(misc.get_listing(desired_field_order,
6d404348751c19ac37cfb42375abdd3c5f298e30Timo Sirainen field_data, gen_listing(), out_format, def_fmt,
904f9d5654b9c39edcdf32883e5e88771faf4d69Timo Sirainen # Don't pollute other output formats.
5ca745ae8e9903ef5265360e4c882e9314595020Timo Sirainen """Display a list of known publishers and a summary of known packages
5ca745ae8e9903ef5265360e4c882e9314595020Timo Sirainen and when the package data for the given publisher was last updated.
5ca745ae8e9903ef5265360e4c882e9314595020Timo Sirainen opts, pargs = getopt.getopt(args, "F:Hp:s:", ["key=", "cert="])
7ef5ca6fb59a318c821a852ae48a2edbb671d7ddTimo Sirainen usage(_("command does not take operands"), cmd=subcommand)
7ef5ca6fb59a318c821a852ae48a2edbb671d7ddTimo Sirainen # Setup transport so status can be retrieved.
7662010b03ffe5f2a6ecf4b4eb220d1c65efea76Timo Sirainen usage(_("A package repository location must be provided "
fe363b433b8038a69b55169da9dca27892ad7d18Timo Sirainen xport, xpub, tmp_dir = setup_transport(conf.get("repo_uri"),
7ef5ca6fb59a318c821a852ae48a2edbb671d7ddTimo Sirainen subcommand=subcommand, ssl_key=key, ssl_cert=cert)
0928812e725cd3a4debab2a93d0c9b0436a4de9fTimo Sirainen # Retrieve repository status information.
0928812e725cd3a4debab2a93d0c9b0436a4de9fTimo Sirainen pub_idx = stat_idx.get("repository", {}).get("publishers", {})
14175321ddb88619015866978c05a27786ca4814Timo Sirainen last_update = pdata.get("last-catalog-update", "")
14175321ddb88619015866978c05a27786ca4814Timo Sirainen # Reformat the date into something more user
14175321ddb88619015866978c05a27786ca4814Timo Sirainen # friendly (and locale specific).
5ca745ae8e9903ef5265360e4c882e9314595020Timo Sirainen last_update = pkg.catalog.basic_ts_to_datetime(
5ca745ae8e9903ef5265360e4c882e9314595020Timo Sirainen rstatus = _(pub_idx[pfx].get("status", "online"))
14175321ddb88619015866978c05a27786ca4814Timo Sirainen # PUBLISHER PACKAGES STATUS UPDATED
14175321ddb88619015866978c05a27786ca4814Timo Sirainen # <pub_1> <num_uniq_pkgs> <status> <cat_last_modified>
a10ed8c47534b4c6b6bf2711ccfe577e720a47b4Timo Sirainen # <pub_2> <num_uniq_pkgs> <status> <cat_last_modified>
439dd06aec3301e65d650f6dc1d4a1a00b356b4fTimo Sirainen "publisher" : [("default", "json", "tsv"), _("PUBLISHER"), ""],
439dd06aec3301e65d650f6dc1d4a1a00b356b4fTimo Sirainen "packages" : [("default", "json", "tsv"), _("PACKAGES"), ""],
14175321ddb88619015866978c05a27786ca4814Timo Sirainen "status" : [("default", "json", "tsv"), _("STATUS"), ""],
14175321ddb88619015866978c05a27786ca4814Timo Sirainen "updated" : [("default", "json", "tsv"), _("UPDATED"), ""],
51d379cbc50242a13462d0fded50e013eb00cc07Timo Sirainen desired_field_order = (_("PUBLISHER"), "", _("PACKAGES"), _("STATUS"),
51d379cbc50242a13462d0fded50e013eb00cc07Timo Sirainen _("UPDATED"))
51d379cbc50242a13462d0fded50e013eb00cc07Timo Sirainen # Default output formatting.
51d379cbc50242a13462d0fded50e013eb00cc07Timo Sirainen [len(desired_field_order[0])] + [len(p) for p in found]
51d379cbc50242a13462d0fded50e013eb00cc07Timo Sirainen def_fmt = "{0:" + pub_len + "} {1:8} {2:16} {3}"
51d379cbc50242a13462d0fded50e013eb00cc07Timo Sirainen if found or (not pubs and out_format == "default"):
51d379cbc50242a13462d0fded50e013eb00cc07Timo Sirainen # print without trailing newline.
51d379cbc50242a13462d0fded50e013eb00cc07Timo Sirainen sys.stdout.write(misc.get_listing(desired_field_order,
51d379cbc50242a13462d0fded50e013eb00cc07Timo Sirainen field_data, gen_listing(), out_format, def_fmt,
c7acd38cd4ef76a0f4652f9ca659ea5e64458b52Timo Sirainen # Don't pollute other output formats.
c7acd38cd4ef76a0f4652f9ca659ea5e64458b52Timo Sirainen """List all packages matching the specified patterns."""
282a436a74d8835edb45cc019b1c916013013fd3Timo Sirainen opts, pargs = getopt.getopt(args, "F:Hp:s:", ["key=", "cert="])
5a9bbcb13b2dd2cf9a825c7ed09fe7ee143b1275Timo Sirainen # Setup transport so configuration can be retrieved.
5a9bbcb13b2dd2cf9a825c7ed09fe7ee143b1275Timo Sirainen usage(_("A package repository location must be provided "
5a9bbcb13b2dd2cf9a825c7ed09fe7ee143b1275Timo Sirainen xport, xpub, tmp_dir = setup_transport(conf.get("repo_uri"),
4c096615cb86a826fda377b87df22c579bfe5525Timo Sirainen subcommand=subcommand, ssl_key=key, ssl_cert=cert)
4c096615cb86a826fda377b87df22c579bfe5525Timo Sirainen rval, found, pub_data = _get_matching_pubs(subcommand, pubs, xport,
4c096615cb86a826fda377b87df22c579bfe5525Timo Sirainen xpub, out_format=out_format, use_transport=True)
01e606cda5192c4254c090624a0b2ca92da6da8eTimo Sirainen "build-release":
01e606cda5192c4254c090624a0b2ca92da6da8eTimo Sirainen d["value"] = \
032964c7cc6788188b63ae6270fc26cbd4a3ca26Timo Sirainen "publisher": [("default", "json", "tsv"), _("PUBLISHER"), ""],
032964c7cc6788188b63ae6270fc26cbd4a3ca26Timo Sirainen "name": [("default", "json", "tsv"), _("NAME"), ""],
032964c7cc6788188b63ae6270fc26cbd4a3ca26Timo Sirainen "version": [("default", "json"), _("VERSION"), ""],
032964c7cc6788188b63ae6270fc26cbd4a3ca26Timo Sirainen "release": [("json", "tsv",), _("RELEASE"), ""],
032964c7cc6788188b63ae6270fc26cbd4a3ca26Timo Sirainen "build-release": [("json", "tsv",), _("BUILD RELEASE"), ""],
032964c7cc6788188b63ae6270fc26cbd4a3ca26Timo Sirainen "branch": [("json", "tsv",), _("BRANCH"), ""],
032964c7cc6788188b63ae6270fc26cbd4a3ca26Timo Sirainen "timestamp": [("json", "tsv",), _("PACKAGING DATE"), ""],
032964c7cc6788188b63ae6270fc26cbd4a3ca26Timo Sirainen "pkg.fmri": [("json", "tsv",), _("FMRI"), ""],
12a3540693ab69ec622e04d1b3b66962b8b2a3d9Timo Sirainen desired_field_order = (_("PUBLISHER"), _("NAME"), "O", _("VERSION"),
12a3540693ab69ec622e04d1b3b66962b8b2a3d9Timo Sirainen _("SUMMARY"), _("DESCRIPTION"), _("CATEGORIES"), _("RELEASE"),
66d84e6f0ae34a3cf5b8fa8e009d6caf025b6a2aTimo Sirainen _("BUILD RELEASE"), _("BRANCH"), _("PACKAGING DATE"), _("FMRI"),
12a3540693ab69ec622e04d1b3b66962b8b2a3d9Timo Sirainen # Default output formatting.
12a3540693ab69ec622e04d1b3b66962b8b2a3d9Timo Sirainen max(list(len(p) for p in found) + [len(_("PUBLISHER"))]))
12a3540693ab69ec622e04d1b3b66962b8b2a3d9Timo Sirainen def_fmt = "{0:" + max_pub_name_len + "} {1:45} {2:1} {3}"
b80c329a25b5b07f5e68cd44ef0fef9db6613486Timo Sirainen # print without trailing newline.
b80c329a25b5b07f5e68cd44ef0fef9db6613486Timo Sirainen desired_field_order, field_data, gen_listing(),
73b9c241e7fb6abdccda88e88fbd32e844dbc185Timo Sirainen # No matching packages.
12a3540693ab69ec622e04d1b3b66962b8b2a3d9Timo Sirainen error(apx.PackageMatchErrors(unmatched_fmris=unmatched),
12a3540693ab69ec622e04d1b3b66962b8b2a3d9Timo Sirainen # One or more patterns didn't match a package from any
12a3540693ab69ec622e04d1b3b66962b8b2a3d9Timo Sirainen # publisher; only display the error.
12a3540693ab69ec622e04d1b3b66962b8b2a3d9Timo Sirainen error(apx.PackageMatchErrors(unmatched_fmris=unmatched),
01f4ee4a0243f3fe9af763e1a540cd5cff0d63f5Timo Sirainen """A helper function to refresh all specified publishers."""
2c0f1cb7a0564d48ec43c7315ea46ea38d2abd19Timo Sirainen progtrack.set_purpose(progtrack.PURPOSE_LISTING)
2c0f1cb7a0564d48ec43c7315ea46ea38d2abd19Timo Sirainen progtrack.refresh_start(pub_cnt=len(pub_data), full_refresh=True,
6eb0192085073a63ea03443860c412bb5312dd7eTimo Sirainen # Assume that a catalog doesn't exist for the target
4b9f99761df5014c659cd87fddaf6854af428cfcTimo Sirainen # publisher and drive on.
5f3151744f3ffa73b57391d4a237884b75423f57Timo Sirainen """List package contents."""
5f3151744f3ffa73b57391d4a237884b75423f57Timo Sirainen opts, pargs = getopt.getopt(args, "ms:t:", ["key=", "cert="])
89a89730a1dd98edb5c16a5b65f693389eb81124Timo Sirainen # Setup transport so configuration can be retrieved.
82ea464c113f43aaa2b2e23de334cf3081c332beTimo Sirainen usage(_("A package repository location must be provided "
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainen xport, xpub, tmp_dir = setup_transport(conf.get("repo_uri"),
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainen subcommand=subcommand, ssl_key=key, ssl_cert=cert)
e2ce8d4a6ac5d82a906178148453e7613fab9ba0Timo Sirainen rval, found, pub_data = _get_matching_pubs(subcommand, pubs, xport,
032964c7cc6788188b63ae6270fc26cbd4a3ca26Timo Sirainen # Default output prints out the raw manifest. The -m option is implicit
032964c7cc6788188b63ae6270fc26cbd4a3ca26Timo Sirainen # for now and supported to make the interface equivalent to pkg
a94936bafd127680184da114c6a177b37ff656e5Timo Sirainen for f, states, attr in cat.gen_packages(matched=matched,
07e4875d250e7a7157cd99132aafc773cf3cdf83Timo Sirainen # Build a generator expression based on whether specific action types
07e4875d250e7a7157cd99132aafc773cf3cdf83Timo Sirainen # were provided.
252db51b6c0a605163326b3ea5d09e9936ca3b29Timo Sirainen # If query is limited to specific action types, use the more
a85c629c5d75a5fd9489ba14d5d4f54f3cddd591Aki Tuomi # efficient type-based generation mechanism.
a85c629c5d75a5fd9489ba14d5d4f54f3cddd591Aki Tuomi (m.fmri, a, None, None, None)
0c1835a90dd1dcedaeaedd1cd91672299cbeb5beTimo Sirainen (m.fmri, a, None, None, None)
0c1835a90dd1dcedaeaedd1cd91672299cbeb5beTimo Sirainen # Determine if the query returned any results by "peeking" at the first
0c1835a90dd1dcedaeaedd1cd91672299cbeb5beTimo Sirainen # value returned from the generator expression.
f4735bf7ec2019fdc730e9ebdb39e5a4ea580405Timo Sirainenpkgrepo: contents: This package contains no actions with the types specified
f4735bf7ec2019fdc730e9ebdb39e5a4ea580405Timo Sirainenpkgrepo: contents: These packages contain no actions with the types specified
f4735bf7ec2019fdc730e9ebdb39e5a4ea580405Timo Sirainen lines = misc.list_actions_by_attrs(actionlist, attrs)
if not text:
if unmatched:
if manifests:
for p in unmatched:
return rval
if not pubs:
return EXIT_OOPS
return rval
elif build_catalog:
elif build_index:
xpub)
return rval
return rval
key = None
cert = None
if pargs:
return EXIT_OK
key = None
cert = None
if pargs:
return EXIT_OK
elif add_content:
elif refresh_index:
xpub)
return rval
return rval
props = {}
if not pargs:
except ValueError:
if bad_args:
if pubs:
if not pubs:
failed = []
if not target:
val = []
if new_pub:
if failed:
return EXIT_PARTIAL
return EXIT_OOPS
return EXIT_OK
return EXIT_OK
if args:
return EXIT_OK
verify_error_header = None
verify_warning_header = None
verify_reason_headers = None
def __load_verify_msgs():
global verify_error_header
global verify_warning_header
global verify_reason_headers
return formatted_message, None
if altroot:
igf))
ignored_dep_files = []
if pargs:
if not repo_uri:
xpub)
return rval
if bad_fmri:
found_pubs = []
if bad_fmris:
return EXIT_OOPS
return EXIT_OK
ignored_dep_files = []
if pargs:
if not repo_uri:
xpub)
return rval
if not verbose:
found_pubs = []
if not fmri:
if verbose:
if broken_fmris:
if failed_fix_paths:
if bad_deps:
return EXIT_OOPS
return EXIT_OK
return text
if quiet:
return EXIT_DIFF
if not verbose:
if parsable:
if quiet:
return EXIT_DIFF
cat_lm_pub = None
cat_lm_rpub = None
if compare_cat:
return EXIT_DIFF
if not verbose:
if not same_cat:
if not same_pkgs:
com_pub_info = {}
if parsable:
if not same_cat:
if parsable:
for f in minus_fmris:
if parsable:
del minus_fmris
for f in plus_fmris:
if parsable:
del plus_fmris
if not same_pkgs:
if parsable:
if com_pub_info:
if same_repo:
return EXIT_OK
if verbose:
if parsable:
return EXIT_DIFF
if not parsable:
t_row = []
if not cell:
return EXIT_DIFF
return EXIT_OOPS
if not repo_uri:
if not com_repo_uri:
return rval
return rval
def main_func():
conf = {}
if DebugValues:
subcommand = None
if pargs:
if show_usage:
elif not subcommand:
if not func:
raise __e
return __ret
except IOError: