pkgrepo.py revision 2132
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore# CDDL HEADER START
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore# The contents of this file are subject to the terms of the
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore# Common Development and Distribution License (the "License").
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore# You may not use this file except in compliance with the License.
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore# or http://www.opensolaris.org/os/licensing.
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore# See the License for the specific language governing permissions
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore# and limitations under the License.
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore# When distributing Covered Code, include this CDDL HEADER in each
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore# If applicable, add the following below this CDDL HEADER, with the
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore# fields enclosed by brackets "[]" replaced with your own identifying
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore# information: Portions Copyright [yyyy] [name of copyright owner]
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore# CDDL HEADER END
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore# Copyright (c) 2010 Oracle and/or its affiliates. All rights reserved.
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore# pkgrepo exit codes
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore# listing constants
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amoreimport pkg.client.transport.transport as transport
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore """To be called at program finish."""
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore """Emit an error message prefixed by the command name """
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore # If we get passed something like an Exception, we can convert
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore # it down to a string.
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore # If the message starts with whitespace, assume that it should come
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore # *before* the command-name prefix.
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore # This has to be a constant value as we can't reliably get our actual
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore # program name on all platforms.
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amoredef usage(usage_error=None, cmd=None, retcode=2, full=False):
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore """Emit a usage message and optionally prefix it with a more
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore specific error message. Causes program to exit.
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore # The full usage message isn't desired.
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore logger.error(_("Try `pkgrepo --help or -?' for more "
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore "information."))
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore pkgrepo [options] command [cmd_options] [operands]
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore pkgrepo create [--version] uri_or_path
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore pkgrepo add-signing-ca-cert [-p publisher ...]
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore [-s repo_uri_or_path] path ...
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore pkgrepo add-signing-intermediate-cert [-p publisher ...]
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore [-s repo_uri_or_path] path ...
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore pkgrepo get [-F format] [-p publisher ...] [-s repo_uri_or_path]
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore pkgrepo info [-F format] [-H] [-p publisher ...]
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore [-s repo_uri_or_path]
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore pkgrepo rebuild [-p publisher ...] [-s repo_uri_or_path]
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore [--no-catalog] [--no-index]
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore pkgrepo refresh [-p publisher ...] [-s repo_uri_or_path]
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore [--no-catalog] [--no-index]
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore pkgrepo remove-signing-ca-cert [-p publisher ...]
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore [-s repo_uri_or_path] hash ...
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore pkgrepo remove-signing-intermediate-cert [-p publisher ...]
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore [-s repo_uri_or_path] hash ...
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore pkgrepo set [-p publisher ...] [-s repo_uri_or_path]
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore section/property[+|-]=[value] ... or
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore section/property[+|-]=([value]) ...
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore pkgrepo version
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore Displays a usage message."""))
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore """Option exception. """
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore """Parse the repository location provided and attempt to transform it
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore into a valid repository URI.
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore return publisher.RepositoryURI(misc.parse_uri(uri))
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore # Get repository object.
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore usage(_("A package repository location must be provided "
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore repo = get_repo(conf, read_only=False, subcommand=subcommand)
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore usage(_("At least one path to a certificate must be provided."))
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore certs = [os.path.join(orig_cwd, f) for f in pargs]
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore repo.add_signing_certs(certs, ca=ca, pub=pfx)
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore except (apx.ApiException, sr.RepositoryError), e:
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore # Default to list of all publishers.
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore # Assume default publisher or older repository.
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore # Add for each publisher specified.
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore """Add the provided signing ca certificates to the repository for
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore the given publisher."""
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore pubs, failed = _add_certs(conf, subcommand, args, True)
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore error(_("Unable to add signing ca certificates for "
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore "publisher '%(pfx)s':\n%(details)s") % locals(),
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amoredef subcmd_add_signing_intermediate_cert(conf, args):
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore subcommand = "add-signing-intermediate-cert"
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore pubs, failed = _add_certs(conf, subcommand, args, True)
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore error(_("Unable to add signing intermediate "
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore "certificates for publisher '%(pfx)s':\n"
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore error(_("Unable to add signing intermediate "
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amoredef _remove_certs(conf, subcommand, args, ca):
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore # Get repository object.
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore usage(_("A package repository location must be provided "
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore repo = get_repo(conf, read_only=False, subcommand=subcommand)
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore usage(_("At least one certificate hash must be provided."))
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore repo.remove_signing_certs(pargs, ca=True, pub=pfx)
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore except (apx.ApiException, sr.RepositoryError), e:
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore # Default to list of all publishers.
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore # Assume default publisher or older repository.
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore # Add for each publisher specified.
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amoredef subcmd_remove_signing_ca_cert(conf, args):
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore pubs, failed = _remove_certs(conf, subcommand, args, True)
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore error(_("Unable to remove signing ca certificates for "
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore "publisher '%(pfx)s':\n%(details)s") % locals(),
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amoredef subcmd_remove_signing_intermediate_cert(conf, args):
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore subcommand = "remove-signing-intermediate-cert"
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore pubs, failed = _remove_certs(conf, subcommand, args, True)
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore error(_("Unable to remove signing intermediate "
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore "certificates for publisher '%(pfx)s':\n"
49ef7e0638c8b771d8a136eae78b1c0f99acc8e0Garrett D'Amore error(_("Unable to remove signing intermediate "
return EXIT_PARTIAL
return EXIT_OOPS
return EXIT_OK
return nval
elif val is None:
nval = []
for v in val:
nval = None
if multi_value:
if not omit_headers:
(field_data[f], v)
if not path:
if not repo_uri:
version = None
except ValueError:
elif pargs:
if not repo_uri:
return EXIT_OK
return EXIT_OOPS
if pubs:
del props
def gen_listing():
field_data = {
return EXIT_PARTIAL
return EXIT_OOPS
return EXIT_OK
return EXIT_OOPS, None, None
pargs):
return rval
pub_idx = {}
if pub_repo:
del props
def gen_listing():
field_data = {
return rval
return EXIT_OOPS
if pargs:
def gen_listing():
if last_update:
field_data = {
return EXIT_PARTIAL
return EXIT_OOPS
return EXIT_OK
if pargs:
return EXIT_OK
elif build_catalog:
elif build_index:
xpub)
return rval
return rval
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:
repo)
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
def main_func():
global orig_cwd
except OSError, e:
orig_cwd = None
except KeyError:
orig_cwd = None
conf = {}
subcommand = None
if pargs:
if show_usage:
elif not subcommand:
if not func:
raise __e
return __ret
except IOError: