Ejemplo n.º 1
0
def makeParser(functions):
    """returns a command line parser parsing subcommands from functions.

	functions is a dictionary (as returned from globals()).  Subcommands
	will be generated from all objects that have a subparseArgs attribute;
	furnish them using the commandWithArgs decorator.

	This attribute must contain a sequence of Arg items (see above).
	"""
    parser = argparse.ArgumentParser()
    subparsers = parser.add_subparsers()
    for name, val in functions.iteritems():
        args = getattr(val, "subparseArgs", None)
        if args is not None:
            subForName = subparsers.add_parser(name, help=val.subparseHelp)
            for arg in args:
                arg.add(subForName)
            subForName.set_defaults(subAction=val)

    # Now monkeypatch matching of unique prefixes into argparse guts.
    # If the guts change, don't fail hard, just turn off prefix matching
    try:
        for action in parser._actions:
            if isinstance(action, argparse._SubParsersAction):
                action.choices = action._name_parser_map = \
                 _PrefixMatchDict(action._name_parser_map)
                break
    except Exception, msg:
        # no prefix matching, then
        base.ui.notifyWarning(
            "Couldn't teach prefix matching to argparse: %s" % repr(msg))
def parseCommandLine(args=None):
	"""parses the command line for main()
	"""
	parser = argparse.ArgumentParser(description="Run tests embedded in RDs")
	parser.add_argument("id", type=str,
		help="RD id or cross-RD identifier for a testable thing.")
	parser.add_argument("-v", "--verbose", help="Talk while working",
		action="store_true", dest="verbose")
	parser.add_argument("-d", "--dump-negative", help="Dump the content of"
		" failing tests to stdout",
		action="store_true", dest="dumpNegative")
	parser.add_argument("-t", "--tag", help="Also run tests tagged with TAG.",
		action="store", dest="tag", default=None, metavar="TAG")
	parser.add_argument("-R", "--n-repeat", help="Run each test N times",
		action="store", dest="nRepeat", type=int, default=None, metavar="N")
	parser.add_argument("-T", "--timeout", help="Abort and fail requests"
		" after inactivity of SECONDS",
		action="store", dest="timeout", type=int, default=15, metavar="SECONDS")
	parser.add_argument("-D", "--dump-to", help="Dump the content of"
		" last failing test to FILE", metavar="FILE",
		action="store", type=str, dest="failFile", 
		default=None)
	parser.add_argument("-w", "--wait", help="Wait SECONDS before executing"
		" a request", metavar="SECONDS", action="store", 
		dest="execDelay", type=int, default=0)
	parser.add_argument("-u", "--serverURL", help="URL of the DaCHS root"
		" at the server to test",
		action="store", type=str, dest="serverURL", 
		default=base.getConfig("web", "serverURL"))
	parser.add_argument("-n", "--number-par", help="Number of requests"
		" to be run in parallel",
		action="store", type=int, dest="nThreads", 
		default=8)

	return parser.parse_args(args)
def parseCommandLine():
    from gavo.imp import argparse
    parser = argparse.ArgumentParser(description="Create or update DaCHS'"
                                     " file system and database environment.")
    parser.add_argument(
        "-d",
        "--dsn",
        help="DSN to use to connect to"
        " the future DaCHS database.  The DSN must let DaCHS connect"
        " to the DB as an administrator.  dbname, host, and port"
        " get copied to the profile, if given.  The DSN looks roughly like"
        ' "host=foo.bar user=admin password=secret". If you followed the'
        " installation instructions, you don't need this option.",
        action="store",
        type=str,
        dest="dsn",
        default="gavo")
    parser.add_argument(
        "--nodb",
        help="Inhibit initialization of the"
        " database (you may want to use this when refreshing the file system"
        " hierarchcy)",
        action="store_false",
        dest="initDB")
    return parser.parse_args()
Ejemplo n.º 4
0
def parseCommandLine():
    parser = argparse.ArgumentParser(
        description="Check RDs for well-formedness"
        " and some aspects of VO-friendlyness")
    parser.add_argument(
        "rd",
        nargs="+",
        type=str,
        help="RD identifier or file system path.  Use magic value ALL to"
        " check all reachable RDs.")
    parser.add_argument(
        "-p",
        "--pre-publication",
        help="Validate"
        " as if all services were IVOA published even if they are not"
        " (this may produce spurious errors if unpublished services are in"
        " the RD).",
        action="store_true",
        dest="prePublication")
    parser.add_argument("-v",
                        "--verbose",
                        help="Talk while working",
                        action="store_true",
                        dest="verbose")
    parser.add_argument("-t",
                        "--run-tests",
                        help="Run regression tests"
                        " embedded in the checked RDs",
                        action="store_true",
                        dest="runTests")
    parser.add_argument("-T",
                        "--timeout",
                        help="When running tests, abort"
                        " and fail requests after inactivity of SECONDS",
                        action="store",
                        dest="timeout",
                        type=int,
                        default=15,
                        metavar="SECONDS")
    parser.add_argument(
        "-c",
        "--compare-db",
        help="Also make sure that"
        " tables that are on disk (somewhat) match the definition in the RD.",
        action="store_true",
        dest="compareDB")
    parser.add_argument("-u",
                        "--accept-free-units",
                        help="Do not warn"
                        " against units not listed in VOUnits.",
                        action="store_true",
                        dest="acceptFreeUnits")

    return parser.parse_args()
def parseCommandLine():
	from gavo.imp import argparse
	parser = argparse.ArgumentParser()
	parser.add_argument("--force-dbversion", help="assume this as the"
		" database's schema version.  If you don't develop DaCHS, you"
		" almost certainly should stay clear of this flag", type=int,
		dest="forceDBVersion", default=None)
	parser.add_argument("--dry-run", help="do not commit at the end of"
		" the upgrade; this will not change anything in the database",
		dest="dryRun", action="store_true")
	return parser.parse_args()
Ejemplo n.º 6
0
def parseCommandLine():
	from gavo.imp import argparse
	parser = argparse.ArgumentParser(description="Run an asynchronous"
		" generic job (used internally)")
	parser.add_argument("jobId", type=str, help="UWS id of the job to run")
	return parser.parse_args()