Example #1
0
def cli_set_rpm_macro(session: ClientSession,
                      tagname: Union[int, str],
                      macro: str,
                      value: Optional[str] = None,
                      remove: bool = False,
                      block: bool = False,
                      target: bool = False):
    """
    If remove is True, value and block are ignored. The setting will
    be removed from the tag's extra settings.

    If block is True, value is ignored. A block entry will be added to
    the tag's extra settings.

    If remove and block are both False, then the value will be
    assigned to the tag's extra settings.

    If target is True, then tagname is actually the name of a target.
    That target's build tag will be the tag that is therefore
    modified.
    """

    taginfo = resolve_tag(session, tagname, target)

    if macro.startswith("rpm.macro."):
        key = macro
        macro = macro[10:]
    elif macro.startswith("%"):
        macro = macro.lstrip("%")
        key = "rpm.macro." + macro
    else:
        key = "rpm.macro." + macro

    if remove:
        if key not in taginfo["extra"]:
            raise NoSuchMacro(macro)

        session.editTag2(taginfo["id"], remove_extra=[key])

    elif block:
        version_require(session, (1, 23), "block tag extra values")
        session.editTag2(taginfo["id"], block_extra=[key])

    else:
        # converts to numbers, True, False, and None as applicable
        value = arg_filter(value)

        # an empty string breaks mock and RPM, make it %nil instead.  RPM
        # macros are not allowed to have an empty body. None is treated as
        # the string "None" so we leave that alone.
        if value == '':
            value = "%nil"

        session.editTag2(taginfo["id"], extra={key: value})
Example #2
0
def cli_set_env_var(session: ClientSession,
                    tagname: Union[int, str],
                    var: str,
                    value: Optional[str] = None,
                    remove: bool = False,
                    block: bool = False,
                    target: bool = False):
    """
    If remove is True, value and block are ignored. The setting will
    be removed from the tag's extra settings.

    If block is True, value is ignored. A block entry will be added to
    the tag's extra settings.

    If remove and block are both False, then the value will be
    assigned to the tag's extra settings.

    If target is True, then tagname is actually the name of a target.
    That target's build tag will be the tag that is therefore
    modified.
    """

    taginfo = resolve_tag(session, tagname, target)

    if var.startswith("rpm.env."):
        key = var
        var = var[8:]
    else:
        key = "rpm.env." + var

    if remove:
        if key not in taginfo["extra"]:
            raise NoSuchEnvVar(var)

        session.editTag2(taginfo["id"], remove_extra=[key])

    elif block:
        version_require(session, (1, 23), "block tag extra values")
        session.editTag2(taginfo["id"], block_extra=[key])

    else:
        session.editTag2(taginfo["id"], extra={key: value})