pkgrepo.py revision 2028
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch# CDDL HEADER START
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch# The contents of this file are subject to the terms of the
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch# Common Development and Distribution License (the "License").
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch# You may not use this file except in compliance with the License.
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch# See the License for the specific language governing permissions
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch# and limitations under the License.
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch# When distributing Covered Code, include this CDDL HEADER in each
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch# If applicable, add the following below this CDDL HEADER, with the
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch# fields enclosed by brackets "[]" replaced with your own identifying
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch# information: Portions Copyright [yyyy] [name of copyright owner]
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch# CDDL HEADER END
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch# Copyright (c) 2010 Oracle and/or its affiliates. All rights reserved.
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch# pkgrepo exit codes
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch# listing constants
7384b4e78eaab44693c985192276e31322155e32Stephan Boschimport pkg.client.transport.transport as transport
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch """To be called at program finish."""
eb325a5a90c1d2655e74972bde0de6a699d2c864Stephan Bosch """Emit an error message prefixed by the command name """
30d917bcd48d70af0371baf27571cc198d621a62Timo Sirainen # If we get passed something like an Exception, we can convert
9d0aee99a8c80d71137aa9b8c216cc203bec7a9aTimo Sirainen # it down to a string.
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch # If the message starts with whitespace, assume that it should come
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch # *before* the command-name prefix.
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch # This has to be a constant value as we can't reliably get our actual
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch # program name on all platforms.
7384b4e78eaab44693c985192276e31322155e32Stephan Boschdef usage(usage_error=None, cmd=None, retcode=2, full=False):
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch """Emit a usage message and optionally prefix it with a more
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch specific error message. Causes program to exit.
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch # The full usage message isn't desired.
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch logger.error(_("Try `pkgrepo --help or -?' for more "
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch "information."))
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch pkgrepo [options] command [cmd_options] [operands]
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch pkgrepo create [--version] uri_or_path
aacf2a69acc59e9382578d6f4e030788abc79706Timo Sirainen pkgrepo add-signing-ca-cert [-p publisher ...]
aacf2a69acc59e9382578d6f4e030788abc79706Timo Sirainen [-s repo_uri_or_path] path ...
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch pkgrepo add-signing-intermediate-cert [-p publisher ...]
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch [-s repo_uri_or_path] path ...
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch pkgrepo get [-p publisher ...] [-s repo_uri_or_path]
415e16c3dc185578695b7d88e561a52de6c8b1b1Timo Sirainen pkgrepo info [-F format] [-H] [-p publisher ...]
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch [-s repo_uri_or_path]
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch pkgrepo rebuild [-s repo_uri_or_path] [--no-catalog]
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch pkgrepo refresh [-s repo_uri_or_path] [--no-catalog]
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch pkgrepo remove-signing-ca-cert [-p publisher ...]
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch [-s repo_uri_or_path] hash ...
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch pkgrepo remove-signing-intermediate-cert [-p publisher ...]
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch [-s repo_uri_or_path] hash ...
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch pkgrepo set [-p publisher ...] [-s repo_uri_or_path]
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch section/property[+|-]=[value] ... or
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch section/property[+|-]=([value]) ...
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch pkgrepo version
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch Displays a usage message."""))
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch """Option exception. """
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch """Parse the repository location provided and attempt to transform it
1a9a35a6b307f8d5b25345af55e40a99162b4072Timo Sirainen into a valid repository URI.
1a9a35a6b307f8d5b25345af55e40a99162b4072Timo Sirainen return publisher.RepositoryURI(misc.parse_uri(uri))
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch # Get repository object.
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch usage(_("A package repository location must be provided "
415e16c3dc185578695b7d88e561a52de6c8b1b1Timo Sirainen repo = get_repo(conf, read_only=False, subcommand=subcommand)
415e16c3dc185578695b7d88e561a52de6c8b1b1Timo Sirainen usage(_("At least one path to a certificate must be provided."))
56d1345c43bbd28c36b7faa85e4163bd9e874290Timo Sirainen certs = [os.path.join(orig_cwd, f) for f in pargs]
415e16c3dc185578695b7d88e561a52de6c8b1b1Timo Sirainen except (apx.ApiException, sr.RepositoryError), e:
415e16c3dc185578695b7d88e561a52de6c8b1b1Timo Sirainen # Default to list of all publishers.
if failed:
return EXIT_PARTIAL
return EXIT_OOPS
return EXIT_OK
if failed:
if pfx:
return EXIT_PARTIAL
return EXIT_OOPS
return EXIT_OK
failed = []
if not pubs:
if failed:
return EXIT_PARTIAL
return EXIT_OOPS
return EXIT_OK
if failed:
if pfx:
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
pargs):
return EXIT_OOPS
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:
return EXIT_OK
if pargs:
return EXIT_OK
elif add_content:
elif refresh_index:
return EXIT_OK
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:
"http://defect.opensolaris.org and including the\nabove "
raise __e
return __ret
except IOError: