pkgrepo.py revision 3140
1968N/A# The contents of this file are subject to the terms of the 1968N/A# Common Development and Distribution License (the "License"). 1968N/A# You may not use this file except in compliance with the License. 1968N/A# See the License for the specific language governing permissions 1968N/A# and limitations under the License. 1968N/A# When distributing Covered Code, include this CDDL HEADER in each 1968N/A# If applicable, add the following below this CDDL HEADER, with the 1968N/A# fields enclosed by brackets "[]" replaced with your own identifying 1968N/A# information: Portions Copyright [yyyy] [name of copyright owner] 3031N/A# Copyright (c) 2010, 2014, Oracle and/or its affiliates. All rights reserved. 2028N/A """To be called at program finish.""" 1968N/A """Emit an error message prefixed by the command name """ 1968N/A # If we get passed something like an Exception, we can convert 1968N/A # If the message starts with whitespace, assume that it should come 1968N/A # *before* the command-name prefix. 1968N/A # This has to be a constant value as we can't reliably get our actual 1968N/A # program name on all platforms. 1968N/A """Emit a usage message and optionally prefix it with a more 1968N/A specific error message. Causes program to exit. 1968N/A # The full usage message isn't desired. 1978N/A pkgrepo [options] command [cmd_options] [operands] 2510N/A pkgrepo create [--version ver] uri_or_path 2301N/A pkgrepo add-publisher -s repo_uri_or_path publisher ... 2970N/A pkgrepo remove-publisher [-n] [--synchronous] -s repo_uri_or_path 2864N/A pkgrepo get [-F format] [-p publisher ...] -s repo_uri_or_path 2864N/A pkgrepo info [-F format] [-H] [-p publisher ...] -s repo_uri_or_path 2864N/A [--key ssl_key ... --cert ssl_cert ...] 2864N/A pkgrepo list [-F format] [-H] [-p publisher ...] -s repo_uri_or_path 2864N/A [--key ssl_key ... --cert ssl_cert ...] [pkg_fmri_pattern ...] 3041N/A pkgrepo contents [-m] [-t action_type ...] -s repo_uri_or_path 3041N/A [--key ssl_key ... --cert ssl_cert ...] [pkg_fmri_pattern ...] 2864N/A pkgrepo rebuild [-p publisher ...] -s repo_uri_or_path [--key ssl_key ... 2864N/A --cert ssl_cert ...] [--no-catalog] [--no-index] 2864N/A pkgrepo refresh [-p publisher ...] -s repo_uri_or_path [--key ssl_key ... 2864N/A --cert ssl_cert ...] [--no-catalog] [--no-index] 2301N/A pkgrepo remove [-n] [-p publisher ...] -s repo_uri_or_path 2301N/A pkgrepo set [-p publisher ...] -s repo_uri_or_path 3138N/A pkgrepo verify [-d] [-p publisher ...] [-i ignored_dep_file ...] 3138N/A [--disable verification ...] -s repo_uri_or_path 2843N/A pkgrepo fix [-v] [-p publisher ...] -s repo_uri_or_path 1978N/A Displays a usage message."""))
1968N/A """Parse the repository location provided and attempt to transform it 1968N/A into a valid repository URI. 2301N/A usage(_(
"At least one package pattern must be provided."),
2301N/A usage(_(
"A package repository location must be provided " 2301N/A # Don't make any changes; display list of packages to be 2301N/A # Add a newline between each publisher. 2990N/A """Return the repository object for current program configuration. 2990N/A 'allow_invalid' specifies whether potentially corrupt repositories are 2990N/A allowed; should only be True if performing a rebuild operation.""" 2028N/A usage(_(
"Network repositories are not currently supported " 2028N/A # Create transport and transport config. 2028N/A # Configure target publisher. 2142N/A """Add publisher(s) to the specified repository.""" 2142N/A usage(_(
"Network repositories are not currently supported " 2142N/A usage(_(
"At least one publisher must be specified"),
2142N/A # Elide the publishers that already exist, but retain the order 2142N/A # publishers were specified in. 2142N/A # Tricky logic; _set_pub will happily add new publishers if necessary 2142N/A # and not set any properties if you didn't specify any. 2142N/A # No publisher existed previously, so set the default publisher 2142N/A # to be the first new one that was added. 2142N/A # Some of the publishers that were requested for addition 2142N/A error(_(
"specified publisher(s) already exist: %s") %
2970N/A """Remove publisher(s) from a repository""" 2970N/A usage(_(
"Network repositories are not currently supported " 2970N/A usage(_(
"At least one publisher must be specified"),
2970N/A # Publishers left if remove succeeds. 2970N/A error(_(
"The following publisher(s) could not be found:\n %s")
2970N/A msg(_(
"The default publisher was removed." 2970N/A msg(_(
"The default publisher was removed." 2028N/A """Create a package repository at the given location.""" 2028N/A # This option is currently private and allows creating a 2028N/A # repository with a specific format based on version. 2028N/A usage(_(
"Only one repository location may be specified."),
2028N/A usage(_(
"Network repositories are not currently supported " 2028N/A # Attempt to create a repository at the specified location. Allow 2028N/A # whatever exceptions are raised to bubble up. 2028N/A """Display repository properties.""" 2028N/A # Setup transport so configuration can be retrieved. 2028N/A usage(_(
"A package repository location must be provided " 2028N/A """Display repository properties.""" 1968N/A # Configuration index is indexed by section name and property name. 2028N/A # Retrieve and flatten it to simplify listing process. 1968N/A # Set minimum widths for section and property name columns by using the 1968N/A # length of the column headers. 1968N/A # <sec_1> <prop_1> <prop_1_value> 1968N/A # <sec_2> <prop_2> <prop_2_value> 2510N/A "section" : [(
"default",
"json",
"tsv"), _(
"SECTION"),
""],
2510N/A "property" : [(
"default",
"json",
"tsv"), _(
"PROPERTY"),
""],
2510N/A "value" : [(
"default",
"json",
"tsv"), _(
"VALUE"),
""],
1968N/A # Default output formatting. 2453N/A # print without trailing newline. 1968N/A # Don't pollute other output formats. 2028N/A # Retrieve publisher information. 2510N/A # Assign transport information. 2028N/A # Establish initial return value and perform early exit if appropriate. 2028N/A # Don't pollute other output formats. 2132N/A """Display publisher properties.""" 2028N/A # Set minimum widths for section and property name columns by using the 2028N/A # length of the column headers and data. 2028N/A # For each requested publisher, retrieve the requested property data. 2028N/A # Determine possible set of properties and lengths. 2028N/A # Determine properties to display. 2028N/A # PUBLISHER SECTION PROPERTY VALUE 2028N/A # <pub_1> <sec_1> <prop_1> <prop_1_value> 2028N/A # <pub_1> <sec_2> <prop_2> <prop_2_value> 2510N/A "publisher" : [(
"default",
"json",
"tsv"), _(
"PUBLISHER"),
""],
2510N/A "section" : [(
"default",
"json",
"tsv"), _(
"SECTION"),
""],
2510N/A "property" : [(
"default",
"json",
"tsv"), _(
"PROPERTY"),
""],
2510N/A "value" : [(
"default",
"json",
"tsv"), _(
"VALUE"),
""],
2028N/A # Default output formatting. 2453N/A # print without trailing newline. 2028N/A # Don't pollute other output formats. 1968N/A """Display a list of known publishers and a summary of known packages 1968N/A and when the package data for the given publisher was last updated. 2028N/A # Setup transport so status can be retrieved. 2028N/A usage(_(
"A package repository location must be provided " 2028N/A # Retrieve repository status information. 2028N/A # Reformat the date into something more user 2028N/A # friendly (and locale specific). 2028N/A # PUBLISHER PACKAGES STATUS UPDATED 2028N/A # <pub_1> <num_uniq_pkgs> <status> <cat_last_modified> 2028N/A # <pub_2> <num_uniq_pkgs> <status> <cat_last_modified> 2510N/A "publisher" : [(
"default",
"json",
"tsv"), _(
"PUBLISHER"),
""],
2510N/A "packages" : [(
"default",
"json",
"tsv"), _(
"PACKAGES"),
""],
2510N/A "status" : [(
"default",
"json",
"tsv"), _(
"STATUS"),
""],
2510N/A "updated" : [(
"default",
"json",
"tsv"), _(
"UPDATED"),
""],
1968N/A # Default output formatting. 2453N/A # print without trailing newline. 1968N/A # Don't pollute other output formats. 2510N/A """List all packages matching the specified patterns.""" 2510N/A # Setup transport so configuration can be retrieved. 2510N/A usage(_(
"A package repository location must be provided " 2510N/A "publisher": [(
"default",
"json",
"tsv"), _(
"PUBLISHER"),
""],
2510N/A "name": [(
"default",
"json",
"tsv"), _(
"NAME"),
""],
2510N/A "version": [(
"default",
"json"), _(
"VERSION"),
""],
2510N/A "release": [(
"json",
"tsv",), _(
"RELEASE"),
""],
2510N/A "build-release": [(
"json",
"tsv",), _(
"BUILD RELEASE"),
""],
2510N/A "branch": [(
"json",
"tsv",), _(
"BRANCH"),
""],
2510N/A "timestamp": [(
"json",
"tsv",), _(
"PACKAGING DATE"),
""],
2510N/A "pkg.fmri": [(
"json",
"tsv",), _(
"FMRI"),
""],
2510N/A "short_state": [(
"default",
"tsv"),
"O",
""],
2510N/A _(
"SUMMARY"), _(
"DESCRIPTION"), _(
"CATEGORIES"), _(
"RELEASE"),
2510N/A _(
"BUILD RELEASE"), _(
"BRANCH"), _(
"PACKAGING DATE"), _(
"FMRI"),
2510N/A # Default output formatting. 2510N/A # print without trailing newline. 2510N/A # One or more patterns didn't match a package from any 2510N/A # publisher; only display the error. 3041N/A """A helper function to refresh all specified publishers.""" 3041N/A # Assume that a catalog doesn't exist for the target 3041N/A """List package contents.""" 3041N/A # Setup transport so configuration can be retrieved. 3041N/A usage(_(
"A package repository location must be provided " 3041N/A # Default output prints out the raw manifest. The -m option is implicit 3138N/A # for now and supported to make the interface equivalent to pkg 3041N/A # Build a generator expression based on whether specific action types 3041N/A # If query is limited to specific action types, use the more 3041N/A # efficient type-based generation mechanism. 3041N/A # Determine if the query returned any results by "peeking" at the first 3041N/A # value returned from the generator expression. 3041N/Apkgrepo: contents: This package contains no actions with the types specified 3041N/Ausing the -t option""",
"""\ 3041N/Apkgrepo: contents: These packages contain no actions with the types specified 3041N/Apkgrepo: contents: no packages matching the following patterns you specified 3041N/Awere found in the repository."""))
2990N/A """In an attempt to allow operations on potentially corrupt 2990N/A repositories, 'local' repositories (filesystem-basd ones) are handled 1968N/A """Rebuild the repository's catalog and index data (as permitted).""" 2028N/A # Why? Who knows; but do what was requested--nothing! 2028N/A # Setup transport so operation can be performed. 2028N/A usage(_(
"A package repository location must be provided " 1968N/A """Refresh the repository's catalog and index data (as permitted).""" 1968N/A # Why? Who knows; but do what was requested--nothing! 2028N/A # Setup transport so operation can be performed. 2028N/A usage(_(
"A package repository location must be provided " 2028N/A """Set repository properties.""" 2028N/A # Attempt to parse property into components. 2028N/A # Store property values by section. 2028N/A # Parse the property value into a list if 2028N/A # necessary, otherwise append it to the list 2028N/A # of values for the property. 2028N/A # Determine if previous value is already 2028N/A # a list, and if not, convert and append 2028N/A # Otherwise, just store the value. 2028N/A usage(_(
"a property name and value must be provided in the " 2028N/A usage(_(
"A package repository location must be provided " 2028N/A """Set publisher properties.""" 2028N/A # Default to list of all publishers. 2028N/A # If there are still no known publishers, this 2028N/A # operation cannot succeed, so fail now. 2028N/A usage(_(
"One or more publishers must be specified to " 2028N/A "create and set properties for as none exist yet."),
2028N/A # Get publishers and update properties. 2028N/A # Get a copy of the existing publisher. 2028N/A # If the target property expects 2028N/A # a list, transform the provided 2028N/A # value into one if it isn't 2028N/A """Set repository properties.""" 1968N/A """Display the version of the pkg(5) API.""" 2843N/A """Since our gettext isn't loaded we need to ensure our globals have 2843N/A correct content by calling this method. These values are used by both 2843N/A fix when in verbose mode, and verify""" 2843N/A # A map of error detail types to the human-readable description of each 2843N/A # type. These correspond to keys in the dictionary returned by 2843N/A "path": _(
"Repository path"),
2843N/A "actual": _(
"Computed hash"),
2843N/A "permissionspath": _(
"Path"),
3138N/A "type":_(
"Dependency type"),
2843N/A """Format a verify_tuple, of the form (error, path, message, reason) 2843N/A returning a formatted error message, and an FMRI indicating what 2843N/A packages within the repository are affected. Note that the returned FMRI 2843N/A may not be valid, in which case a path to the broken manifest in the 2843N/A repository is returned instead.""" 2843N/A "%(error_type)16s: %(message)s\n" % \
2843N/A # A list of the details we provide. Some error codes 2843N/A # have different details associated with them. 2843N/A # the detailed error message can be long, so we'll wrap it. If what we 2843N/A # have fits on a single line, use it, otherwise begin displaying the 2843N/A # message on the next line. 2843N/A # sometimes we don't have the key we want, for example we may 2843N/A # not have a file path from the package if the error is a 2843N/A # missing repository file for a 'license' action (which don't 2843N/A # have 'path' attributes, hence no 'fpath' dictionary entry) 3138N/A """Helpler function to collect default ignored-dependency files.""" 3138N/A """Verify the repository content (file, manifest content and 2843N/A usage(_(
"A package repository location must be provided " 2843N/A usage(_(
"Network repositories are not currently supported " 3138N/A usage(_(
"-d or -i option cannot be used when dependency " 2843N/A """Fix the repository content (file and manifest content only) 2843N/A For index and catalog content corruption, a rebuild should be 3138N/A # Dependency verification. Note fix will not force dependency check. 2843N/A usage(_(
"A package repository location must be provided " 2843N/A usage(_(
"Network repositories are not currently supported " 2843N/A """A method passed to sr.Repository.fix(..) to emit verify 2843N/A messages if verbose mode is enabled.""" 3138N/A # When we can't get the FMRI, eg. in the case 3138N/A # of a corrupt manifest, use the path instead. 2843N/A "following packages or paths which were quarantined:\n\n\t" 2843N/A "in the repository:\n\n\t%s") %
3138N/A "dependency issues in the repository:\n\n\t%s") %
2864N/A "name=value, not %(arg)s") % {
1968N/A# Establish a specific exit status which means: "python barfed an exception" 1968N/A# so that we can more easily detect these in testing of the CLI commands. 1968N/A """Catch exceptions raised by the main program function and then print 1968N/A a message and/or exit with an appropriate return code. 1968N/A # Out of memory errors can be raised as EnvironmentErrors with 1968N/A # an errno of ENOMEM, so in order to handle those exceptions 1968N/A # with other errnos, we nest this try block and have the outer 1968N/A # one handle the other instances. 1968N/A # Don't display any messages here to prevent possible further 1968N/A # broken pipe (EPIPE) errors. 1968N/A error(_(
"The pkgrepo command appears out of sync with the " 1968N/A "version is %(client)s while the library\nAPI version is " 1968N/A # Make all warnings be errors. 1968N/A # Ignore python's spurious pipe problems.