Exemplo n.º 1
0
def parse_arguments(options, args, flatpak):
    "Build a container"
    if flatpak:
        usage = _("usage: %prog flatpak-build [options] target <scm url>")
    else:
        usage = _("usage: %prog container-build [options] target <scm url or "
                  "archive path>")
    usage += _("\n(Specify the --help global option for a list of other help "
               "options)")
    parser = OptionParser(usage=usage)
    parser.add_option("--scratch",
                      action="store_true",
                      help=_("Perform a scratch build"))
    if not flatpak:
        parser.add_option("--isolated",
                          action="store_true",
                          help=_("Perform an isolated build"))
    parser.add_option("--arch-override",
                      help=_(
                          "Requires --scratch or --isolated. Limit a build to "
                          "the specified arches. Comma or space separated."))
    parser.add_option("--wait",
                      action="store_true",
                      help=_("Wait on the build, even if running in the "
                             "background"))
    parser.add_option("--nowait",
                      action="store_false",
                      dest="wait",
                      help=_("Don't wait on build"))
    parser.add_option("--quiet",
                      action="store_true",
                      help=_("Do not print the task information"),
                      default=options.quiet)
    parser.add_option("--background",
                      action="store_true",
                      help=_("Run the build at a lower priority"))
    parser.add_option(
        "--replace-dependency",
        dest='dependency_replacements',
        metavar="pkg_manager:name:version[:new_name]",
        action='append',
        help=_("Cachito dependency replacement. May be used multiple times."))
    parser.add_option(
        "--repo-url",
        dest='yum_repourls',
        metavar="REPO_URL",
        action='append',
        help=_("URL of yum repo file. May be used multiple times."))
    parser.add_option("--git-branch",
                      metavar="GIT_BRANCH",
                      help=_("Git branch"))
    parser.add_option("--channel-override",
                      help=_("Use a non-standard channel [default: %default]"),
                      default=DEFAULT_CHANNEL)
    parser.add_option(
        "--signing-intent",
        help=_("Signing intent of the ODCS composes [default: %default]."
               " Cannot be used with --compose-id"),
        default=None,
        dest='signing_intent')
    parser.add_option(
        "--compose-id",
        help=_("ODCS composes used. May be used multiple times. Cannot be"
               " used with --signing-intent"),
        dest='compose_ids',
        action='append',
        metavar="COMPOSE_ID",
        type="int")
    parser.add_option("--skip-build",
                      action="store_true",
                      help=_("Skip build and update buildconfig. "
                             "Use this option to update autorebuild settings"))
    parser.add_option(
        "--userdata",
        help=_("JSON dictionary of user defined custom metadata"))
    parser.add_option(
        "--operator-csv-modifications-url",
        help=_("URL to JSON file with operator CSV modification"),
        action='store',
        default=None,
        dest='operator_csv_modifications_url',
        metavar='URL',
    )

    if not flatpak:
        parser.add_option("--release", help=_("Set release value"))
        parser.add_option(
            "--koji-parent-build",
            help=_("Overwrite parent image with image from koji build"))
    build_opts, args = parser.parse_args(args)
    if len(args) != 2:
        parser.error(
            _("Exactly two arguments (a build target and a SCM URL) "
              "are required"))
        assert False

    source = args[1]
    if '://' not in source:
        parser.error(
            _("scm URL does not look like an URL to a source repository"))
    if '#' not in source:
        parser.error(
            _("scm URL must be of the form <url_to_repository>#<revision>)"))

    if build_opts.arch_override and not (build_opts.scratch
                                         or build_opts.isolated):
        parser.error(
            _("--arch-override is only allowed for --scratch or --isolated builds"
              ))

    if build_opts.signing_intent and build_opts.compose_ids:
        parser.error(_("--signing-intent cannot be used with --compose-id"))

    if build_opts.operator_csv_modifications_url and not build_opts.isolated:
        parser.error(
            _("Only --isolated builds support option --operator-csv-modifications-url"
              ))

    if (build_opts.operator_csv_modifications_url
            and '://' not in build_opts.operator_csv_modifications_url):
        parser.error(
            _("Value provided to --operator-csv-modifications-url "
              "does not look like an URL"))

    opts = {}
    if not build_opts.git_branch:
        parser.error(_("git-branch must be specified"))

    keys = ('scratch', 'yum_repourls', 'git_branch', 'signing_intent',
            'compose_ids', 'skip_build', 'userdata', 'dependency_replacements',
            'operator_csv_modifications_url')

    if flatpak:
        opts['flatpak'] = True
    else:
        if build_opts.isolated and build_opts.scratch:
            parser.error(_("Build cannot be both isolated and scratch"))

        keys += ('release', 'isolated', 'koji_parent_build')

    if build_opts.arch_override:
        opts['arch_override'] = parse_arches(build_opts.arch_override)

    for key in keys:
        val = getattr(build_opts, key)
        if val is not None:
            opts[key] = val
            if key == 'userdata':
                opts[key] = json.loads(val)

    # create the parser in this function and return it to
    # simplify the unit test cases
    return build_opts, args, opts, parser
def parse_arguments(options, args, flatpak):
    "Build a container"
    if flatpak:
        usage = _("usage: %prog flatpak-build [options] target <scm url>")
    else:
        usage = _("usage: %prog container-build [options] target <scm url or "
                  "archive path>")
    usage += _("\n(Specify the --help global option for a list of other help "
               "options)")
    parser = OptionParser(usage=usage)
    parser.add_option("--scratch",
                      action="store_true",
                      help=_("Perform a scratch build"))
    if not flatpak:
        parser.add_option("--isolated",
                          action="store_true",
                          help=_("Perform an isolated build"))
    parser.add_option("--arch-override",
                      help=_(
                          "Requires --scratch. Limit a scratch build to "
                          "the specified arches. Comma or space separated."))
    parser.add_option("--wait",
                      action="store_true",
                      help=_("Wait on the build, even if running in the "
                             "background"))
    parser.add_option("--nowait",
                      action="store_false",
                      dest="wait",
                      help=_("Don't wait on build"))
    parser.add_option("--quiet",
                      action="store_true",
                      help=_("Do not print the task information"),
                      default=options.quiet)
    parser.add_option("--background",
                      action="store_true",
                      help=_("Run the build at a lower priority"))
    parser.add_option("--epoch",
                      help=_("Specify container epoch. Requires koji admin "
                             "permission."))
    parser.add_option("--repo-url",
                      dest='yum_repourls',
                      metavar="REPO_URL",
                      action='append',
                      help=_("URL of yum repo file. May be used multiple "
                             "times. Cannot be used with --compose-id"))
    parser.add_option("--git-branch",
                      metavar="GIT_BRANCH",
                      help=_("Git branch"))
    parser.add_option("--channel-override",
                      help=_("Use a non-standard channel [default: %default]"),
                      default=DEFAULT_CHANNEL)
    parser.add_option(
        "--signing-intent",
        help=_("Signing intent of the ODCS composes [default: %default]."
               " Cannot be used with --compose-id"),
        default=None,
        dest='signing_intent')
    parser.add_option(
        "--compose-id",
        help=_("ODCS composes used. May be used multiple times. Cannot be"
               " used with --signing-intent or --repo-url"),
        dest='compose_ids',
        action='append',
        metavar="COMPOSE_ID",
        type="int")
    if not flatpak:
        parser.add_option("--release", help=_("Set release value"))
        parser.add_option(
            "--koji-parent-build",
            help=_("Overwrite parent image with image from koji build"))
    build_opts, args = parser.parse_args(args)
    if len(args) != 2:
        parser.error(
            _("Exactly two arguments (a build target and a SCM URL) "
              "are required"))
        assert False

    if build_opts.arch_override and not (build_opts.scratch
                                         or build_opts.isolated):
        parser.error(
            _("--arch-override is only allowed for --scratch or --isolated builds"
              ))

    if build_opts.signing_intent and build_opts.compose_ids:
        parser.error(_("--signing-intent cannot be used with --compose-id"))

    if build_opts.compose_ids and build_opts.yum_repourls:
        parser.error(_("--compose-id cannot be used with --repo-url"))

    opts = {}
    if not build_opts.git_branch:
        parser.error(_("git-branch must be specified"))

    keys = ('scratch', 'epoch', 'yum_repourls', 'git_branch', 'signing_intent',
            'compose_ids')

    if flatpak:
        opts['flatpak'] = True
    else:
        if build_opts.isolated and build_opts.scratch:
            parser.error(_("Build cannot be both isolated and scratch"))

        keys += ('release', 'isolated', 'koji_parent_build')

    if build_opts.arch_override:
        opts['arch_override'] = parse_arches(build_opts.arch_override)

    for key in keys:
        val = getattr(build_opts, key)
        if val is not None:
            opts[key] = val
    # create the parser in this function and return it to
    # simplify the unit test cases
    return build_opts, args, opts, parser
def parse_arguments(options, args, flatpak):
    "Build a container"
    if flatpak:
        usage = _("usage: %prog flatpak-build [options] target <scm url>")
    else:
        usage = _("usage: %prog container-build [options] target <scm url or "
                  "archive path>")
    usage += _("\n(Specify the --help global option for a list of other help "
               "options)")
    parser = OptionParser(usage=usage)
    parser.add_option("--scratch", action="store_true",
                      help=_("Perform a scratch build"))
    if not flatpak:
        parser.add_option("--isolated", action="store_true",
                          help=_("Perform an isolated build"))
    parser.add_option("--arch-override",
                      help=_("Requires --scratch. Limit a scratch build to "
                             "the specified arches. Comma or space separated."))
    parser.add_option("--wait", action="store_true",
                      help=_("Wait on the build, even if running in the "
                             "background"))
    parser.add_option("--nowait", action="store_false", dest="wait",
                      help=_("Don't wait on build"))
    parser.add_option("--quiet", action="store_true",
                      help=_("Do not print the task information"),
                      default=options.quiet)
    parser.add_option("--background", action="store_true",
                      help=_("Run the build at a lower priority"))
    parser.add_option("--epoch",
                      help=_("Specify container epoch. Requires koji admin "
                             "permission."))
    parser.add_option("--repo-url", dest='yum_repourls', metavar="REPO_URL",
                      action='append',
                      help=_("URL of yum repo file. May be used multiple times."))
    parser.add_option("--git-branch", metavar="GIT_BRANCH",
                      help=_("Git branch"))
    parser.add_option("--channel-override",
                      help=_("Use a non-standard channel [default: %default]"),
                      default=DEFAULT_CHANNEL)
    parser.add_option("--signing-intent",
                      help=_("Signing intent of the ODCS composes [default: %default]."
                             " Cannot be used with --compose-id"),
                      default=None, dest='signing_intent')
    parser.add_option("--compose-id",
                      help=_("ODCS composes used. May be used multiple times. Cannot be"
                             " used with --signing-intent"),
                      dest='compose_ids', action='append', metavar="COMPOSE_ID", type="int")
    if not flatpak:
        parser.add_option("--release",
                          help=_("Set release value"))
        parser.add_option("--koji-parent-build",
                          help=_("Overwrite parent image with image from koji build"))
    build_opts, args = parser.parse_args(args)
    if len(args) != 2:
        parser.error(_("Exactly two arguments (a build target and a SCM URL) "
                       "are required"))
        assert False

    if build_opts.arch_override and not (build_opts.scratch or build_opts.isolated):
        parser.error(_("--arch-override is only allowed for --scratch or --isolated builds"))

    if build_opts.signing_intent and build_opts.compose_ids:
        parser.error(_("--signing-intent cannot be used with --compose-id"))

    opts = {}
    if not build_opts.git_branch:
        parser.error(_("git-branch must be specified"))

    keys = ('scratch', 'epoch', 'yum_repourls', 'git_branch', 'signing_intent', 'compose_ids')

    if flatpak:
        opts['flatpak'] = True
    else:
        if build_opts.isolated and build_opts.scratch:
            parser.error(_("Build cannot be both isolated and scratch"))

        keys += ('release', 'isolated', 'koji_parent_build')

    if build_opts.arch_override:
        opts['arch_override'] = parse_arches(build_opts.arch_override)

    for key in keys:
        val = getattr(build_opts, key)
        if val is not None:
            opts[key] = val
    # create the parser in this function and return it to
    # simplify the unit test cases
    return build_opts, args, opts, parser