pkgrepo.py revision 1968
1795e934ebcd58175d3b5bbdd811b13c7889efa3Timo Sirainen# CDDL HEADER START
1795e934ebcd58175d3b5bbdd811b13c7889efa3Timo Sirainen# The contents of this file are subject to the terms of the
1795e934ebcd58175d3b5bbdd811b13c7889efa3Timo Sirainen# Common Development and Distribution License (the "License").
1795e934ebcd58175d3b5bbdd811b13c7889efa3Timo Sirainen# You may not use this file except in compliance with the License.
1795e934ebcd58175d3b5bbdd811b13c7889efa3Timo Sirainen# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
1795e934ebcd58175d3b5bbdd811b13c7889efa3Timo Sirainen# See the License for the specific language governing permissions
1795e934ebcd58175d3b5bbdd811b13c7889efa3Timo Sirainen# and limitations under the License.
1795e934ebcd58175d3b5bbdd811b13c7889efa3Timo Sirainen# When distributing Covered Code, include this CDDL HEADER in each
1795e934ebcd58175d3b5bbdd811b13c7889efa3Timo Sirainen# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
1795e934ebcd58175d3b5bbdd811b13c7889efa3Timo Sirainen# If applicable, add the following below this CDDL HEADER, with the
1795e934ebcd58175d3b5bbdd811b13c7889efa3Timo Sirainen# fields enclosed by brackets "[]" replaced with your own identifying
1795e934ebcd58175d3b5bbdd811b13c7889efa3Timo Sirainen# information: Portions Copyright [yyyy] [name of copyright owner]
1795e934ebcd58175d3b5bbdd811b13c7889efa3Timo Sirainen# CDDL HEADER END
1795e934ebcd58175d3b5bbdd811b13c7889efa3Timo Sirainen# Copyright (c) 2010 Oracle and/or its affiliates. All rights reserved.
1795e934ebcd58175d3b5bbdd811b13c7889efa3Timo Sirainen# pkgrepo exit codes
1795e934ebcd58175d3b5bbdd811b13c7889efa3Timo Sirainen# listing constants
1795e934ebcd58175d3b5bbdd811b13c7889efa3Timo Sirainen """Emit an error message prefixed by the command name """
1795e934ebcd58175d3b5bbdd811b13c7889efa3Timo Sirainen # If we get passed something like an Exception, we can convert
1795e934ebcd58175d3b5bbdd811b13c7889efa3Timo Sirainen # it down to a string.
1795e934ebcd58175d3b5bbdd811b13c7889efa3Timo Sirainen # If the message starts with whitespace, assume that it should come
1795e934ebcd58175d3b5bbdd811b13c7889efa3Timo Sirainen # *before* the command-name prefix.
1795e934ebcd58175d3b5bbdd811b13c7889efa3Timo Sirainen # This has to be a constant value as we can't reliably get our actual
1795e934ebcd58175d3b5bbdd811b13c7889efa3Timo Sirainen # program name on all platforms.
1795e934ebcd58175d3b5bbdd811b13c7889efa3Timo Sirainendef usage(usage_error=None, cmd=None, retcode=2, full=False):
1795e934ebcd58175d3b5bbdd811b13c7889efa3Timo Sirainen """Emit a usage message and optionally prefix it with a more
1795e934ebcd58175d3b5bbdd811b13c7889efa3Timo Sirainen specific error message. Causes program to exit.
1795e934ebcd58175d3b5bbdd811b13c7889efa3Timo Sirainen # The full usage message isn't desired.
1795e934ebcd58175d3b5bbdd811b13c7889efa3Timo Sirainen logger.error(_("Try `pkgrepo --help or -?' for more "
1795e934ebcd58175d3b5bbdd811b13c7889efa3Timo Sirainen "information."))
1795e934ebcd58175d3b5bbdd811b13c7889efa3Timo Sirainen pkgrepo [options] subcommand [subcmd_options] [operands]
1795e934ebcd58175d3b5bbdd811b13c7889efa3Timo Sirainen pkgrepo create [repo_uri_or_path]
1795e934ebcd58175d3b5bbdd811b13c7889efa3Timo Sirainen pkgrepo publisher [pub_prefix ...]
1795e934ebcd58175d3b5bbdd811b13c7889efa3Timo Sirainen pkgrepo rebuild [--no-index]
1795e934ebcd58175d3b5bbdd811b13c7889efa3Timo Sirainen pkgrepo refresh [--no-catalog] [--no-index]
1795e934ebcd58175d3b5bbdd811b13c7889efa3Timo Sirainen pkgrepo version
1795e934ebcd58175d3b5bbdd811b13c7889efa3Timo Sirainen -s repo_uri_or_path The location of the repository to use for
1795e934ebcd58175d3b5bbdd811b13c7889efa3Timo Sirainen operations. Network repositories are not
dcd50ecbfe796bd76f2d63483c534cc0e4e94164Timo Sirainen currently supported.
dcd50ecbfe796bd76f2d63483c534cc0e4e94164Timo Sirainen --help or -?"""))
1795e934ebcd58175d3b5bbdd811b13c7889efa3Timo Sirainen """Option exception. """
1795e934ebcd58175d3b5bbdd811b13c7889efa3Timo Sirainen """Parse the repository location provided and attempt to transform it
1795e934ebcd58175d3b5bbdd811b13c7889efa3Timo Sirainen into a valid repository URI.
1795e934ebcd58175d3b5bbdd811b13c7889efa3Timo Sirainen if uri.find("://") == -1 and not uri.startswith("file:/"):
1795e934ebcd58175d3b5bbdd811b13c7889efa3Timo Sirainen # Convert the file path to a URI.
1795e934ebcd58175d3b5bbdd811b13c7889efa3Timo Sirainen scheme, netloc, path, params, query, fragment = \
1795e934ebcd58175d3b5bbdd811b13c7889efa3Timo Sirainen urlparse.urlparse(uri, "file", allow_fragments=0)
1795e934ebcd58175d3b5bbdd811b13c7889efa3Timo Sirainen usage(_("Network repositories are not currently supported."),
1795e934ebcd58175d3b5bbdd811b13c7889efa3Timo Sirainen # During urlunparsing below, ensure that the path starts with
1795e934ebcd58175d3b5bbdd811b13c7889efa3Timo Sirainen # only one '/' character, if any are present.
1795e934ebcd58175d3b5bbdd811b13c7889efa3Timo Sirainen # Rebuild the url with the sanitized components.
1795e934ebcd58175d3b5bbdd811b13c7889efa3Timo Sirainen uri = urlparse.urlunparse((scheme, netloc, path, params,
1795e934ebcd58175d3b5bbdd811b13c7889efa3Timo Sirainendef get_repo(conf, read_only=True, refresh_index=False):
1795e934ebcd58175d3b5bbdd811b13c7889efa3Timo Sirainen """Return the repository object for current program configuration."""
1795e934ebcd58175d3b5bbdd811b13c7889efa3Timo Sirainen raise sr.RepositoryInvalidError(str(repo_uri))
1795e934ebcd58175d3b5bbdd811b13c7889efa3Timo Sirainen return sr.Repository(auto_create=False, read_only=read_only,
1795e934ebcd58175d3b5bbdd811b13c7889efa3Timo Sirainen """Create a package repository at the given location."""
1795e934ebcd58175d3b5bbdd811b13c7889efa3Timo Sirainen usage(_("Only one repository location may be specified."),
1795e934ebcd58175d3b5bbdd811b13c7889efa3Timo Sirainen usage(_("No repository location specified."), cmd=subcommand)
1795e934ebcd58175d3b5bbdd811b13c7889efa3Timo Sirainen # Attempt to create a repository at the specified location. Allow
1795e934ebcd58175d3b5bbdd811b13c7889efa3Timo Sirainen # whatever exceptions are raised to bubble up.
1795e934ebcd58175d3b5bbdd811b13c7889efa3Timo Sirainendef print_col_listing(desired_field_order, field_data, field_values, out_format,
1795e934ebcd58175d3b5bbdd811b13c7889efa3Timo Sirainen """Print a columnar listing defined by provided values."""
1795e934ebcd58175d3b5bbdd811b13c7889efa3Timo Sirainen # Custom sort function for preserving field ordering
1795e934ebcd58175d3b5bbdd811b13c7889efa3Timo Sirainen return desired_field_order.index(get_header(one)) - \
1795e934ebcd58175d3b5bbdd811b13c7889efa3Timo Sirainen # Functions for manipulating field_data records
1795e934ebcd58175d3b5bbdd811b13c7889efa3Timo Sirainen # Create a formatting string for the default output
1795e934ebcd58175d3b5bbdd811b13c7889efa3Timo Sirainen # Create a formatting string for the tsv output
1795e934ebcd58175d3b5bbdd811b13c7889efa3Timo Sirainen fmt = "\t".join('%s' for x in xrange(num_fields))
1795e934ebcd58175d3b5bbdd811b13c7889efa3Timo Sirainen # Extract the list of headers from the field_data dictionary. Ensure
1795e934ebcd58175d3b5bbdd811b13c7889efa3Timo Sirainen # they are extracted in the desired order by using the custom sort
1795e934ebcd58175d3b5bbdd811b13c7889efa3Timo Sirainen hdrs = map(get_header, sorted(filter(filter_func, field_data.values()),
1795e934ebcd58175d3b5bbdd811b13c7889efa3Timo Sirainen # Output a header if desired.
1795e934ebcd58175d3b5bbdd811b13c7889efa3Timo Sirainen values = map(get_value, sorted(filter(filter_func,
return EXIT_OOPS
del cfg_idx
del props
def gen_listing():
field_data = {
return EXIT_PARTIAL
return EXIT_OOPS
return EXIT_OK
except ValueError:
if bad_args:
return EXIT_OOPS
pub_idx = {}
def gen_listing():
field_data = {
return EXIT_PARTIAL
return EXIT_OOPS
return EXIT_OK
if pargs:
if build_index:
return EXIT_OK
if pargs:
return EXIT_OK
if add_content:
if refresh_index:
return EXIT_OK
if args:
return EXIT_OK
def main_func():
conf = {}
if not arg:
subcommand = None
if pargs:
if show_usage:
elif not subcommand:
if not func:
"http://defect.opensolaris.org and including the\nabove "
raise __e
return __ret
except IOError: