Exemple #1
0
def doParseArgs(star):
    parser = argparse.ArgumentParser(
        epilog=
        "For help about each option, specify --help after the option itself.\nFor complete documentation please refer to https://alisw.github.io/alibuild"
    )

    parser.add_argument("-d",
                        "--debug",
                        dest="debug",
                        action="store_true",
                        default=False,
                        help="Enable debug log output")
    parser.add_argument(
        "-n",
        "--dry-run",
        dest="dryRun",
        default=False,
        action="store_true",
        help="Prints what would happen, without actually doing it.")

    subparsers = parser.add_subparsers(dest='action')
    analytics_parser = subparsers.add_parser("analytics",
                                             help="turn on / off analytics")
    architecture_parser = subparsers.add_parser(
        "architecture", help="display detected architecture")
    build_parser = subparsers.add_parser("build", help="build a package")
    clean_parser = subparsers.add_parser("clean", help="cleanup build area")
    deps_parser = subparsers.add_parser(
        "deps", help="generate a dependency graph for a given package")
    doctor_parser = subparsers.add_parser("doctor",
                                          help="verify status of your system")
    init_parser = subparsers.add_parser("init",
                                        help="initialise local packages")
    version_parser = subparsers.add_parser("version",
                                           help="display %(prog)s version")

    # Options for the analytics command
    analytics_parser.add_argument("state",
                                  choices=["on", "off"],
                                  help="Whether to report analytics or not")

    # Options for the build command
    build_parser.add_argument(
        "pkgname",
        nargs="+",
        help="One (or more) of the packages in `alidist'")

    build_parser.add_argument("--config-dir",
                              "-c",
                              dest="configDir",
                              default="%%(prefix)s%sdist" % star)
    build_parser.add_argument(
        "--no-local",
        dest="noDevel",
        default="",
        type=csv_list,
        help="Do not pick up the following packages from a local checkout.")
    build_parser.add_argument("--docker",
                              dest="docker",
                              action="store_true",
                              default=False)
    build_parser.add_argument(
        "--docker-image",
        dest="dockerImage",
        default=argparse.SUPPRESS,
        help="Image to use in case you build with docker (implies --docker)")
    build_parser.add_argument("--work-dir",
                              "-w",
                              dest="workDir",
                              default=DEFAULT_WORK_DIR)
    build_parser.add_argument("--architecture",
                              "-a",
                              dest="architecture",
                              default=detectArch())
    build_parser.add_argument("-e",
                              dest="environment",
                              action='append',
                              default=[])
    build_parser.add_argument("-v",
                              dest="volumes",
                              action='append',
                              default=[],
                              help="Specify volumes to be used in Docker")
    build_parser.add_argument("--jobs",
                              "-j",
                              dest="jobs",
                              type=int,
                              default=detectJobs())
    build_parser.add_argument("--reference-sources",
                              dest="referenceSources",
                              default="%(workDir)s/MIRROR")
    build_parser.add_argument(
        "--remote-store",
        dest="remoteStore",
        default="",
        help="Where to find packages already built for reuse."
        "Use ssh:// in front for remote store. End with ::rw if you want to upload."
    )
    build_parser.add_argument(
        "--write-store",
        dest="writeStore",
        default="",
        help="Where to upload the built packages for reuse."
        "Use ssh:// in front for remote store.")
    build_parser.add_argument(
        "--disable",
        dest="disable",
        default=[],
        metavar="PACKAGE",
        action="append",
        help="Do not build PACKAGE and all its (unique) dependencies.")
    build_parser.add_argument("--defaults",
                              dest="defaults",
                              default="release",
                              metavar="FILE",
                              help="Specify which defaults to use")
    build_parser.add_argument("--force-unknown-architecture",
                              dest="forceUnknownArch",
                              default=False,
                              action="store_true",
                              help="Do not check for valid architecture")
    build_parser.add_argument("--insecure",
                              dest="insecure",
                              default=False,
                              action="store_true",
                              help="Do not check for valid certificates")
    build_parser.add_argument("--aggressive-cleanup",
                              dest="aggressiveCleanup",
                              default=False,
                              action="store_true",
                              help="Perform additional cleanups")
    build_parser.add_argument("--chdir",
                              "-C",
                              help="Change to the specified directory first",
                              metavar="DIR",
                              dest="chdir",
                              default=DEFAULT_CHDIR)
    build_parser.add_argument(
        "--no-auto-cleanup",
        help="Do not cleanup build by products automatically",
        dest="autoCleanup",
        action="store_false",
        default=True)
    build_parser.add_argument(
        "--devel-prefix",
        "-z",
        nargs="?",
        help=
        "Version name to use for development packages. Defaults to branch name.",
        dest="develPrefix",
        default=argparse.SUPPRESS)
    build_parser.add_argument("--fetch-repos",
                              "-u",
                              dest="fetchRepos",
                              default=False,
                              action="store_true",
                              help="Fetch repository updates")

    group = build_parser.add_mutually_exclusive_group()
    group.add_argument("--always-prefer-system",
                       dest="preferSystem",
                       default=False,
                       action="store_true",
                       help="Always use system packages when compatible")
    group.add_argument("--no-system",
                       dest="noSystem",
                       default=False,
                       action="store_true",
                       help="Never use system packages")

    # Options for clean subcommand
    clean_parser.add_argument("--architecture",
                              "-a",
                              dest="architecture",
                              default=detectArch())
    clean_parser.add_argument("--force-unknown-architecture",
                              dest="forceUnknownArch",
                              default=False,
                              action="store_true",
                              help="Do not check for valid architecture")
    clean_parser.add_argument("--work-dir",
                              "-w",
                              dest="workDir",
                              default=DEFAULT_WORK_DIR)
    clean_parser.add_argument("--aggressive-cleanup",
                              dest="aggressiveCleanup",
                              default=False,
                              action="store_true",
                              help="Perform additional cleanups")
    clean_parser.add_argument(
        "--disable",
        dest="disable",
        default=[],
        metavar="PACKAGE",
        action="append",
        help="Do not build PACKAGE and all its (unique) dependencies.")
    clean_parser.add_argument("--reference-sources",
                              dest="referenceSources",
                              default="%(workDir)s/MIRROR")
    clean_parser.add_argument("--chdir",
                              "-C",
                              help="Change to the specified directory first",
                              metavar="DIR",
                              dest="chdir",
                              default=DEFAULT_CHDIR)

    # Options for the deps subcommand
    deps_parser = depsArgsParser(deps_parser)

    # Options for the doctor subcommand
    doctor_parser = doctorArgParser(doctor_parser)

    # Options for the init subcommand
    init_parser.add_argument("pkgname",
                             nargs="?",
                             default="",
                             help="One (or more) of the packages in `alidist'")
    init_parser.add_argument("--architecture",
                             "-a",
                             dest="architecture",
                             default=detectArch())
    init_parser.add_argument("--work-dir",
                             "-w",
                             dest="workDir",
                             default=DEFAULT_WORK_DIR)
    init_parser.add_argument(
        "--devel-prefix",
        "-z",
        nargs="?",
        default=".",
        help=
        "Version name to use for development packages. Defaults to branch name.",
        dest="develPrefix")
    init_parser.add_argument("--config-dir",
                             "-c",
                             dest="configDir",
                             default="%%(prefix)s%sdist" % star)
    init_parser.add_argument("--reference-sources",
                             dest="referenceSources",
                             default="%(workDir)s/MIRROR")
    init_parser.add_argument(
        "--dist",
        dest="dist",
        default="",
        type=lambda x: alidist_string(x, star),
        help=
        "Prepare development mode by downloading the given recipes set ([user/repo@]branch)"
    )
    init_parser.add_argument("--defaults",
                             dest="defaults",
                             default="release",
                             metavar="FILE",
                             help="Specify which defaults to use")
    init_parser.add_argument("--chdir",
                             "-C",
                             help="Change to the specified directory first",
                             metavar="DIR",
                             dest="chdir",
                             default=DEFAULT_CHDIR)

    # Options for the version subcommand
    version_parser.add_argument("--architecture",
                                "-a",
                                dest="architecture",
                                default=detectArch())

    # Make sure old option ordering behavior is actually still working
    prog = sys.argv[0]
    rest = sys.argv[1:]

    def optionOrder(x):
        if x in ["--debug", "-d", "-n", "--dry-run"]:
            return 0
        if x in ["build", "init", "clean", "analytics", "doctor", "deps"]:
            return 1
        return 2

    rest.sort(key=optionOrder)
    sys.argv = [prog] + rest
    args = finaliseArgs(parser.parse_args(), parser, star)
    return (args, parser)
Exemple #2
0
def doParseArgs(star):
  parser = argparse.ArgumentParser(epilog="For help about each option, specify --help after the option itself.\nFor complete documentation please refer to https://alisw.github.io/alibuild")

  parser.add_argument("-d", "--debug", dest="debug", action="store_true", default=False, help="Enable debug log output")
  parser.add_argument("-n", "--dry-run", dest="dryRun", default=False,
                      action="store_true", help="Prints what would happen, without actually doing it.")

  subparsers = parser.add_subparsers(dest='action')
  analytics_parser = subparsers.add_parser("analytics", help="turn on / off analytics")
  architecture_parser = subparsers.add_parser("architecture", help="display detected architecture")
  build_parser = subparsers.add_parser("build", help="build a package")
  clean_parser = subparsers.add_parser("clean", help="cleanup build area")
  deps_parser = subparsers.add_parser("deps", help="generate a dependency graph for a given package")
  doctor_parser = subparsers.add_parser("doctor", help="verify status of your system")
  init_parser = subparsers.add_parser("init", help="initialise local packages")
  version_parser = subparsers.add_parser("version", help="display %(prog)s version")

  # Options for the analytics command
  analytics_parser.add_argument("state", choices=["on", "off"], help="Whether to report analytics or not")

  # Options for the build command
  build_parser.add_argument("pkgname", nargs="+", help="One (or more) of the packages in `alidist'")

  build_parser.add_argument("--config-dir", "-c", dest="configDir", default="%%(prefix)s%sdist" % star)
  build_parser.add_argument("--no-local", dest="noDevel", default="", type=csv_list,
                      help="Do not pick up the following packages from a local checkout.")
  build_parser.add_argument("--docker", dest="docker", action="store_true", default=False)
  build_parser.add_argument("--docker-image", dest="dockerImage", default=argparse.SUPPRESS,
                            help="Image to use in case you build with docker (implies --docker)")
  build_parser.add_argument("--work-dir", "-w", dest="workDir", default=DEFAULT_WORK_DIR)
  build_parser.add_argument("--architecture", "-a", dest="architecture",
                      default=detectArch())
  build_parser.add_argument("-e", dest="environment", action='append', default=[])
  build_parser.add_argument("-v", dest="volumes", action='append', default=[],
                      help="Specify volumes to be used in Docker")
  build_parser.add_argument("--jobs", "-j", dest="jobs", type=int, default=detectJobs())
  build_parser.add_argument("--reference-sources", dest="referenceSources", default="%(workDir)s/MIRROR")
  build_parser.add_argument("--remote-store", dest="remoteStore", default="",
                            help="Where to find packages already built for reuse."
                                 "Use ssh:// in front for remote store. End with ::rw if you want to upload.")
  build_parser.add_argument("--write-store", dest="writeStore", default="",
                            help="Where to upload the built packages for reuse."
                                 "Use ssh:// in front for remote store.")
  build_parser.add_argument("--disable", dest="disable", default=[],
                            metavar="PACKAGE", action="append",
                            help="Do not build PACKAGE and all its (unique) dependencies.")
  build_parser.add_argument("--defaults", dest="defaults", default="release",
                            metavar="FILE", help="Specify which defaults to use")
  build_parser.add_argument("--force-unknown-architecture", dest="forceUnknownArch", default=False,
                            action="store_true", help="Do not check for valid architecture")
  build_parser.add_argument("--insecure", dest="insecure", default=False,
                            action="store_true", help="Do not check for valid certificates")
  build_parser.add_argument("--aggressive-cleanup", dest="aggressiveCleanup", default=False,
                            action="store_true", help="Perform additional cleanups")
  build_parser.add_argument("--chdir", "-C", help="Change to the specified directory first",
                            metavar="DIR", dest="chdir", default=DEFAULT_CHDIR)
  build_parser.add_argument("--no-auto-cleanup", help="Do not cleanup build by products automatically",
                      dest="autoCleanup", action="store_false", default=True)
  build_parser.add_argument("--devel-prefix", "-z", nargs="?", help="Version name to use for development packages. Defaults to branch name.",
                      dest="develPrefix", default=argparse.SUPPRESS)
  build_parser.add_argument("--fetch-repos", "-u", dest="fetchRepos", default=False,
                            action="store_true", help="Fetch repository updates")

  group = build_parser.add_mutually_exclusive_group()
  group.add_argument("--always-prefer-system", dest="preferSystem", default=False,
                     action="store_true", help="Always use system packages when compatible")
  group.add_argument("--no-system", dest="noSystem", default=False,
                     action="store_true", help="Never use system packages")

  # Options for clean subcommand
  clean_parser.add_argument("--architecture", "-a", dest="architecture",
                            default=detectArch())
  clean_parser.add_argument("--force-unknown-architecture", dest="forceUnknownArch", default=False,
                            action="store_true", help="Do not check for valid architecture")
  clean_parser.add_argument("--work-dir", "-w", dest="workDir", default=DEFAULT_WORK_DIR)
  clean_parser.add_argument("--aggressive-cleanup", dest="aggressiveCleanup", default=False,
                            action="store_true", help="Perform additional cleanups")
  clean_parser.add_argument("--disable", dest="disable", default=[],
                            metavar="PACKAGE", action="append",
                            help="Do not build PACKAGE and all its (unique) dependencies.")
  clean_parser.add_argument("--reference-sources", dest="referenceSources", default="%(workDir)s/MIRROR")
  clean_parser.add_argument("--chdir", "-C", help="Change to the specified directory first",
                            metavar="DIR", dest="chdir", default=DEFAULT_CHDIR)

  # Options for the deps subcommand
  deps_parser = depsArgsParser(deps_parser)

  # Options for the doctor subcommand
  doctor_parser = doctorArgParser(doctor_parser)

  # Options for the init subcommand
  init_parser.add_argument("pkgname", nargs="?", default="", help="One (or more) of the packages in `alidist'")
  init_parser.add_argument("--architecture", "-a", dest="architecture",
                            default=detectArch())
  init_parser.add_argument("--work-dir", "-w", dest="workDir", default=DEFAULT_WORK_DIR)
  init_parser.add_argument("--devel-prefix", "-z", nargs="?", default=".", help="Version name to use for development packages. Defaults to branch name.",
                           dest="develPrefix")
  init_parser.add_argument("--config-dir", "-c", dest="configDir", default="%%(prefix)s%sdist" % star)
  init_parser.add_argument("--reference-sources", dest="referenceSources", default="%(workDir)s/MIRROR")
  init_parser.add_argument("--dist", dest="dist", default="", type=lambda x : alidist_string(x, star),
                           help="Prepare development mode by downloading the given recipes set ([user/repo@]branch)")
  init_parser.add_argument("--defaults", dest="defaults", default="release",
                            metavar="FILE", help="Specify which defaults to use")
  init_parser.add_argument("--chdir", "-C", help="Change to the specified directory first",
                           metavar="DIR", dest="chdir", default=DEFAULT_CHDIR)

  # Options for the version subcommand
  version_parser.add_argument("--architecture", "-a", dest="architecture",
                      default=detectArch())

  # Make sure old option ordering behavior is actually still working
  prog = sys.argv[0]
  rest = sys.argv[1:]
  def optionOrder(x):
    if x in ["--debug", "-d", "-n", "--dry-run"]:
      return 0
    if x in ["build", "init", "clean", "analytics", "doctor", "deps"]:
      return 1
    return 2
  rest.sort(key=optionOrder)
  sys.argv = [prog] + rest
  args = finaliseArgs(parser.parse_args(), parser, star)
  return (args, parser)