예제 #1
0
파일: options.py 프로젝트: oetiker/pkg5
def opts_table_cb_md_only(api_inst, opts, opts_new):
    # if the user didn't specify linked-md-only we're done
    if not opts[LI_MD_ONLY]:
        return

    # li_md_only implies no li_pkg_updates
    if LI_PKG_UPDATES in opts:
        opts_new[LI_PKG_UPDATES] = False

    #
    # if li_md_only is false that means we're not updating any packages
    # within the current image so there are a ton of options that no
    # longer apply to the current operation, and hence are incompatible
    # with li_md_only.
    #
    arg1 = LI_MD_ONLY
    if BE_NAME in opts and opts[BE_NAME]:
        raise InvalidOptionError(InvalidOptionError.INCOMPAT, [arg1, BE_NAME])
    if DENY_NEW_BE in opts and opts[DENY_NEW_BE]:
        raise InvalidOptionError(InvalidOptionError.INCOMPAT,
                                 [arg1, DENY_NEW_BE])
    if REQUIRE_NEW_BE in opts and opts[REQUIRE_NEW_BE]:
        raise InvalidOptionError(InvalidOptionError.INCOMPAT,
                                 [arg1, REQUIRE_NEW_BE])
    if LI_PARENT_SYNC in opts and not opts[LI_PARENT_SYNC]:
        raise InvalidOptionError(InvalidOptionError.REQUIRED,
                                 [arg1, LI_PARENT_SYNC])
    if REJECT_PATS in opts and opts[REJECT_PATS]:
        raise InvalidOptionError(InvalidOptionError.INCOMPAT,
                                 [arg1, REJECT_PATS])
예제 #2
0
파일: options.py 프로젝트: oetiker/pkg5
def __parse_linked_props(args):
    """"Parse linked image property options that were specified on the
        command line into a dictionary.  Make sure duplicate properties were
        not specified."""

    linked_props = dict()
    for pv in args:
        try:
            p, v = pv.split("=", 1)
        except ValueError:
            raise InvalidOptionError(
                msg=_("linked image "
                      "property arguments must be of the form "
                      "'<name>=<value>'."))

        if p not in li.prop_values:
            raise InvalidOptionError(msg=_("invalid linked "
                                           "image property: '{0}'.").format(p))

        if p in linked_props:
            raise InvalidOptionError(
                msg=_("linked image "
                      "property specified multiple times: "
                      "'{0}'.").format(p))

        linked_props[p] = v

    return linked_props
예제 #3
0
파일: options.py 프로젝트: oetiker/pkg5
def opts_table_cb_li_recurse(api_inst, opts, opts_new):

    del opts_new[LI_ERECURSE_INCL]
    del opts_new[LI_ERECURSE_EXCL]
    del opts_new[LI_ERECURSE_ALL]

    if opts[LI_ERECURSE_EXCL] and not opts[LI_ERECURSE_ALL]:
        raise InvalidOptionError(InvalidOptionError.REQUIRED,
                                 [LI_ERECURSE_EXCL, LI_ERECURSE_ALL])

    if opts[LI_ERECURSE_INCL] and not opts[LI_ERECURSE_ALL]:
        raise InvalidOptionError(InvalidOptionError.REQUIRED,
                                 [LI_ERECURSE_INCL, LI_ERECURSE_ALL])

    if opts[LI_ERECURSE_INCL] and opts[LI_ERECURSE_EXCL]:
        raise InvalidOptionError(InvalidOptionError.INCOMPAT,
                                 [LI_ERECURSE_INCL, LI_ERECURSE_EXCL])

    if not opts[LI_ERECURSE_ALL]:
        opts_new[LI_ERECURSE] = None
        return

    # Go through all children and check if they are in the recurse list.
    li_child_targets = []
    li_child_list = set(
        [lin for lin, rel, path in api_inst.list_linked() if rel == "child"])

    def parse_lin(ulin):
        lin = None
        try:
            lin = api_inst.parse_linked_name(ulin, allow_unknown=True)
        except LinkedImageException as e:
            try:
                lin = api_inst.parse_linked_name("zone:{0}".format(ulin),
                                                 allow_unknown=True)
            except LinkedImageException as e:
                pass
        if lin is None or lin not in li_child_list:
            raise InvalidOptionError(msg=_("invalid linked image or zone name "
                                           "'{0}'.").format(ulin))

        return lin

    if opts[LI_ERECURSE_INCL]:
        # include list specified
        for ulin in opts[LI_ERECURSE_INCL]:
            li_child_targets.append(parse_lin(ulin))
        opts_new[LI_ERECURSE] = li_child_targets
    else:
        # exclude list specified
        for ulin in opts[LI_ERECURSE_EXCL]:
            li_child_list.remove(parse_lin(ulin))
        opts_new[LI_ERECURSE] = li_child_list

    # If we use image recursion we need to make sure uninstall and update
    # ignore non-existing packages in the parent image.
    if opts_new[LI_ERECURSE] and IGNORE_MISSING in opts:
        opts_new[IGNORE_MISSING] = True
예제 #4
0
파일: options.py 프로젝트: oetiker/pkg5
def opts_table_cb_pub_search(api_inst, opts, opts_new):
    if opts[SEARCH_BEFORE] and opts[SEARCH_AFTER]:
        raise InvalidOptionError(InvalidOptionError.INCOMPAT,
                                 [SEARCH_BEFORE, SEARCH_AFTER])

    if opts[SEARCH_BEFORE] and opts[SEARCH_FIRST]:
        raise InvalidOptionError(InvalidOptionError.INCOMPAT,
                                 [SEARCH_BEFORE, SEARCH_FIRST])

    if opts[SEARCH_AFTER] and opts[SEARCH_FIRST]:
        raise InvalidOptionError(InvalidOptionError.INCOMPAT,
                                 [SEARCH_AFTER, SEARCH_FIRST])
예제 #5
0
파일: options.py 프로젝트: oetiker/pkg5
def opts_table_cb_parsable(api_inst, opts, opts_new):
    if opts[PARSABLE_VERSION] and opts.get(VERBOSE, False):
        raise InvalidOptionError(InvalidOptionError.INCOMPAT,
                                 [VERBOSE, PARSABLE_VERSION])
    if opts[PARSABLE_VERSION]:
        try:
            opts_new[PARSABLE_VERSION] = int(opts[PARSABLE_VERSION])
        except ValueError:
            raise InvalidOptionError(options=[PARSABLE_VERSION],
                                     msg=_("integer argument expected"))

        global_settings.client_output_parsable_version = \
            opts_new[PARSABLE_VERSION]
        opts_new[QUIET] = True
        global_settings.client_output_quiet = True
예제 #6
0
def opts_table_cb_li_ignore(api_inst, opts, opts_new):

        # synthesize li_ignore_all and li_ignore_list into li_ignore
        del opts_new[LI_IGNORE_ALL]
        del opts_new[LI_IGNORE_LIST]
        opts_new[LI_IGNORE] = None

        # check if there's nothing to ignore
        if not opts[LI_IGNORE_ALL] and not opts[LI_IGNORE_LIST]:
                return

        if opts[LI_IGNORE_ALL]:

                # can't ignore all and specific images
                if opts[LI_IGNORE_LIST]:
                        raise InvalidOptionError(InvalidOptionError.INCOMPAT,
                            [LI_IGNORE_ALL, LI_IGNORE_LIST])

                # can't ignore all and target anything.
                if LI_TARGET_ALL in opts and opts[LI_TARGET_ALL]:
                        raise InvalidOptionError(InvalidOptionError.INCOMPAT,
                            [LI_IGNORE_ALL, LI_TARGET_ALL])
                if LI_TARGET_LIST in opts and opts[LI_TARGET_LIST]:
                        raise InvalidOptionError(InvalidOptionError.INCOMPAT,
                            [LI_IGNORE_ALL, LI_TARGET_LIST])
                if LI_NAME in opts and opts[LI_NAME]:
                        raise InvalidOptionError(InvalidOptionError.INCOMPAT,
                            [LI_IGNORE_ALL, LI_NAME])
                opts_new[LI_IGNORE] = []
                return

        assert opts[LI_IGNORE_LIST]

        # it doesn't make sense to specify images to ignore if the
        # user is already specifying images to operate on.
        if LI_TARGET_ALL in opts and opts[LI_TARGET_ALL]:
                raise InvalidOptionError(InvalidOptionError.INCOMPAT,
                    [LI_IGNORE_LIST, LI_TARGET_ALL])
        if LI_TARGET_LIST in opts and opts[LI_TARGET_LIST]:
                raise InvalidOptionError(InvalidOptionError.INCOMPAT,
                    [LI_IGNORE_LIST, LI_TARGET_LIST])
        if LI_NAME in opts and opts[LI_NAME]:
                raise InvalidOptionError(InvalidOptionError.INCOMPAT,
                    [LI_IGNORE_LIST, LI_NAME])

        li_ignore = []
        for li_name in opts[LI_IGNORE_LIST]:
                # check for repeats
                if li_name in li_ignore:
                        raise InvalidOptionError(
                            InvalidOptionError.ARG_REPEAT, [li_name,
                            LI_IGNORE_LIST])
                # add to ignore list
                li_ignore.append(li_name)

        opts_new[LI_IGNORE] = api_inst.parse_linked_name_list(li_ignore)
예제 #7
0
파일: options.py 프로젝트: oetiker/pkg5
def opts_table_cb_stage(api_inst, opts, opts_new):
    if opts[STAGE] == None:
        opts_new[STAGE] = pkgdefs.API_STAGE_DEFAULT
        return

    if opts_new[STAGE] not in pkgdefs.api_stage_values:
        raise InvalidOptionError(msg=_("invalid operation stage: "
                                       "'{0}'").format(opts[STAGE]))
예제 #8
0
파일: options.py 프로젝트: oetiker/pkg5
def opts_table_cb_li_no_psync(api_inst, opts, opts_new):
    # if a target child linked image was specified, the no-parent-sync
    # option doesn't make sense since we know that both the parent and
    # child image are accessible

    if LI_TARGET_ALL not in opts:
        # we don't accept linked image target options
        assert LI_TARGET_LIST not in opts
        return

    if opts[LI_TARGET_ALL] and not opts[LI_PARENT_SYNC]:
        raise InvalidOptionError(InvalidOptionError.REQUIRED,
                                 [LI_TARGET_ALL, LI_PARENT_SYNC])

    if opts[LI_TARGET_LIST] and not opts[LI_PARENT_SYNC]:
        raise InvalidOptionError(InvalidOptionError.REQUIRED,
                                 [LI_TARGET_LIST, LI_PARENT_SYNC])
예제 #9
0
파일: options.py 프로젝트: oetiker/pkg5
def opts_cb_fd(k, api_inst, opts, opts_new):
    opts_cb_int(k, api_inst, opts, opts_new, minimum=0)

    err = _("value '{0}' invalid").format(opts_new[k])
    try:
        os.fstat(opts_new[k])
    except OSError:
        # not a valid file descriptor
        raise InvalidOptionError(msg=err, options=[k])
예제 #10
0
파일: options.py 프로젝트: oetiker/pkg5
def opts_cb_li_attach(api_inst, opts, opts_new):
    if opts[ATTACH_PARENT] and opts[ATTACH_CHILD]:
        raise InvalidOptionError(InvalidOptionError.INCOMPAT,
                                 [ATTACH_PARENT, ATTACH_CHILD])

    if not opts[ATTACH_PARENT] and not opts[ATTACH_CHILD]:
        raise InvalidOptionError(InvalidOptionError.XOR,
                                 [ATTACH_PARENT, ATTACH_CHILD])

    if opts[ATTACH_CHILD]:
        # if we're attaching a new child then that doesn't affect
        # any other children, so ignoring them doesn't make sense.
        if opts[LI_IGNORE_ALL]:
            raise InvalidOptionError(InvalidOptionError.INCOMPAT,
                                     [ATTACH_CHILD, LI_IGNORE_ALL])
        if opts[LI_IGNORE_LIST]:
            raise InvalidOptionError(InvalidOptionError.INCOMPAT,
                                     [ATTACH_CHILD, LI_IGNORE_LIST])
예제 #11
0
def __parse_set_props(args):
        """"Parse set property options that were specified on the command
        line into a dictionary.  Make sure duplicate properties were not
        specified."""

        set_props = dict()
        for pv in args:
                try:
                        p, v = pv.split("=", 1)
                except ValueError:
                        raise InvalidOptionError(msg=_("properties to be set "
                            "must be of the form '<name>=<value>'. This is "
                            "what was given: {0}").format(pv))

                if p in set_props:
                        raise InvalidOptionError(msg=_("a property may only "
                            "be set once in a command. {0} was set twice"
                            ).format(p))
                set_props[p] = v

        return set_props
예제 #12
0
파일: options.py 프로젝트: oetiker/pkg5
def opts_cb_list(api_inst, opts, opts_new):
    if opts_new[ORIGINS] and opts_new[LIST_UPGRADABLE]:
        raise InvalidOptionError(InvalidOptionError.INCOMPAT,
                                 [ORIGINS, LIST_UPGRADABLE])

    if opts_new[ORIGINS] and not opts_new[LIST_NEWEST]:
        # Use of -g implies -a unless -n is provided.
        opts_new[LIST_INSTALLED_NEWEST] = True

    if opts_new[LIST_ALL] and not opts_new[LIST_INSTALLED_NEWEST]:
        raise InvalidOptionError(InvalidOptionError.REQUIRED,
                                 [LIST_ALL, LIST_INSTALLED_NEWEST])

    if opts_new[LIST_INSTALLED_NEWEST] and opts_new[LIST_NEWEST]:
        raise InvalidOptionError(InvalidOptionError.INCOMPAT,
                                 [LIST_INSTALLED_NEWEST, LIST_NEWEST])

    if opts_new[LIST_INSTALLED_NEWEST] and opts_new[LIST_UPGRADABLE]:
        raise InvalidOptionError(InvalidOptionError.INCOMPAT,
                                 [LIST_INSTALLED_NEWEST, LIST_UPGRADABLE])

    if opts_new[SUMMARY] and opts_new[VERBOSE]:
        raise InvalidOptionError(InvalidOptionError.INCOMPAT,
                                 [SUMMARY, VERBOSE])

    if opts_new[QUIET] and opts_new[VERBOSE]:
        raise InvalidOptionError(InvalidOptionError.INCOMPAT, [QUIET, VERBOSE])
예제 #13
0
def opts_table_cb_li_target1(api_inst, opts, opts_new):
        # figure out which option the user specified
        if opts[LI_NAME]:
                arg1 = LI_NAME
        else:
                return

        if BE_ACTIVATE in opts and not opts[BE_ACTIVATE]:
                raise InvalidOptionError(InvalidOptionError.REQUIRED,
                    [arg1, BE_ACTIVATE])
        if BE_NAME in opts and opts[BE_NAME]:
                raise InvalidOptionError(InvalidOptionError.INCOMPAT,
                    [arg1, BE_NAME])
        if DENY_NEW_BE in opts and opts[DENY_NEW_BE]:
                raise InvalidOptionError(InvalidOptionError.INCOMPAT,
                    [arg1, DENY_NEW_BE])
        if REQUIRE_NEW_BE in opts and opts[REQUIRE_NEW_BE]:
                raise InvalidOptionError(InvalidOptionError.INCOMPAT,
                    [arg1, REQUIRE_NEW_BE])
        if REJECT_PATS in opts and opts[REJECT_PATS]:
                raise InvalidOptionError(InvalidOptionError.INCOMPAT,
                    [arg1, REJECT_PATS])
        if ORIGINS in opts and opts[ORIGINS]:
                raise InvalidOptionError(InvalidOptionError.INCOMPAT,
                    [arg1, ORIGINS])
예제 #14
0
파일: options.py 프로젝트: oetiker/pkg5
def opts_table_cb_info(api_inst, opts, opts_new):
    opts_new[ORIGINS] = set()
    for e in opts[ORIGINS]:
        opts_new[ORIGINS].add(misc.parse_uri(e, cwd=_orig_cwd))
    if opts[ORIGINS]:
        opts_new[INFO_REMOTE] = True
    if opts[QUIET]:
        global_settings.client_output_quiet = True
    if not opts_new[INFO_LOCAL] and not opts_new[INFO_REMOTE]:
        opts_new[INFO_LOCAL] = True
    elif opts_new[INFO_LOCAL] and opts_new[INFO_REMOTE]:
        raise InvalidOptionError(InvalidOptionError.INCOMPAT,
                                 [INFO_LOCAL, INFO_REMOTE])
예제 #15
0
파일: options.py 프로젝트: oetiker/pkg5
def opts_table_cb_beopts(api_inst, opts, opts_new):

    # synthesize require_new_be and deny_new_be into new_be
    del opts_new[REQUIRE_NEW_BE]
    del opts_new[DENY_NEW_BE]
    opts_new[NEW_BE] = None

    if (opts[BE_NAME] or opts[REQUIRE_NEW_BE]) and opts[DENY_NEW_BE]:
        raise InvalidOptionError(InvalidOptionError.INCOMPAT,
                                 [REQUIRE_NEW_BE, DENY_NEW_BE])

    # create a new key called BACKUP_BE in the options array
    if opts[REQUIRE_NEW_BE] or opts[BE_NAME]:
        opts_new[NEW_BE] = True
    if opts[DENY_NEW_BE]:
        opts_new[NEW_BE] = False

    # synthesize require_backup_be and no_backup_be into backup_be
    del opts_new[REQUIRE_BACKUP_BE]
    del opts_new[NO_BACKUP_BE]
    opts_new[BACKUP_BE] = None

    if (opts[REQUIRE_BACKUP_BE] or opts[BACKUP_BE_NAME]) and \
        opts[NO_BACKUP_BE]:
        raise InvalidOptionError(InvalidOptionError.INCOMPAT,
                                 [REQUIRE_BACKUP_BE, NO_BACKUP_BE])

    if (opts[REQUIRE_BACKUP_BE] or opts[BACKUP_BE_NAME]) and \
        (opts[REQUIRE_NEW_BE] or opts[BE_NAME]):
        raise InvalidOptionError(InvalidOptionError.INCOMPAT,
                                 [REQUIRE_BACKUP_BE, REQUIRE_NEW_BE])

    # create a new key called BACKUP_BE in the options array
    if opts[REQUIRE_BACKUP_BE] or opts[BACKUP_BE_NAME]:
        opts_new[BACKUP_BE] = True
    if opts[NO_BACKUP_BE]:
        opts_new[BACKUP_BE] = False
예제 #16
0
파일: options.py 프로젝트: oetiker/pkg5
def opts_cb_int(k, api_inst, opts, opts_new, minimum=None):

    if k not in opts or opts[k] == None:
        err = _("missing required parameter")
        raise InvalidOptionError(msg=err, options=[k])

    # get the original argument value
    v = opts[k]

    # make sure it is an integer
    try:
        v = int(v)
    except (ValueError, TypeError):
        # not a valid integer
        err = _("value '{0}' invalid").format(v)
        raise InvalidOptionError(msg=err, options=[k])

    # check the minimum bounds
    if minimum is not None and v < minimum:
        err = _("value must be >= {0:d}").format(minimum)
        raise InvalidOptionError(msg=err, options=[k])

    # update the new options array to make the value an integer
    opts_new[k] = v
예제 #17
0
파일: options.py 프로젝트: oetiker/pkg5
    def parse_lin(ulin):
        lin = None
        try:
            lin = api_inst.parse_linked_name(ulin, allow_unknown=True)
        except LinkedImageException as e:
            try:
                lin = api_inst.parse_linked_name("zone:{0}".format(ulin),
                                                 allow_unknown=True)
            except LinkedImageException as e:
                pass
        if lin is None or lin not in li_child_list:
            raise InvalidOptionError(msg=_("invalid linked image or zone name "
                                           "'{0}'.").format(ulin))

        return lin
예제 #18
0
def opts_table_cb_li_target(api_inst, opts, opts_new):
        # figure out which option the user specified
        if opts[LI_TARGET_ALL] and opts[LI_TARGET_LIST]:
                raise InvalidOptionError(InvalidOptionError.INCOMPAT,
                    [LI_TARGET_ALL, LI_TARGET_LIST])
        elif opts[LI_TARGET_ALL]:
                arg1 = LI_TARGET_ALL
        elif opts[LI_TARGET_LIST]:
                arg1 = LI_TARGET_LIST
        else:
                return

        if BE_ACTIVATE in opts and not opts[BE_ACTIVATE]:
                raise InvalidOptionError(InvalidOptionError.REQUIRED,
                    [arg1, BE_ACTIVATE])
        if BE_NAME in opts and opts[BE_NAME]:
                raise InvalidOptionError(InvalidOptionError.INCOMPAT,
                    [arg1, BE_NAME])
        if DENY_NEW_BE in opts and opts[DENY_NEW_BE]:
                raise InvalidOptionError(InvalidOptionError.INCOMPAT,
                    [arg1, DENY_NEW_BE])
        if REQUIRE_NEW_BE in opts and opts[REQUIRE_NEW_BE]:
                raise InvalidOptionError(InvalidOptionError.INCOMPAT,
                    [arg1, REQUIRE_NEW_BE])
        if REJECT_PATS in opts and opts[REJECT_PATS]:
                raise InvalidOptionError(InvalidOptionError.INCOMPAT,
                    [arg1, REJECT_PATS])
        if ORIGINS in opts and opts[ORIGINS]:
                raise InvalidOptionError(InvalidOptionError.INCOMPAT,
                    [arg1, ORIGINS])

        # validate linked image name
        li_target_list = []
        for li_name in opts[LI_TARGET_LIST]:
                # check for repeats
                if li_name in li_target_list:
                        raise InvalidOptionError(
                            InvalidOptionError.ARG_REPEAT, [li_name,
                            LI_TARGET_LIST])
                # add to ignore list
                li_target_list.append(li_name)

        opts_new[LI_TARGET_LIST] = \
            api_inst.parse_linked_name_list(li_target_list)
예제 #19
0
파일: options.py 프로젝트: oetiker/pkg5
def __parse_prop_values(args, add=True):
    """"Parse add or remove property values options that were specified
        on the command line into a dictionary.  Make sure duplicate properties
        were not specified."""

    props_values = dict()
    if add:
        add_txt = "added"
    else:
        add_txt = "removed"

    for pv in args:
        try:
            p, v = pv.split("=", 1)
        except ValueError:
            raise InvalidOptionError(msg=_(
                "property values to be "
                "{add} must be of the form '<name>=<value>'. "
                "This is what was given: {key}").format(add=add_txt, key=pv))

        props_values.setdefault(p, [])
        props_values[p].append(v)

    return props_values
예제 #20
0
파일: options.py 프로젝트: oetiker/pkg5
def opts_table_cb_nqv(api_inst, opts, opts_new):
    if opts[VERBOSE] and opts[QUIET]:
        raise InvalidOptionError(InvalidOptionError.INCOMPAT, [VERBOSE, QUIET])
예제 #21
0
파일: options.py 프로젝트: oetiker/pkg5
def opts_assemble(op, api_inst, opts, add_table=None, cwd=None):
    """Assembly of the options for a specific operation. Options are read in
        from a dict (see explanation below) and sanity tested.

        This is the common interface to supply options to the functions of the
        API.

        'op' is the operation for which the options need to be assembled and
        verified. The currently supported operations are listed in
        pkgdefs.pkg_op_values.

        'api_inst' is a reference to the API instance, required for some of the
        verification steps.

        'opts' is the raw options table to be processed. It needs to be a dict
        in the format: { option_name: argument, ... }
        """

    global _orig_cwd

    if cwd is not None:
        _orig_cwd = cwd
    else:
        _orig_cwd = None

    popts = get_pkg_opts(op, add_table)

    rv = {}
    callbacks = []

    for o in popts:
        if type(o) != tuple:
            callbacks.append(o)
            continue
        valid_args = []
        # If no valid argument list specified.
        if len(o) == 2:
            avail_opt, default = o
        elif len(o) == 3:
            avail_opt, default, valid_args = o
        elif len(o) == 4:
            avail_opt, default, valid_args, schema = o
        # for options not given we substitue the default value
        if avail_opt not in opts:
            rv[avail_opt] = default
            continue

        if type(default) == int:
            assert type(opts[avail_opt]) == int, opts[avail_opt]
        elif type(default) == list:
            assert type(opts[avail_opt]) == list, opts[avail_opt]
        elif type(default) == bool:
            assert type(opts[avail_opt]) == bool, opts[avail_opt]

        if valid_args:
            assert type(default) == list or default is None, \
                default
            raise_error = False
            if type(opts[avail_opt]) == list:
                if not set(opts[avail_opt]).issubset(set(valid_args)):
                    raise_error = True
            else:
                if opts[avail_opt] not in valid_args:
                    raise_error = True
            if raise_error:
                raise InvalidOptionError(InvalidOptionError.ARG_INVALID,
                                         [opts[avail_opt], avail_opt],
                                         valid_args=valid_args)

        rv[avail_opt] = opts[avail_opt]

    rv_updated = rv.copy()

    # run the option verification callbacks
    for cb in callbacks:
        cb(api_inst, rv, rv_updated)

    return rv_updated
예제 #22
0
파일: options.py 프로젝트: oetiker/pkg5
def opts_table_cb_pub_opts(api_inst, opts, opts_new):
    del opts_new[PUB_DISABLE]
    del opts_new[PUB_ENABLE]
    del opts_new[PUB_STICKY]
    del opts_new[PUB_NON_STICKY]

    if opts[PUB_DISABLE] and opts[PUB_ENABLE]:
        raise InvalidOptionError(InvalidOptionError.INCOMPAT,
                                 [PUB_DISABLE, PUB_ENABLE])

    if opts[PUB_STICKY] and opts[PUB_NON_STICKY]:
        raise InvalidOptionError(InvalidOptionError.INCOMPAT,
                                 [PUB_STICKY, PUB_NON_STICKY])

    opts_new[PUB_DISABLE] = None
    if opts[PUB_DISABLE]:
        opts_new[PUB_DISABLE] = True

    if opts[PUB_ENABLE]:
        opts_new[PUB_DISABLE] = False

    opts_new[PUB_STICKY] = None
    if opts[PUB_STICKY]:
        opts_new[PUB_STICKY] = True

    if opts[PUB_NON_STICKY]:
        opts_new[PUB_STICKY] = False

    if opts[ORIGIN_URI] and opts[ADD_ORIGINS]:
        raise InvalidOptionError(InvalidOptionError.INCOMPAT,
                                 [ORIGIN_URI, ADD_ORIGINS])

    if opts[ORIGIN_URI] and opts[REMOVE_ORIGINS]:
        raise InvalidOptionError(InvalidOptionError.INCOMPAT,
                                 [ORIGIN_URI, REMOVE_ORIGINS])

    if opts[REPO_URI] and opts[ADD_ORIGINS]:
        raise InvalidOptionError(InvalidOptionError.INCOMPAT,
                                 [REPO_URI, ADD_ORIGINS])
    if opts[REPO_URI] and opts[ADD_MIRRORS]:
        raise InvalidOptionError(InvalidOptionError.INCOMPAT,
                                 [REPO_URI, ADD_MIRRORS])
    if opts[REPO_URI] and opts[REMOVE_ORIGINS]:
        raise InvalidOptionError(InvalidOptionError.INCOMPAT,
                                 [REPO_URI, REMOVE_ORIGINS])
    if opts[REPO_URI] and opts[REMOVE_MIRRORS]:
        raise InvalidOptionError(InvalidOptionError.INCOMPAT,
                                 [REPO_URI, REMOVE_MIRRORS])
    if opts[REPO_URI] and opts[PUB_DISABLE]:
        raise InvalidOptionError(InvalidOptionError.INCOMPAT,
                                 [REPO_URI, PUB_DISABLE])
    if opts[REPO_URI] and opts[PUB_ENABLE]:
        raise InvalidOptionError(InvalidOptionError.INCOMPAT,
                                 [REPO_URI, PUB_ENABLE])
    if opts[REPO_URI] and not opts[REFRESH_ALLOWED]:
        raise InvalidOptionError(InvalidOptionError.REQUIRED,
                                 [REPO_URI, REFRESH_ALLOWED])
    if opts[REPO_URI] and opts[RESET_UUID]:
        raise InvalidOptionError(InvalidOptionError.INCOMPAT,
                                 [REPO_URI, RESET_UUID])

    if opts[PROXY_URI] and not (opts[ADD_ORIGINS] or opts[ADD_MIRRORS]
                                or opts[REPO_URI] or opts[REMOVE_ORIGINS]
                                or opts[REMOVE_MIRRORS]):
        raise InvalidOptionError(InvalidOptionError.REQUIRED_ANY, [
            PROXY_URI, ADD_ORIGINS, ADD_MIRRORS, REMOVE_ORIGINS,
            REMOVE_MIRRORS, REPO_URI
        ])

    opts_new[ADD_ORIGINS] = set()
    opts_new[REMOVE_ORIGINS] = set()
    opts_new[ADD_MIRRORS] = set()
    opts_new[REMOVE_MIRRORS] = set()
    for e in opts[ADD_ORIGINS]:
        opts_new[ADD_ORIGINS].add(misc.parse_uri(e, cwd=_orig_cwd))
    for e in opts[REMOVE_ORIGINS]:
        if e == "*":
            # Allow wildcard to support an easy, scriptable
            # way of removing all existing entries.
            opts_new[REMOVE_ORIGINS].add("*")
        else:
            opts_new[REMOVE_ORIGINS].add(misc.parse_uri(e, cwd=_orig_cwd))

    for e in opts[ADD_MIRRORS]:
        opts_new[ADD_MIRRORS].add(misc.parse_uri(e, cwd=_orig_cwd))
    for e in opts[REMOVE_MIRRORS]:
        if e == "*":
            # Allow wildcard to support an easy, scriptable
            # way of removing all existing entries.
            opts_new[REMOVE_MIRRORS].add("*")
        else:
            opts_new[REMOVE_MIRRORS].add(misc.parse_uri(e, cwd=_orig_cwd))

    if opts[REPO_URI]:
        opts_new[REPO_URI] = misc.parse_uri(opts[REPO_URI], cwd=_orig_cwd)