def doctorArgParser(parser): parser.add_argument("-a", "--architecture", help="force architecture", dest="architecture", default=detectArch()) parser.add_argument("-c", "--config", help="path to alidist", dest="configDir", default="alidist") parser.add_argument("-w", "--work-dir", help="path to work dir", dest="workDir", default="workDir") parser.add_argument("--defaults", default="release", dest="defaults", help="Specify default to use") parser.add_argument( "--disable", dest="disable", default=[], metavar="PACKAGE", action="append", help="Do not build PACKAGE and all its (unique) dependencies.") parser.add_argument("--always-prefer-system", dest="preferSystem", default=False, action="store_true", help="Always use system packages when compatible") parser.add_argument("--no-system", dest="noSystem", default=False, action="store_true", help="Never use system packages") parser.add_argument("packages", nargs="+", help="Package to test", default=[]) parser.add_argument("--docker", dest="docker", action="store_true", default=False) parser.add_argument( "--docker-image", dest="dockerImage", help= "Image to use in case you build with docker (implies --docker-image)") parser.add_argument("--chdir", "-C", help="Change to the specified directory first", metavar="DIR", dest="chdir", default=os.environ.get("ALIBUILD_CHDIR", ".")) return parser
def depsArgsParser(parser): parser.add_argument("topPackage") parser.add_argument("-a", "--architecture", help="force architecture", dest="architecture", default=detectArch()) parser.add_argument("--dist", dest="distDir", default="alidist", help="Recipes directory") parser.add_argument("--output-file", "-o", dest="outFile", default="dist.pdf", help="Output file (PDF format)") parser.add_argument("--debug", "-d", dest="debug", action="store_true", default=False, help="Debug output") parser.add_argument("--build-requires", "-b", dest="buildRequires", action="store_true", default=False, help="Debug output") parser.add_argument("--neat", dest="neat", action="store_true", default=False, help="Neat graph with transitive reduction") parser.add_argument("--disable", dest="disable", default=[], help="List of packages to ignore") parser.add_argument("--chdir", "-C", help="Change to the specified directory first", metavar="DIR", dest="chdir", default=os.environ.get("ALIBUILD_CHDIR", ".")) return parser
def depsArgsParser(parser): parser.add_argument("topPackage") parser.add_argument("-a", "--architecture", help="force architecture", dest="architecture", default=detectArch()) parser.add_argument("--dist", dest="distDir", default="alidist", help="Recipes directory") parser.add_argument("--output-file", "-o", dest="outFile", default="dist.pdf", help="Output file (PDF format)") parser.add_argument("--debug", "-d", dest="debug", action="store_true", default=False, help="Debug output") parser.add_argument("--build-requires", "-b", dest="buildRequires", action="store_true", default=False, help="Debug output") parser.add_argument("--neat", dest="neat", action="store_true", default=False, help="Neat graph with transitive reduction") parser.add_argument("--disable", dest="disable", default=[], help="List of packages to ignore") parser.add_argument("--chdir", "-C", help="Change to the specified directory first", metavar="DIR", dest="chdir", default=os.environ.get("ALIBUILD_CHDIR", ".")) return parser
def doctorArgParser(parser): parser.add_argument("-a", "--architecture", help="force architecture", dest="architecture", default=detectArch()) parser.add_argument("-c", "--config", help="path to alidist", dest="configDir", default="alidist") parser.add_argument("-w", "--work-dir", help="path to work dir", dest="workDir", default="workDir") parser.add_argument("--defaults", default="release", dest="defaults", help="Specify default to use") parser.add_argument("--disable", dest="disable", default=[], metavar="PACKAGE", action="append", help="Do not build PACKAGE and all its (unique) dependencies.") parser.add_argument("--always-prefer-system", dest="preferSystem", default=False, action="store_true", help="Always use system packages when compatible") parser.add_argument("--no-system", dest="noSystem", default=False, action="store_true", help="Never use system packages") parser.add_argument("packages", nargs="+", help="Package to test", default=[]) parser.add_argument("--docker", dest="docker", action="store_true", default=False) parser.add_argument("--docker-image", dest="dockerImage", help="Image to use in case you build with docker (implies --docker-image)") parser.add_argument("--chdir", "-C", help="Change to the specified directory first", metavar="DIR", dest="chdir", default=os.environ.get("ALIBUILD_CHDIR", ".")) return parser
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)
PUT THIS IN FairShip/python/detectArch #!/usr/bin/env /software/miniconda/bin/python import os,sys sys.path.append(os.environ['SHIPBUILD']+'/alibuild') from alibuild_helpers.utilities import getVersion, detectArch print detectArch()
def doParseArgs(star): detectedArch = detectArch() parser = argparse.ArgumentParser(epilog="""\ For help about each option, specify --help after the option itself. For complete documentation please refer to https://alisw.github.io/alibuild. """) parser.add_argument("-d", "--debug", dest="debug", action="store_true", help="Enable debug log output") parser.add_argument( "-n", "--dry-run", dest="dryRun", action="store_true", help="Print what would happen, without actually doing it.") subparsers = parser.add_subparsers(dest="action") analytics_parser = subparsers.add_parser( "analytics", help="turn on / off analytics", description="Control analytics state.") subparsers.add_parser("architecture", help="display detected architecture", description="Display the detected architecture.") build_parser = subparsers.add_parser("build", help="build a package", description="Build a package.") clean_parser = subparsers.add_parser( "clean", help="clean up build area", description="Clean up the build area.") deps_parser = subparsers.add_parser( "deps", help="generate a dependency graph for a given package", description="Generate a dependency graph for a given package.") doctor_parser = subparsers.add_parser( "doctor", help="verify status of your system", description="Verify the status of your system.") init_parser = subparsers.add_parser( "init", help="initialise local packages", description="Initialise development packages.") version_parser = subparsers.add_parser( "version", help="display %(prog)s version", description="Display %(prog)s and architecture.") # 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", metavar="PACKAGE", nargs="+", help= "One of the packages in CONFIGDIR. May be specified multiple times.") build_parser.add_argument( "--defaults", dest="defaults", default="release", metavar="DEFAULT", help="Use defaults from CONFIGDIR/defaults-%(metavar)s.sh.") build_parser.add_argument( "-a", "--architecture", dest="architecture", metavar="ARCH", default=detectedArch, help= ("Build as if on the specified architecture. When used with --docker, build " "inside a Docker image for the specified architecture. Default is the current " "system architecture, which is '%(default)s'.")) build_parser.add_argument( "--force-unknown-architecture", dest="forceUnknownArch", action="store_true", help= "Build on this system, even if it doesn't have a supported architecture." ) build_parser.add_argument( "-z", "--devel-prefix", nargs="?", dest="develPrefix", default=argparse.SUPPRESS, help= "Version name to use for development packages. Defaults to branch name." ) build_parser.add_argument( "-e", dest="environment", action="append", default=[], help= "KEY=VALUE binding to add to the build environment. May be specified multiple times." ) build_parser.add_argument( "-j", "--jobs", dest="jobs", type=int, default=multiprocessing.cpu_count(), help=("The number of parallel compilation processes to run. " "Default for this system: %(default)d.")) build_parser.add_argument( "-u", "--fetch-repos", dest="fetchRepos", action="store_true", help= ("Fetch updates to repositories in MIRRORDIR. Required but nonexistent " "repositories are always cloned, even if this option is not given.")) build_parser.add_argument( "--no-local", dest="noDevel", metavar="PKGLIST", default="", type=csv_list, help=("Do not pick up the following packages from a local checkout. " "%(metavar)s is a comma-separated list.")) build_parser.add_argument( "--disable", dest="disable", default=[], metavar="PACKAGE", action="append", help="Do not build %(metavar)s and all its (unique) dependencies.") build_docker = build_parser.add_argument_group( title="Build inside a container", description="""\ Builds can be done inside a Docker container, to make it easier to get a common, usable environment. The Docker daemon must be installed and running on your system. By default, images from alisw/<platform>-builder:latest will be used, e.g. alisw/slc8-builder:latest. They will be fetched if unavailable. """) build_docker.add_argument("--docker", dest="docker", action="store_true", help="Build inside a Docker container.") build_docker.add_argument( "--docker-image", dest="dockerImage", metavar="IMAGE", default=argparse.SUPPRESS, help=("The Docker image to build inside of. Implies --docker. " "By default, an image is chosen based on the architecture.")) build_docker.add_argument( "--docker-extra-args", metavar="ARGLIST", default="", help=( "Command-line arguments to pass to 'docker run'. " "Passed through verbatim -- separate multiple arguments " "with spaces, and make sure quoting is correct! Implies --docker." )) build_docker.add_argument( "-v", dest="volumes", action="append", default=[], help= ("Additional volume to be mounted inside the Docker container, if one is used. " "May be specified multiple times. Passed verbatim to 'docker run'.")) build_remote = build_parser.add_argument_group( title="Re-use prebuilt tarballs", description="""\ Reusing prebuilt tarballs saves compilation time, as common packages need not be rebuilt from scratch. rsync://, https://, b3:// and s3:// remote stores are recognised. Some of these require credentials: s3:// remotes require an ~/.s3cfg; b3:// remotes require AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY environment variables. A useful remote store is 'https://s3.cern.ch/swift/v1/alibuild-repo'. It requires no credentials and provides tarballs for the most common supported architectures. """) build_remote.add_argument( "--no-remote-store", action="store_true", help= "Disable the use of the remote store, even if it is enabled by default." ) build_remote.add_argument("--remote-store", dest="remoteStore", metavar="STORE", default="", help="""\ Where to find prebuilt tarballs to reuse. See above for available remote stores. End with ::rw if you want to upload (in that case, ::rw is stripped and --write-store is set to the same value). Implies --no-system. May be set to a default store on some architectures; use --no-remote-store to disable it in that case. """) build_remote.add_argument( "--write-store", dest="writeStore", metavar="STORE", default="", help= ("Where to upload newly built packages. Same syntax as --remote-store, " "except ::rw is not recognised. Implies --no-system.")) build_remote.add_argument( "--insecure", dest="insecure", action="store_true", help= "Don't validate TLS certificates when connecting to an https:// remote store." ) build_dirs = build_parser.add_argument_group( title="Customise %sBuild directories" % star) build_dirs.add_argument( "-C", "--chdir", metavar="DIR", dest="chdir", default=DEFAULT_CHDIR, help=("Change to the specified directory before building. " "Alternatively, set ALIBUILD_CHDIR. Default '%(default)s'.")) build_dirs.add_argument( "-w", "--work-dir", dest="workDir", default=DEFAULT_WORK_DIR, help= ("The toplevel directory under which builds should be done and build results " "should be installed. Default '%(default)s'.")) build_dirs.add_argument( "-c", "--config-dir", dest="configDir", default="%sdist" % star, help="The directory containing build recipes. Default '%(default)s'.") build_dirs.add_argument( "--reference-sources", dest="referenceSources", metavar="MIRRORDIR", default="%(workDir)s/MIRROR", help= ("The directory where reference git repositories will be cloned. " "'%%(workDir)s' will be substituted by WORKDIR. Default '%(default)s'." )) build_cleanup = build_parser.add_argument_group( title="Cleaning up after building") build_cleanup.add_argument( "--aggressive-cleanup", dest="aggressiveCleanup", action="store_true", help="Delete as much build data as possible when cleaning up.") build_cleanup.add_argument( "--no-auto-cleanup", dest="autoCleanup", action="store_false", help="Do not clean up build directories automatically after a build.") build_system = build_parser.add_mutually_exclusive_group() build_system.add_argument( "--always-prefer-system", dest="preferSystem", action="store_true", help="Always use system packages when compatible.") build_system.add_argument( "--no-system", dest="noSystem", action="store_true", help="Never use system packages, even if compatible.") # Options for clean subcommand clean_parser.add_argument( "-a", "--architecture", dest="architecture", metavar="ARCH", default=detectedArch, help= ("Clean up build results for this architecture. Default is the current system " "architecture, which is '%(default)s'.")) clean_parser.add_argument( "--aggressive-cleanup", dest="aggressiveCleanup", action="store_true", help="Delete as much build data as possible when cleaning up.") clean_dirs = clean_parser.add_argument_group( title="Customise %sBuild directories" % star) clean_dirs.add_argument( "-C", "--chdir", metavar="DIR", dest="chdir", default=DEFAULT_CHDIR, help=("Change to the specified directory before cleaning up. " "Alternatively, set ALIBUILD_CHDIR. Default '%(default)s'.")) clean_dirs.add_argument( "-w", "--work-dir", dest="workDir", default=DEFAULT_WORK_DIR, help= "The toplevel directory used in previous builds. Default '%(default)s'." ) # Options for the deps subcommand deps_parser.add_argument("package", metavar="PACKAGE", help="Calculate dependency tree for %(metavar)s.") deps_parser.add_argument( "-a", "--architecture", dest="architecture", metavar="ARCH", default=detectedArch, help= ("Resolve dependencies as if on the specified architecture. When used with " "--docker, use a Docker image for the specified architecture. Default is " "the current system architecture, which is '%(default)s'.")) deps_parser.add_argument( "--defaults", dest="defaults", default="release", metavar="DEFAULT", help="Use defaults from CONFIGDIR/defaults-%(metavar)s.sh.") deps_parser.add_argument( "--disable", dest="disable", default=[], metavar="PACKAGE", action="append", help="Do not build %(metavar)s and all its (unique) dependencies.") deps_graph = deps_parser.add_argument_group(title="Customise graph output") deps_graph.add_argument("--neat", dest="neat", action="store_true", help="Produce a graph with transitive reduction.") deps_graph.add_argument( "--outdot", dest="outdot", metavar="FILE", help="Keep intermediate Graphviz dot file in %(metavar)s.") deps_graph.add_argument("--outgraph", dest="outgraph", metavar="FILE", help="Store final output PDF file in %(metavar)s.") deps_docker = deps_parser.add_argument_group( title="Use a Docker container", description="""\ If you're planning to build inside a Docker container, e.g. using aliBuild build's --docker option, it may be useful to resolve dependencies inside that container as well, as which system packages are picked up may differ. """) deps_docker.add_argument( "--docker", dest="docker", action="store_true", help="Check for available system packages inside a Docker container.") deps_docker.add_argument( "--docker-image", dest="dockerImage", metavar="IMAGE", help=( "The Docker image to use. Implies --docker. By default, an image " "is chosen based on the current or selected architecture.")) deps_docker.add_argument( "--docker-extra-args", default="", metavar="ARGLIST", help=( "Command-line arguments to pass to 'docker run'. " "Passed through verbatim -- separate multiple arguments " "with spaces, and make sure quoting is correct! Implies --docker." )) deps_parser.add_argument_group(title="Customise %sBuild directories" % star) \ .add_argument("-c", "--config-dir", dest="configDir", default="%sdist" % star, help="The directory containing build recipes. Default '%(default)s'.") deps_system = deps_parser.add_mutually_exclusive_group() deps_system.add_argument( "--always-prefer-system", dest="preferSystem", action="store_true", help="Always use system packages when compatible.") deps_system.add_argument( "--no-system", dest="noSystem", action="store_true", help="Never use system packages, even if compatible.") # Options for the doctor subcommand doctor_parser.add_argument( "packages", metavar="PACKAGE", nargs="+", help= ("Check whether all system requirements of %(metavar)s are satisfied. " "May be specified multiple times.")) doctor_parser.add_argument( "-a", "--architecture", dest="architecture", metavar="ARCH", default=detectedArch, help= ("Resolve requirements as if on the specified architecture. When used with " "--docker, use a Docker image for the specified architecture. Default is " "the current system architecture, which is '%(default)s'.")) doctor_parser.add_argument( "--defaults", dest="defaults", default="release", metavar="DEFAULT", help="Use defaults from CONFIGDIR/defaults-%(metavar)s.sh.") doctor_parser.add_argument( "--disable", dest="disable", default=[], metavar="PACKAGE", action="append", help= "Assume we're not building %(metavar)s and all its (unique) dependencies." ) doctor_system = doctor_parser.add_mutually_exclusive_group() doctor_system.add_argument( "--always-prefer-system", dest="preferSystem", action="store_true", help="Always use system packages when compatible.") doctor_system.add_argument( "--no-system", dest="noSystem", action="store_true", help="Never use system packages, even if compatible.") doctor_docker = doctor_parser.add_argument_group( title="Use a Docker container", description="""\ If you're planning to build inside a Docker container, e.g. using aliBuild build's --docker option, it may be useful to resolve dependencies inside that container as well, as which system packages are picked up may differ. """) doctor_docker.add_argument( "--docker", dest="docker", action="store_true", help="Check for available system packages inside a Docker container.") doctor_docker.add_argument( "--docker-image", dest="dockerImage", metavar="IMAGE", help=( "The Docker image to use. Implies --docker. By default, an image " "is chosen based on the current or selected architecture.")) doctor_dirs = doctor_parser.add_argument_group( title="Customise %sBuild directories" % star) doctor_dirs.add_argument( "-C", "--chdir", metavar="DIR", dest="chdir", default=DEFAULT_CHDIR, help=("Change to the specified directory before doing anything. " "Alternatively, set ALIBUILD_CHDIR. Default '%(default)s'.")) doctor_dirs.add_argument( "-w", "--work-dir", dest="workDir", default=DEFAULT_WORK_DIR, # TODO: previous default was "workDir". help= ("The toplevel directory under which builds should be done and build results " "should be installed. Default '%(default)s'.")) doctor_dirs.add_argument( "-c", "--config", dest="configDir", default="%sdist" % star, help="The directory containing build recipes. Default '%(default)s'.") # Options for the init subcommand init_parser.add_argument( "pkgname", nargs="?", default="", metavar="PACKAGE", help="Package to clone locally. One of the packages in CONFIGDIR.") init_parser.add_argument( "-a", "--architecture", dest="architecture", metavar="ARCH", default=detectedArch, help=("Parse defaults using the specified architecture. Default is " "the current system architecture, which is '%(default)s'.")) init_parser.add_argument( "--defaults", dest="defaults", default="release", metavar="DEFAULT", help="Use defaults from CONFIGDIR/defaults-%(metavar)s.sh.") init_parser.add_argument( "-z", "--devel-prefix", dest="develPrefix", default=".", help=( "Directory under which to clone the repository of build recipes. " "See also: -c/--config-dir. Default '%(default)s'.")) init_parser.add_argument( "--dist", metavar="[USER/REPO@]BRANCH", dest="dist", default="", type=lambda x: alidist_string(x, star), help=("Download the given repository containing build recipes into " "CONFIGDIR. Syntax: [user/repo@]branch or [url@]branch. The " "default repo is 'alisw/%sdist; the default branch is the " "repository's main branch." % star)) init_dirs = init_parser.add_argument_group( title="Customise %sBuild directories" % star) init_dirs.add_argument( "-C", "--chdir", metavar="DIR", dest="chdir", default=DEFAULT_CHDIR, help=("Change to the specified directory before doing anything. " "Alternatively, set ALIBUILD_CHDIR. Default '%(default)s'.")) init_dirs.add_argument( "-w", "--work-dir", dest="workDir", default=DEFAULT_WORK_DIR, help=("The toplevel directory under which builds should be done and " "build results should be installed. Default '%(default)s'.")) init_dirs.add_argument( "-c", "--config-dir", dest="configDir", default="%%(prefix)s%sdist" % star, help= ("The directory where build recipes will be placed. '%%(prefix)s' will " "be replaced with 'DEVELPREFIX/'. Default '%(default)s'.")) init_dirs.add_argument( "--reference-sources", dest="referenceSources", metavar="MIRRORDIR", default="%(workDir)s/MIRROR", help= ("The directory where reference git repositories will be cloned. " "'%%(workDir)s' will be substituted by WORKDIR. Default '%(default)s'." )) # Options for the version subcommand version_parser.add_argument( "-a", "--architecture", dest="architecture", metavar="ARCH", default=detectedArch, help= ("Display the specified architecture next to the version number. Default is " "the current system architecture, which is '%(default)s'.")) # 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)
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)