options.py revision 2925
2875N/A#!/usr/bin/python
2875N/A#
2875N/A# CDDL HEADER START
2875N/A#
2875N/A# The contents of this file are subject to the terms of the
2875N/A# Common Development and Distribution License (the "License").
2875N/A# You may not use this file except in compliance with the License.
2875N/A#
2875N/A# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
2875N/A# or http://www.opensolaris.org/os/licensing.
2875N/A# See the License for the specific language governing permissions
2875N/A# and limitations under the License.
2875N/A#
2875N/A# When distributing Covered Code, include this CDDL HEADER in each
2875N/A# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
2875N/A# If applicable, add the following below this CDDL HEADER, with the
2875N/A# fields enclosed by brackets "[]" replaced with your own identifying
2875N/A# information: Portions Copyright [yyyy] [name of copyright owner]
2875N/A#
2875N/A# CDDL HEADER END
2875N/A#
2875N/A
2875N/A# Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
2875N/A
2875N/Aimport os
2875N/A
2875N/Aimport pkg.client.pkgdefs as pkgdefs
2875N/Aimport pkg.client.linkedimage as li
2875N/Aimport pkg.misc as misc
2875N/A
2875N/Afrom pkg.client.api_errors import InvalidOptionError
2875N/Afrom pkg.client import global_settings
2875N/A
2875N/A_orig_cwd = None
2875N/A
2875N/A# List of available options for common option processing.
2875N/AACCEPT = "accept"
2875N/AALLOW_RELINK = "allow_relink"
2875N/AATTACH_CHILD = "attach_child"
2875N/AATTACH_PARENT = "attach_parent"
2875N/ABACKUP_BE = "backup_be"
2875N/ABACKUP_BE_NAME = "backup_be_name"
2875N/ABE_ACTIVATE = "be_activate"
2875N/ABE_NAME = "be_name"
2875N/ACONCURRENCY = "concurrency"
2875N/ADENY_NEW_BE = "deny_new_be"
2875N/AFORCE = "force"
2875N/ALI_IGNORE = "li_ignore"
2875N/ALI_IGNORE_ALL = "li_ignore_all"
2875N/ALI_IGNORE_LIST = "li_ignore_list"
2875N/ALI_MD_ONLY = "li_md_only"
2875N/ALI_NAME = "li_name"
2875N/ALI_PARENT_SYNC = "li_parent_sync"
2875N/ALI_PKG_UPDATES = "li_pkg_updates"
2875N/ALI_PROPS = "li_props"
2875N/ALI_TARGET_ALL = "li_target_all"
2875N/ALI_TARGET_LIST = "li_target_list"
2875N/ALIST_ALL = "list_all"
2875N/ALIST_INSTALLED_NEWEST = "list_installed_newest"
2875N/ALIST_NEWEST = "list_newest"
2875N/ALIST_UPGRADABLE = "list_upgradable"
2875N/AMED_IMPLEMENTATION = "med_implementation"
2875N/AMED_VERSION = "med_version"
2875N/ANEW_BE = "new_be"
2875N/ANO_BACKUP_BE = "no_backup_be"
2875N/ANOEXECUTE = "noexecute"
2875N/AOMIT_HEADERS = "omit_headers"
2875N/AORIGINS = "origins"
2875N/APARSABLE_VERSION = "parsable_version"
2875N/AQUIET = "quiet"
2875N/AREFRESH_CATALOGS = "refresh_catalogs"
2875N/AREJECT_PATS = "reject_pats"
2875N/AREQUIRE_BACKUP_BE = "require_backup_be"
2875N/AREQUIRE_NEW_BE = "require_new_be"
2875N/ASHOW_LICENSES = "show_licenses"
2875N/ASTAGE = "stage"
2875N/ASUMMARY = "summary"
2875N/ATAGGED = "tagged"
2875N/AUPDATE_INDEX = "update_index"
2875N/AVERBOSE = "verbose"
2875N/A
2875N/A
2875N/A
2875N/Adef opts_table_cb_beopts(api_inst, opts, opts_new):
2875N/A
2875N/A # synthesize require_new_be and deny_new_be into new_be
2875N/A del opts_new[REQUIRE_NEW_BE]
2875N/A del opts_new[DENY_NEW_BE]
2875N/A opts_new[NEW_BE] = None
2875N/A
2875N/A if (opts[BE_NAME] or opts[REQUIRE_NEW_BE]) and opts[DENY_NEW_BE]:
2875N/A raise InvalidOptionError(InvalidOptionError.INCOMPAT,
2875N/A [REQUIRE_NEW_BE, DENY_NEW_BE])
2875N/A
2875N/A # create a new key called BACKUP_BE in the options array
2875N/A if opts[REQUIRE_NEW_BE] or opts[BE_NAME]:
2875N/A opts_new[NEW_BE] = True
2875N/A if opts[DENY_NEW_BE]:
2875N/A opts_new[NEW_BE] = False
2875N/A
2875N/A # synthesize require_backup_be and no_backup_be into backup_be
2875N/A del opts_new[REQUIRE_BACKUP_BE]
2875N/A del opts_new[NO_BACKUP_BE]
2875N/A opts_new[BACKUP_BE] = None
2875N/A
2875N/A if (opts[REQUIRE_BACKUP_BE] or opts[BACKUP_BE_NAME]) and \
2875N/A opts[NO_BACKUP_BE]:
2875N/A raise InvalidOptionError(InvalidOptionError.INCOMPAT,
2875N/A [REQUIRE_BACKUP_BE, NO_BACKUP_BE])
2875N/A
2875N/A if (opts[REQUIRE_BACKUP_BE] or opts[BACKUP_BE_NAME]) and \
2875N/A (opts[REQUIRE_NEW_BE] or opts[BE_NAME]):
2875N/A raise InvalidOptionError(InvalidOptionError.INCOMPAT,
2875N/A [REQUIRE_BACKUP_BE, REQUIRE_NEW_BE])
2875N/A
2875N/A # create a new key called BACKUP_BE in the options array
2875N/A if opts[REQUIRE_BACKUP_BE] or opts[BACKUP_BE_NAME]:
2875N/A opts_new[BACKUP_BE] = True
2875N/A if opts[NO_BACKUP_BE]:
2875N/A opts_new[BACKUP_BE] = False
2875N/A
2875N/Adef opts_table_cb_li_ignore(api_inst, opts, opts_new):
2875N/A
2875N/A # synthesize li_ignore_all and li_ignore_list into li_ignore
2875N/A del opts_new[LI_IGNORE_ALL]
2875N/A del opts_new[LI_IGNORE_LIST]
2875N/A opts_new[LI_IGNORE] = None
2875N/A
2875N/A # check if there's nothing to ignore
2875N/A if not opts[LI_IGNORE_ALL] and not opts[LI_IGNORE_LIST]:
2875N/A return
2875N/A
2875N/A if opts[LI_IGNORE_ALL]:
2875N/A
2875N/A # can't ignore all and specific images
2875N/A if opts[LI_IGNORE_LIST]:
2875N/A raise InvalidOptionError(InvalidOptionError.INCOMPAT,
2875N/A [LI_IGNORE_ALL, LI_IGNORE_LIST])
2875N/A
2875N/A # can't ignore all and target anything.
2875N/A if LI_TARGET_ALL in opts and opts[LI_TARGET_ALL]:
2875N/A raise InvalidOptionError(InvalidOptionError.INCOMPAT,
2875N/A [LI_IGNORE_ALL, LI_TARGET_ALL])
2875N/A if LI_TARGET_LIST in opts and opts[LI_TARGET_LIST]:
2875N/A raise InvalidOptionError(InvalidOptionError.INCOMPAT,
2875N/A [LI_IGNORE_ALL, LI_TARGET_LIST])
2875N/A if LI_NAME in opts and opts[LI_NAME]:
2875N/A raise InvalidOptionError(InvalidOptionError.INCOMPAT,
2875N/A [LI_IGNORE_ALL, LI_NAME])
2875N/A opts_new[LI_IGNORE] = []
2875N/A return
2875N/A
2875N/A assert opts[LI_IGNORE_LIST]
2875N/A
2875N/A # it doesn't make sense to specify images to ignore if the
2875N/A # user is already specifying images to operate on.
2875N/A if LI_TARGET_ALL in opts and opts[LI_TARGET_ALL]:
2875N/A raise InvalidOptionError(InvalidOptionError.INCOMPAT,
2875N/A [LI_IGNORE_LIST, LI_TARGET_ALL])
2875N/A if LI_TARGET_LIST in opts and opts[LI_TARGET_LIST]:
2875N/A raise InvalidOptionError(InvalidOptionError.INCOMPAT,
2875N/A [LI_IGNORE_LIST, LI_TARGET_LIST])
2875N/A if LI_NAME in opts and opts[LI_NAME]:
2875N/A raise InvalidOptionError(InvalidOptionError.INCOMPAT,
2875N/A [LI_IGNORE_LIST, LI_NAME])
2875N/A
2875N/A li_ignore = []
2875N/A for li_name in opts[LI_IGNORE_LIST]:
2875N/A # check for repeats
2875N/A if li_name in li_ignore:
2875N/A raise InvalidOptionError(
2875N/A InvalidOptionError.ARG_REPEAT, [li_name,
2875N/A LI_IGNORE_LIST])
2875N/A # add to ignore list
2875N/A li_ignore.append(li_name)
2875N/A
2875N/A opts_new[LI_IGNORE] = api_inst.parse_linked_name_list(li_ignore)
2875N/A
2875N/Adef opts_table_cb_li_no_psync(api_inst, opts, opts_new):
2875N/A # if a target child linked image was specified, the no-parent-sync
2875N/A # option doesn't make sense since we know that both the parent and
2875N/A # child image are accessible
2875N/A
2875N/A if LI_TARGET_ALL not in opts:
2875N/A # we don't accept linked image target options
2875N/A assert LI_TARGET_LIST not in opts
2875N/A return
2875N/A
2875N/A if opts[LI_TARGET_ALL] and not opts[LI_PARENT_SYNC]:
2875N/A raise InvalidOptionError(InvalidOptionError.REQUIRED,
2875N/A [LI_TARGET_ALL, LI_PARENT_SYNC])
2875N/A
2875N/A if opts[LI_TARGET_LIST] and not opts[LI_PARENT_SYNC]:
2875N/A raise InvalidOptionError(InvalidOptionError.REQUIRED,
2875N/A [LI_TARGET_LIST, LI_PARENT_SYNC])
2875N/A
2875N/A
2875N/Adef __parse_linked_props(args):
2875N/A """"Parse linked image property options that were specified on the
2875N/A command line into a dictionary. Make sure duplicate properties were
2875N/A not specified."""
2875N/A
2875N/A linked_props = dict()
2875N/A for pv in args:
2875N/A try:
2875N/A p, v = pv.split("=", 1)
2875N/A except ValueError:
2875N/A raise InvalidOptionError(msg=_("linked image "
2875N/A "property arguments must be of the form "
2875N/A "'<name>=<value>'."))
2875N/A
2875N/A if p not in li.prop_values:
2875N/A raise InvalidOptionError(msg=_("invalid linked "
2875N/A "image property: '%s'.") % p)
2875N/A
2875N/A if p in linked_props:
2875N/A raise InvalidOptionError(msg=_("linked image "
2875N/A "property specified multiple times: '%s'.") % p)
2875N/A
2875N/A linked_props[p] = v
2875N/A
2875N/A return linked_props
2875N/A
2875N/Adef opts_table_cb_li_props(api_inst, opts, opts_new):
2875N/A """convert linked image prop list into a dictionary"""
2875N/A
2875N/A opts_new[LI_PROPS] = __parse_linked_props(opts[LI_PROPS])
2875N/A
2875N/Adef opts_table_cb_li_target(api_inst, opts, opts_new):
2875N/A # figure out which option the user specified
2875N/A if opts[LI_TARGET_ALL] and opts[LI_TARGET_LIST]:
2875N/A raise InvalidOptionError(InvalidOptionError.INCOMPAT,
2875N/A [LI_TARGET_ALL, LI_TARGET_LIST])
2875N/A elif opts[LI_TARGET_ALL]:
2875N/A arg1 = LI_TARGET_ALL
2875N/A elif opts[LI_TARGET_LIST]:
2875N/A arg1 = LI_TARGET_LIST
2875N/A else:
2875N/A return
2875N/A
2875N/A if BE_ACTIVATE in opts and not opts[BE_ACTIVATE]:
2875N/A raise InvalidOptionError(InvalidOptionError.REQUIRED,
2875N/A [arg1, BE_ACTIVATE])
2875N/A if BE_NAME in opts and opts[BE_NAME]:
2875N/A raise InvalidOptionError(InvalidOptionError.INCOMPAT,
2875N/A [arg1, BE_NAME])
2875N/A if DENY_NEW_BE in opts and opts[DENY_NEW_BE]:
2875N/A raise InvalidOptionError(InvalidOptionError.INCOMPAT,
2875N/A [arg1, DENY_NEW_BE])
2875N/A if REQUIRE_NEW_BE in opts and opts[REQUIRE_NEW_BE]:
2875N/A raise InvalidOptionError(InvalidOptionError.INCOMPAT,
2875N/A [arg1, REQUIRE_NEW_BE])
2875N/A if REJECT_PATS in opts and opts[REJECT_PATS]:
2875N/A raise InvalidOptionError(InvalidOptionError.INCOMPAT,
2875N/A [arg1, REJECT_PATS])
2875N/A if ORIGINS in opts and opts[ORIGINS]:
2875N/A raise InvalidOptionError(InvalidOptionError.INCOMPAT,
2875N/A [arg1, ORIGINS])
2875N/A
2875N/A # validate linked image name
2875N/A li_target_list = []
2875N/A for li_name in opts[LI_TARGET_LIST]:
2875N/A # check for repeats
2875N/A if li_name in li_target_list:
2875N/A raise InvalidOptionError(
2875N/A InvalidOptionError.ARG_REPEAT, [li_name,
2875N/A LI_TARGET_LIST])
2875N/A # add to ignore list
2875N/A li_target_list.append(li_name)
2875N/A
2875N/A opts_new[LI_TARGET_LIST] = \
2875N/A api_inst.parse_linked_name_list(li_target_list)
2875N/A
2875N/Adef opts_table_cb_li_target1(api_inst, opts, opts_new):
2875N/A # figure out which option the user specified
2875N/A if opts[LI_NAME]:
2875N/A arg1 = LI_NAME
2875N/A else:
2875N/A return
2875N/A
2875N/A if BE_ACTIVATE in opts and not opts[BE_ACTIVATE]:
2875N/A raise InvalidOptionError(InvalidOptionError.REQUIRED,
2875N/A [arg1, BE_ACTIVATE])
2875N/A if BE_NAME in opts and opts[BE_NAME]:
2875N/A raise InvalidOptionError(InvalidOptionError.INCOMPAT,
2875N/A [arg1, BE_NAME])
2875N/A if DENY_NEW_BE in opts and opts[DENY_NEW_BE]:
2875N/A raise InvalidOptionError(InvalidOptionError.INCOMPAT,
2875N/A [arg1, DENY_NEW_BE])
2875N/A if REQUIRE_NEW_BE in opts and opts[REQUIRE_NEW_BE]:
2875N/A raise InvalidOptionError(InvalidOptionError.INCOMPAT,
2875N/A [arg1, REQUIRE_NEW_BE])
2875N/A if REJECT_PATS in opts and opts[REJECT_PATS]:
2875N/A raise InvalidOptionError(InvalidOptionError.INCOMPAT,
2875N/A [arg1, REJECT_PATS])
2875N/A if ORIGINS in opts and opts[ORIGINS]:
2875N/A raise InvalidOptionError(InvalidOptionError.INCOMPAT,
2875N/A [arg1, ORIGINS])
2875N/A
2875N/Adef opts_table_cb_no_headers_vs_quiet(api_inst, opts, opts_new):
2875N/A # check if we accept the -q option
2875N/A if QUIET not in opts:
2875N/A return
2875N/A
2875N/A # -q implies -H
2875N/A if opts[QUIET]:
2875N/A opts_new[OMIT_HEADERS] = True
2875N/A
2875N/Adef opts_table_cb_q(api_inst, opts, opts_new):
2875N/A # Be careful not to overwrite global_settings.client_output_quiet
2875N/A # because it might be set "True" from elsewhere, e.g. in
2875N/A # opts_table_cb_parsable.
2875N/A if opts[QUIET] is True:
2875N/A global_settings.client_output_quiet = True
2875N/A
2875N/Adef opts_table_cb_v(api_inst, opts, opts_new):
2875N/A global_settings.client_output_verbose = opts[VERBOSE]
2875N/A
2875N/Adef opts_table_cb_nqv(api_inst, opts, opts_new):
2875N/A if opts[VERBOSE] and opts[QUIET]:
2875N/A raise InvalidOptionError(InvalidOptionError.INCOMPAT,
2875N/A [VERBOSE, QUIET])
2875N/A
2875N/Adef opts_table_cb_parsable(api_inst, opts, opts_new):
2875N/A if opts[PARSABLE_VERSION] and opts.get(VERBOSE, False):
2875N/A raise InvalidOptionError(InvalidOptionError.INCOMPAT,
2875N/A [VERBOSE, PARSABLE_VERSION])
2875N/A if opts[PARSABLE_VERSION]:
2875N/A try:
2875N/A opts_new[PARSABLE_VERSION] = int(
2875N/A opts[PARSABLE_VERSION])
2875N/A except ValueError:
2875N/A raise InvalidOptionError(
2875N/A options=[PARSABLE_VERSION],
2875N/A msg=_("integer argument expected"))
2875N/A
2875N/A global_settings.client_output_parsable_version = \
2875N/A opts_new[PARSABLE_VERSION]
2875N/A opts_new[QUIET] = True
2875N/A global_settings.client_output_quiet = True
2875N/A
2875N/Adef opts_table_cb_origins(api_inst, opts, opts_new):
2875N/A origins = set()
2875N/A for o in opts[ORIGINS]:
2875N/A origins.add(misc.parse_uri(o, cwd=_orig_cwd))
2875N/A opts_new[ORIGINS] = origins
2875N/A
2875N/Adef opts_table_cb_stage(api_inst, opts, opts_new):
2875N/A if opts[STAGE] == None:
2875N/A opts_new[STAGE] = pkgdefs.API_STAGE_DEFAULT
2875N/A return
2875N/A
2875N/A if opts_new[STAGE] not in pkgdefs.api_stage_values:
2875N/A raise InvalidOptionError(msg=_("invalid operation stage: "
2875N/A "'%s'") % opts[STAGE])
2875N/A
2875N/Adef opts_cb_li_attach(api_inst, opts, opts_new):
2875N/A if opts[ATTACH_PARENT] and opts[ATTACH_CHILD]:
2875N/A raise InvalidOptionError(InvalidOptionError.INCOMPAT,
2875N/A [ATTACH_PARENT, ATTACH_CHILD])
2875N/A
2875N/A if not opts[ATTACH_PARENT] and not opts[ATTACH_CHILD]:
2875N/A raise InvalidOptionError(InvalidOptionError.XOR,
2875N/A [ATTACH_PARENT, ATTACH_CHILD])
2875N/A
2875N/A if opts[ATTACH_CHILD]:
2875N/A # if we're attaching a new child then that doesn't affect
2875N/A # any other children, so ignoring them doesn't make sense.
2875N/A if opts[LI_IGNORE_ALL]:
2875N/A raise InvalidOptionError(
2875N/A InvalidOptionError.INCOMPAT,
2875N/A [ATTACH_CHILD, LI_IGNORE_ALL])
2875N/A if opts[LI_IGNORE_LIST]:
2875N/A raise InvalidOptionError(
2875N/A InvalidOptionError.INCOMPAT,
2875N/A [ATTACH_CHILD, LI_IGNORE_LIST])
2875N/A
2875N/Adef opts_table_cb_md_only(api_inst, opts, opts_new):
2875N/A # if the user didn't specify linked-md-only we're done
2875N/A if not opts[LI_MD_ONLY]:
2875N/A return
2875N/A
2875N/A # li_md_only implies no li_pkg_updates
2875N/A if LI_PKG_UPDATES in opts:
2875N/A opts_new[LI_PKG_UPDATES] = False
2875N/A
2875N/A #
2875N/A # if li_md_only is false that means we're not updating any packages
2875N/A # within the current image so there are a ton of options that no
2875N/A # longer apply to the current operation, and hence are incompatible
2875N/A # with li_md_only.
2875N/A #
2875N/A arg1 = LI_MD_ONLY
2875N/A if BE_NAME in opts and opts[BE_NAME]:
2875N/A raise InvalidOptionError(InvalidOptionError.INCOMPAT,
2875N/A [arg1, BE_NAME])
2875N/A if DENY_NEW_BE in opts and opts[DENY_NEW_BE]:
2875N/A raise InvalidOptionError(InvalidOptionError.INCOMPAT,
2875N/A [arg1, DENY_NEW_BE])
2875N/A if REQUIRE_NEW_BE in opts and opts[REQUIRE_NEW_BE]:
2875N/A raise InvalidOptionError(InvalidOptionError.INCOMPAT,
2875N/A [arg1, REQUIRE_NEW_BE])
2875N/A if LI_PARENT_SYNC in opts and not opts[LI_PARENT_SYNC]:
2875N/A raise InvalidOptionError(InvalidOptionError.REQUIRED,
2875N/A [arg1, LI_PARENT_SYNC])
2875N/A if REJECT_PATS in opts and opts[REJECT_PATS]:
2875N/A raise InvalidOptionError(InvalidOptionError.INCOMPAT,
2875N/A [arg1, REJECT_PATS])
2875N/A
2875N/Adef opts_cb_list(api_inst, opts, opts_new):
2875N/A if opts_new[ORIGINS] and opts_new[LIST_UPGRADABLE]:
2875N/A raise InvalidOptionError(InvalidOptionError.INCOMPAT,
2875N/A [ORIGINS, LIST_UPGRADABLE])
2875N/A
2875N/A if opts_new[ORIGINS] and not opts_new[LIST_NEWEST]:
2875N/A # Use of -g implies -a unless -n is provided.
2875N/A opts_new[LIST_INSTALLED_NEWEST] = True
2875N/A
2875N/A if opts_new[LIST_ALL] and not opts_new[LIST_INSTALLED_NEWEST]:
2875N/A raise InvalidOptionError(InvalidOptionError.REQUIRED,
2875N/A [LIST_ALL, LIST_INSTALLED_NEWEST])
2875N/A
2875N/A if opts_new[LIST_INSTALLED_NEWEST] and opts_new[LIST_NEWEST]:
2875N/A raise InvalidOptionError(InvalidOptionError.INCOMPAT,
2875N/A [LIST_INSTALLED_NEWEST, LIST_NEWEST])
2875N/A
2875N/A if opts_new[LIST_INSTALLED_NEWEST] and opts_new[LIST_UPGRADABLE]:
2875N/A raise InvalidOptionError(InvalidOptionError.INCOMPAT,
2875N/A [LIST_INSTALLED_NEWEST, LIST_UPGRADABLE])
2875N/A
2875N/A if opts_new[SUMMARY] and opts_new[VERBOSE]:
2875N/A raise InvalidOptionError(InvalidOptionError.INCOMPAT,
2875N/A [SUMMARY, VERBOSE])
2875N/A
2893N/A if opts_new[QUIET] and opts_new[VERBOSE]:
2893N/A raise InvalidOptionError(InvalidOptionError.INCOMPAT,
2893N/A [QUIET, VERBOSE])
2893N/A
2875N/Adef opts_cb_int(k, api_inst, opts, opts_new, minimum=None):
2875N/A
2875N/A if k not in opts or opts[k] == None:
2875N/A err = _("missing required parameter")
2875N/A raise InvalidOptionError(msg=err, options=[k])
2875N/A
2875N/A # get the original argument value
2875N/A v = opts[k]
2875N/A
2875N/A # make sure it is an integer
2875N/A try:
2875N/A v = int(v)
2875N/A except (ValueError, TypeError):
2875N/A # not a valid integer
2875N/A err = _("value '%s' invalid") % (v)
2875N/A raise InvalidOptionError(msg=err, options=[k])
2875N/A
2875N/A # check the minimum bounds
2875N/A if minimum is not None and v < minimum:
2875N/A err = _("value must be >= %d") % (minimum)
2875N/A raise InvalidOptionError(msg=err, options=[k])
2875N/A
2875N/A # update the new options array to make the value an integer
2875N/A opts_new[k] = v
2875N/A
2875N/Adef opts_cb_fd(k, api_inst, opts, opts_new):
2875N/A opts_cb_int(k, api_inst, opts, opts_new, minimum=0)
2875N/A
2875N/A err = _("value '%s' invalid") % (opts_new[k])
2875N/A try:
2875N/A os.fstat(opts_new[k])
2875N/A except OSError:
2875N/A # not a valid file descriptor
2875N/A raise InvalidOptionError(msg=err, options=[k])
2875N/A
2875N/Adef opts_table_cb_concurrency(api_inst, opts, opts_new):
2875N/A if opts[CONCURRENCY] is None:
2875N/A # remove concurrency from parameters dict
2875N/A del opts_new[CONCURRENCY]
2875N/A return
2875N/A
2875N/A # make sure we have an integer
2875N/A opts_cb_int(CONCURRENCY, api_inst, opts, opts_new)
2875N/A
2875N/A # update global concurrency setting
2875N/A global_settings.client_concurrency = opts_new[CONCURRENCY]
2896N/A global_settings.client_concurrency_set = True
2875N/A
2875N/A # remove concurrency from parameters dict
2875N/A del opts_new[CONCURRENCY]
2875N/A
2875N/A#
2875N/A# options common to multiple pkg(1) operations. The format for specifying
2875N/A# options is a list which can contain:
2875N/A#
2875N/A# - Tuples formatted as:
2875N/A# (k, v)
2875N/A# where the values are:
2875N/A# k: the key value for the options dictionary
2875N/A# v: the default value. valid values are: True/False, None, [], 0
2875N/A#
2875N/A
2875N/A
2875N/Aopts_table_beopts = [
2875N/A opts_table_cb_beopts,
2875N/A (BACKUP_BE_NAME, None),
2875N/A (BE_NAME, None),
2875N/A (DENY_NEW_BE, False),
2875N/A (NO_BACKUP_BE, False),
2875N/A (BE_ACTIVATE, True),
2875N/A (REQUIRE_BACKUP_BE, False),
2875N/A (REQUIRE_NEW_BE, False),
2875N/A]
2875N/A
2875N/Aopts_table_concurrency = [
2875N/A opts_table_cb_concurrency,
2875N/A (CONCURRENCY, None),
2875N/A]
2875N/A
2875N/Aopts_table_force = [
2875N/A (FORCE, False),
2875N/A]
2875N/A
2875N/Aopts_table_li_ignore = [
2875N/A opts_table_cb_li_ignore,
2875N/A (LI_IGNORE_ALL, False),
2875N/A (LI_IGNORE_LIST, []),
2875N/A]
2875N/A
2875N/Aopts_table_li_md_only = [
2875N/A opts_table_cb_md_only,
2875N/A (LI_MD_ONLY, False),
2875N/A]
2875N/A
2875N/Aopts_table_li_no_pkg_updates = [
2875N/A (LI_PKG_UPDATES, True),
2875N/A]
2875N/A
2875N/Aopts_table_li_no_psync = [
2875N/A opts_table_cb_li_no_psync,
2875N/A (LI_PARENT_SYNC, True),
2875N/A]
2875N/A
2875N/Aopts_table_li_props = [
2875N/A opts_table_cb_li_props,
2875N/A (LI_PROPS, []),
2875N/A]
2875N/A
2875N/Aopts_table_li_target = [
2875N/A opts_table_cb_li_target,
2875N/A (LI_TARGET_ALL, False),
2875N/A (LI_TARGET_LIST, []),
2875N/A]
2875N/A
2875N/Aopts_table_li_target1 = [
2875N/A opts_table_cb_li_target1,
2875N/A (LI_NAME, None),
2875N/A]
2875N/A
2875N/Aopts_table_licenses = [
2875N/A (ACCEPT, False),
2875N/A (SHOW_LICENSES, False),
2875N/A]
2875N/A
2875N/Aopts_table_no_headers = [
2875N/A opts_table_cb_no_headers_vs_quiet,
2875N/A (OMIT_HEADERS, False),
2875N/A]
2875N/A
2875N/Aopts_table_no_index = [
2875N/A (UPDATE_INDEX, True),
2875N/A]
2875N/A
2875N/Aopts_table_no_refresh = [
2875N/A (REFRESH_CATALOGS, True),
2875N/A]
2875N/A
2875N/Aopts_table_reject = [
2875N/A (REJECT_PATS, []),
2875N/A]
2875N/A
2875N/Aopts_table_verbose = [
2875N/A opts_table_cb_v,
2875N/A (VERBOSE, 0),
2875N/A]
2875N/A
2875N/Aopts_table_quiet = [
2875N/A opts_table_cb_q,
2875N/A (QUIET, False),
2875N/A]
2875N/A
2875N/Aopts_table_parsable = [
2875N/A opts_table_cb_parsable,
2875N/A (PARSABLE_VERSION, None),
2875N/A]
2875N/A
2875N/Aopts_table_nqv = \
2875N/A opts_table_quiet + \
2875N/A opts_table_verbose + \
2875N/A [
2875N/A opts_table_cb_nqv,
2875N/A (NOEXECUTE, False),
2875N/A]
2875N/A
2875N/Aopts_table_origins = [
2875N/A opts_table_cb_origins,
2875N/A (ORIGINS, []),
2875N/A]
2875N/A
2875N/Aopts_table_stage = [
2875N/A opts_table_cb_stage,
2875N/A (STAGE, None),
2875N/A]
2875N/A
2875N/A#
2875N/A# Options for pkg(1) subcommands. Built by combining the option tables above,
2875N/A# with some optional subcommand unique options defined below.
2875N/A#
2875N/Aopts_install = \
2875N/A opts_table_beopts + \
2875N/A opts_table_concurrency + \
2875N/A opts_table_li_ignore + \
2875N/A opts_table_li_no_psync + \
2875N/A opts_table_licenses + \
2875N/A opts_table_reject + \
2875N/A opts_table_no_index + \
2875N/A opts_table_no_refresh + \
2875N/A opts_table_nqv + \
2875N/A opts_table_parsable + \
2875N/A opts_table_origins + \
2875N/A []
2875N/A
2875N/A# "update" cmd inherits all "install" cmd options
2875N/Aopts_update = \
2875N/A opts_install + \
2875N/A opts_table_force + \
2875N/A opts_table_stage + \
2875N/A []
2875N/A
2875N/A# "attach-linked" cmd inherits all "install" cmd options
2875N/Aopts_attach_linked = \
2875N/A opts_install + \
2875N/A opts_table_force + \
2875N/A opts_table_li_md_only + \
2875N/A opts_table_li_no_pkg_updates + \
2875N/A opts_table_li_props + \
2875N/A [
2875N/A opts_cb_li_attach,
2875N/A (ALLOW_RELINK, False),
2875N/A (ATTACH_CHILD, False),
2875N/A (ATTACH_PARENT, False),
2875N/A]
2875N/A
2875N/Aopts_revert = \
2875N/A opts_table_beopts + \
2875N/A opts_table_nqv + \
2875N/A opts_table_parsable + \
2875N/A [
2875N/A (TAGGED, False),
2875N/A]
2875N/A
2875N/Aopts_set_mediator = \
2875N/A opts_table_beopts + \
2875N/A opts_table_no_index + \
2875N/A opts_table_nqv + \
2875N/A opts_table_parsable + \
2875N/A [
2875N/A (MED_IMPLEMENTATION, None),
2875N/A (MED_VERSION, None)
2875N/A]
2875N/A
2875N/A# "set-property-linked" cmd inherits all "install" cmd options
2875N/Aopts_set_property_linked = \
2875N/A opts_install + \
2875N/A opts_table_li_md_only + \
2875N/A opts_table_li_no_pkg_updates + \
2875N/A opts_table_li_target1 + \
2875N/A []
2875N/A
2875N/A# "sync-linked" cmd inherits all "install" cmd options
2875N/Aopts_sync_linked = \
2875N/A opts_install + \
2875N/A opts_table_li_md_only + \
2875N/A opts_table_li_no_pkg_updates + \
2875N/A opts_table_li_target + \
2875N/A opts_table_stage + \
2875N/A []
2875N/A
2875N/Aopts_uninstall = \
2875N/A opts_table_beopts + \
2875N/A opts_table_concurrency + \
2875N/A opts_table_li_ignore + \
2925N/A opts_table_li_no_psync + \
2875N/A opts_table_no_index + \
2875N/A opts_table_nqv + \
2875N/A opts_table_parsable + \
2875N/A opts_table_stage
2875N/A
2875N/Aopts_audit_linked = \
2875N/A opts_table_li_no_psync + \
2875N/A opts_table_li_target + \
2875N/A opts_table_no_headers + \
2875N/A opts_table_quiet + \
2875N/A []
2875N/A
2875N/Aopts_detach_linked = \
2875N/A opts_table_force + \
2925N/A opts_table_li_md_only + \
2925N/A opts_table_li_no_pkg_updates + \
2875N/A opts_table_li_target + \
2875N/A opts_table_nqv + \
2875N/A []
2875N/A
2875N/Aopts_list_linked = \
2875N/A opts_table_li_ignore + \
2875N/A opts_table_no_headers + \
2875N/A []
2875N/A
2875N/Aopts_list_property_linked = \
2875N/A opts_table_li_target1 + \
2875N/A opts_table_no_headers + \
2875N/A []
2875N/A
2875N/Aopts_list_inventory = \
2875N/A opts_table_li_no_psync + \
2875N/A opts_table_no_refresh + \
2875N/A opts_table_no_headers + \
2875N/A opts_table_origins + \
2893N/A opts_table_quiet + \
2875N/A opts_table_verbose + \
2875N/A [
2875N/A opts_cb_list,
2875N/A (LIST_INSTALLED_NEWEST, False),
2875N/A (LIST_ALL, False),
2875N/A (LIST_NEWEST, False),
2875N/A (SUMMARY, False),
2875N/A (LIST_UPGRADABLE, False),
2875N/A]
2875N/A
2875N/Apkg_op_opts = {
2875N/A
2875N/A pkgdefs.PKG_OP_ATTACH : opts_attach_linked,
2875N/A pkgdefs.PKG_OP_AUDIT_LINKED : opts_audit_linked,
2875N/A pkgdefs.PKG_OP_CHANGE_FACET : opts_install,
2875N/A pkgdefs.PKG_OP_CHANGE_VARIANT : opts_install,
2875N/A pkgdefs.PKG_OP_DETACH : opts_detach_linked,
2875N/A pkgdefs.PKG_OP_INSTALL : opts_install,
2875N/A pkgdefs.PKG_OP_LIST : opts_list_inventory,
2875N/A pkgdefs.PKG_OP_LIST_LINKED : opts_list_linked,
2875N/A pkgdefs.PKG_OP_PROP_LINKED : opts_list_property_linked,
2875N/A pkgdefs.PKG_OP_PUBCHECK : [],
2875N/A pkgdefs.PKG_OP_REVERT : opts_revert,
2875N/A pkgdefs.PKG_OP_SET_MEDIATOR : opts_set_mediator,
2875N/A pkgdefs.PKG_OP_SET_PROP_LINKED: opts_set_property_linked,
2875N/A pkgdefs.PKG_OP_SYNC : opts_sync_linked,
2875N/A pkgdefs.PKG_OP_UNINSTALL : opts_uninstall,
2875N/A pkgdefs.PKG_OP_UPDATE : opts_update
2875N/A}
2875N/A
2875N/Adef get_pkg_opts(op, add_table=None):
2875N/A """Get the available options for a particular operation specified by
2875N/A 'op'. If the client uses custom pkg_op_opts tables they can be specified
2875N/A by 'add_table'."""
2875N/A
2875N/A popts = pkg_op_opts.copy()
2875N/A if add_table is not None:
2875N/A popts.update(add_table)
2875N/A
2875N/A try:
2875N/A opts = popts[op]
2875N/A except KeyError:
2875N/A opts = None
2875N/A return opts
2875N/A
2875N/Adef get_pkg_opts_defaults(op, opt, add_table=None):
2875N/A """ Get the default value for a certain option 'opt' of a certain
2875N/A operation 'op'. This is useful for clients which toggle boolean options.
2875N/A """
2875N/A popts = get_pkg_opts(op, add_table)
2875N/A
2875N/A for o in popts:
2875N/A if type(o) != tuple:
2875N/A continue
2875N/A opt_name, default = o
2875N/A if opt_name == opt:
2875N/A return default
2875N/A
2875N/Adef opts_assemble(op, api_inst, opts, add_table=None, cwd=None):
2875N/A """Assembly of the options for a specific operation. Options are read in
2875N/A from a dict (see explanation below) and sanity tested.
2875N/A
2875N/A This is the common interface to supply options to the functions of the
2875N/A API.
2875N/A
2875N/A 'op' is the operation for which the options need to be assembled and
2875N/A verified. The currently supported operations are listed in
2875N/A pkgdefs.pkg_op_values.
2875N/A
2875N/A 'api_inst' is a reference to the API instance, required for some of the
2875N/A verification steps.
2875N/A
2875N/A 'opts' is the raw options table to be processed. It needs to be a dict
2875N/A in the format: { option_name: argument, ... }
2875N/A """
2875N/A
2875N/A global _orig_cwd
2875N/A
2875N/A if cwd is not None:
2875N/A _orig_cwd = cwd
2875N/A else:
2875N/A _orig_cwd = None
2875N/A
2875N/A popts = get_pkg_opts(op, add_table)
2875N/A
2875N/A rv = {}
2875N/A callbacks = []
2875N/A
2875N/A for o in popts:
2875N/A if type(o) != tuple:
2875N/A callbacks.append(o)
2875N/A continue
2875N/A
2875N/A avail_opt, default = o
2875N/A # for options not given we substitue the default value
2875N/A if avail_opt not in opts:
2875N/A rv[avail_opt] = default
2875N/A continue
2875N/A
2875N/A if type(default) == int:
2875N/A assert type(opts[avail_opt]) == int, opts[avail_opt]
2875N/A elif type(default) == list:
2875N/A assert type(opts[avail_opt]) == list, opts[avail_opt]
2875N/A elif type(default) == bool:
2875N/A assert type(opts[avail_opt]) == bool, opts[avail_opt]
2875N/A
2875N/A rv[avail_opt] = opts[avail_opt]
2875N/A
2875N/A rv_updated = rv.copy()
2875N/A
2875N/A # run the option verification callbacks
2875N/A for cb in callbacks:
2875N/A cb(api_inst, rv, rv_updated)
2875N/A
2875N/A return rv_updated
2875N/A