Пример #1
0
def main():
    parser = ArgumentParser()
    subs = parser.add_subparsers(dest='cmd')

    account = subs.add_parser('account')
    account.add_argument('--json', '-j', action="store_true",
                         help="Output as JSON")
    sources = subs.add_parser('sources')
    sources.add_argument('--json', '-j', action="store_true",
                         help="Output as JSON")
    organization = subs.add_parser('organization')
    organization.add_argument('--json', '-j', action="store_true",
                              help="Output as JSON")
    args = parser.parse_args()

    client = Client.from_config()
    try:
        if args.cmd == 'account':
            data = client.get_account_details()
        if args.cmd == 'sources':
            data = client.get_account_sources()
        if args.cmd == 'organization':
            data = client.get_account_organization()
    except ValueError as e:
        parser.print_usage()
        sys.stderr.write('{}\n'.format(str(e)))
        sys.exit(1)

    if args.json:
        print(json.dumps(data, indent=4))
    else:
        print(data)
Пример #2
0
def main():
    opt_parser = ArgumentParser(
        description="Manage annotation databases of region_analysis.",
        prog="region_analysis_db.py")
    subparsers = opt_parser.add_subparsers(title="Subcommands",
                                           help="additional help")

    # list parser.
    parser_list = subparsers.add_parser("list", help="List genomes installed \
                                                      in database")
    parser_list.set_defaults(func=listgn)

    # install parser.
    parser_install = subparsers.add_parser("install",
                                           help="Install genome from tar.gz \
                                                  package file")
    parser_install.add_argument("pkg", help="Package file(.tar.gz) to install",
                                type=str)
    parser_install.set_defaults(func=install)
    parser_install.add_argument(
        "-y", "--yes", help="Say yes to all prompted questions",
        action="store_true")

    # remove parser.
    parser_remove = subparsers.add_parser("remove",
                                          help="Remove genome from database")
    parser_remove.add_argument("gn", help="Name of genome to be \
                                           removed(e.g. hg19)", type=str)
    parser_remove.set_defaults(func=remove)
    parser_remove.add_argument(
        "-y", "--yes", help="Say yes to all prompted questions",
        action="store_true")

    args = opt_parser.parse_args()
    args.func(args)
Пример #3
0
def _get_args():
    parser = ArgumentParser(formatter_class=RawDescriptionHelpFormatter,
                            description="Node Agent")
    subparsers = parser.add_subparsers(dest="mode")

    parser_cleanup = subparsers.add_parser('cleanup')
    parser_cleanup.add_argument("session", help="Session Name")
    parser_cleanup.add_argument("volume", help="Volume Name")
    parser_cleanup.add_argument("tmpfilename", help="Temporary File Name")
    parser_cleanup.add_argument("--debug", help="Debug", action="store_true")

    parser_session_create = subparsers.add_parser('create')
    parser_session_create.add_argument("session", help="Session Name")
    parser_session_create.add_argument("volume", help="Volume Name")
    parser_session_create.add_argument("brick", help="Brick Path")
    parser_session_create.add_argument("time_to_update", help="Time to Update")
    parser_session_create.add_argument("--reset-session-time",
                                       help="Reset Session Time",
                                       action="store_true")
    parser_session_create.add_argument("--debug", help="Debug",
                                       action="store_true")

    parser_post = subparsers.add_parser('post')
    parser_post.add_argument("session", help="Session Name")
    parser_post.add_argument("volume", help="Volume Name")
    parser_post.add_argument("brick", help="Brick Path")
    parser_post.add_argument("--debug", help="Debug",
                             action="store_true")

    parser_delete = subparsers.add_parser('delete')
    parser_delete.add_argument("session", help="Session Name")
    parser_delete.add_argument("volume", help="Volume Name")
    parser_delete.add_argument("--debug", help="Debug",
                               action="store_true")
    return parser.parse_args()
Пример #4
0
def create_parser(formatter_class=None):
    ''' Create lkadmin CLI argument parser '''

    if not formatter_class:
        formatter_class = CustomArgparseFormatter

    parser = ArgumentParser(description='Administer a Laniakea instance', formatter_class=formatter_class)
    subparsers = parser.add_subparsers(dest='sp_name', title='subcommands')

    # generic arguments
    parser.add_argument('--verbose', action='store_true', dest='verbose',
                        help='Enable debug messages.')
    parser.add_argument('--version', action='store_true', dest='show_version',
                        help='Display the version of Laniakea itself.')

    import lkadmin.core as core
    core.add_cli_parser(subparsers)

    import lkadmin.synchrotron as synchrotron
    synchrotron.add_cli_parser(subparsers)

    import lkadmin.spears as spears
    spears.add_cli_parser(subparsers)

    import lkadmin.ariadne as ariadne
    ariadne.add_cli_parser(subparsers)

    import lkadmin.isotope as isotope
    isotope.add_cli_parser(subparsers)

    import lkadmin.planter as planter
    planter.add_cli_parser(subparsers)

    return parser
 def run(cls):
     parser = ArgumentParser(
         description=("The theme development utility. "
                      "Includes three modes: "
                      "one for serving a theme compiled on-the-fly, "
                      "the other for compiling statically a theme "
                      "and the latter to dump URLs to files")
     )
     subparsers = parser.add_subparsers(
         title="Commands",
         description="Available commands (modes of operation)"
     )
     for key, target in cls.commands.items():
         if target is None:
             target = cls
         else:
             target = getattr(cls, target)
         subparser = subparsers.add_parser(
             key,
             description=target.__doc__,
             help=target.__doc__.splitlines()[0]
         )
         target.setup_parser(subparser)
         subparser.set_defaults(target=target)
     args = parser.parse_args()
     if hasattr(args, 'target'):
         sys.exit(args.target.main(args))
     else:
         parser.print_usage()
         sys.exit(-1)
Пример #6
0
def create_parser():

    parser = ArgumentParser(description="""
        Tool to interface with rant. Provides methods to create and edit pages
        in yaml/markdown, and generate html sites from them.
    """)

    subparsers = parser.add_subparsers(help='sub-command help', dest='parser')

    subparsers.add_parser(
        'install',
        help='Install a new rant project in current directory'
    )

    subparsers.add_parser(
        'create',
        help='Create a new rant page/post in current directory'
    )

    subparsers.add_parser(
        'build',
        help='Build static site from your source templates and content'
    )

    subparsers.add_parser(
        'serve',
        help='Start server that auto-builds on file-change for development'
    )

    return parser
Пример #7
0
def make_parser(prog):
    parser = ArgumentParser(prog)
    parser.add_argument('--version', action='version', version='%(prog)s ' + VERSION)

    command_parsers = parser.add_subparsers(metavar='command', dest='command')
    command_parsers.required = True

    command_search_parser = command_parsers.add_parser('search', help='search for items')
    command_search_parser.add_argument('type', help='type of item to search for',
                                       choices=['movie', 'person', 'character', 'company', 'keyword'])
    command_search_parser.add_argument('key', help='title or name of item to search for')
    command_search_parser.add_argument('-n', type=int, help='number of items to list')
    command_search_parser.add_argument('--first', action='store_true', help='display only the first result')
    command_search_parser.set_defaults(func=search_item)

    command_get_parser = command_parsers.add_parser('get', help='retrieve information about an item')
    command_get_parser.add_argument('type', help='type of item to retrieve',
                                    choices=['movie', 'person', 'character', 'company', 'keyword'])
    command_get_parser.add_argument('key', help='IMDb id (or keyword name) of item to retrieve')
    command_get_parser.add_argument('-n', type=int, help='number of movies to list (only for keywords)')
    command_get_parser.set_defaults(func=get_item)

    command_top_parser = command_parsers.add_parser('top', help='get top ranked movies')
    command_top_parser.add_argument('-n', type=int, help='number of movies to list')
    command_top_parser.add_argument('--first', action='store_true', help='display only the first result')
    command_top_parser.set_defaults(func=get_top_movies)

    command_bottom_parser = command_parsers.add_parser('bottom', help='get bottom ranked movies')
    command_bottom_parser.add_argument('-n', type=int, help='number of movies to list')
    command_bottom_parser.add_argument('--first', action='store_true', help='display only the first result')
    command_bottom_parser.set_defaults(func=get_bottom_movies)

    return parser
Пример #8
0
    def test_display_completions(self):
        parser = ArgumentParser()
        parser.add_argument("rover",
                            choices=["sojourner", "spirit", "opportunity", "curiosity"],
                            help="help for rover ")
        parser.add_argument("antenna", choices=["low gain", "high gain"], help="help for antenna")
        sub = parser.add_subparsers()
        p = sub.add_parser("list")
        p.add_argument("-o", "--oh", help="ttt")
        p.add_argument("-c", "--ch", help="ccc")
        sub2 = p.add_subparsers()
        sub2.add_parser("cat", help="list cat")
        sub2.add_parser("dog", help="list dog")

        completer = CompletionFinder(parser)

        completer.rl_complete("", 0)
        disp = completer.get_display_completions()
        self.assertEqual("help for rover ", disp.get("spirit", ""))
        self.assertEqual("help for rover ", disp.get("sojourner", ""))
        self.assertEqual("", disp.get("low gain", ""))

        completer.rl_complete('opportunity "low gain" list ', 0)
        disp = completer.get_display_completions()
        self.assertEqual("ttt", disp.get("-o --oh", ""))
        self.assertEqual("list cat", disp.get("cat", ""))

        completer.rl_complete("opportunity low\\ gain list --", 0)
        disp = completer.get_display_completions()
        self.assertEqual("ttt", disp.get("--oh", ""))
        self.assertEqual("ccc", disp.get("--ch", ""))
Пример #9
0
    def test_repl_subcommand(self):
        p = ArgumentParser()
        p.add_argument("--foo")
        p.add_argument("--bar")

        s = p.add_subparsers()
        s.add_parser("list")
        s.add_parser("set")
        show = s.add_parser("show")

        def abc():
            pass

        show.add_argument("--test")
        ss = show.add_subparsers()
        de = ss.add_parser("depth")
        de.set_defaults(func=abc)

        c = CompletionFinder(p, always_complete_options=True)

        expected_outputs = (
            ("prog ", ["-h", "--help", "--foo", "--bar", "list", "show", "set"]),
            ("prog li", ["list "]),
            ("prog s", ["show", "set"]),
            ("prog show ", ["--test", "depth", "-h", "--help"]),
            ("prog show d", ["depth "]),
            ("prog show depth ", ["-h", "--help"]),
        )

        for cmd, output in expected_outputs:
            self.assertEqual(set(self.run_completer(p, c, cmd)), set(output))
Пример #10
0
def main():
    parser = ArgumentParser(epilog=str_examples())

    #parser.add_argument('--version', action='version', version="ppdojo_db.py " + __version__)

    parser.add_argument('-v', '--verbose', default=0, action='count', # -vv --> verbose=2
                         help='verbose, can be supplied multiple times to increase verbosity')

    # Create the parsers for the sub-commands
    subparsers = parser.add_subparsers(dest='command', help='sub-command help')

    # Subparser for validate command.
    p_validate = subparsers.add_parser('validate', help='Validate the pseudopotential database.')

    # Subparser for regenerate command.
    p_reg = subparsers.add_parser('regenerate', help='Regenerate new checksums.')

    ###################################
    # Parse command line and dispatch #
    ###################################
    options = parser.parse_args()

    verbose = options.verbose

    if options.command == "validate":
        isok = validate_checksums(verbose=verbose)
        print("isok %s " % isok)

    if options.command == "regenerate":
        ans = raw_input("This command will regenerate the md5 hash values. Enter Y to continue... ")
        if ans == "Y":
            regenerate_checksums(verbose=verbose)

    return 0
Пример #11
0
def main():
    """
    Main entry point for CLI
    
    """
    load_maestro_rc()
    parser = ArgumentParser(prog='maestro', description='DevOps management')
    sub = parser.add_subparsers()
    sub_tasks = sub.add_parser('tasks', help='Tasks')
    sub_tasks.add_argument('-l', '--list', action='store_true', dest='tasks_list', default=False, \
        help='Show available tasks')
    sub_tasks.add_argument('-r', '--run', action='store', dest='tasks_task', \
        help='Task to run')
    sub_tasks.set_defaults(func=parse_tasks)
    
    sub_nodes = sub.add_parser('nodes', help='Nodes')
    sub_nodes.add_argument('-c', '--cloud-provider', action='store', dest='cloud_provider', \
        choices=config.AVAILABLE_CLOUD_PROVIDERS, default=None, required=True, \
        help='Name of cloud provider to use')
    sub_nodes.add_argument('-l', '--list', action='store_true', dest='list', default=False, \
        help='List all nodes')
    sub_nodes.add_argument('-t', '--task', action='store', dest='task', \
        help='Task to run on nodes')
    sub_nodes.add_argument('-u', '--user', action='store', dest='user', \
        help='Username to use when running task')
    sub_nodes.add_argument('-p', '--parallel', action='store_true', default=False, \
        help='Run task in parallel among nodes')
    sub_nodes.set_defaults(func=parse_nodes)
        
    args = parser.parse_args()
    args.func(args)
    # disconnect
    disconnect_all()
    sys.exit(0)
Пример #12
0
def cli():
    parser_main = ArgumentParser()
    parser_main.set_defaults(func=parser_main.print_usage)
    sub_parsers = parser_main.add_subparsers(help='sub-command')

    # main_parser


    # sub_parser: img
    parser_img = sub_parsers.add_parser('image', help='convert image file format')

    parser_img.add_argument('path', nargs='?', help='image file path')
    parser_img.add_argument('-o', '--outdir', help='output directory')
    parser_img.add_argument('-ext', '--ext',
                            help='to this format like png gif ...')

    parser_img.set_defaults(func=main_img)

    # sub_parser: info
    parser_info = sub_parsers.add_parser('info', help='recognise file format')
    parser_info.add_argument('path', nargs='?', help='file path')

    parser_info.set_defaults(func=main_info)

    parse_result = parser_main.parse_args()
    args = remove_value(remove_key(parse_result.__dict__, 'func'), None)
    try:
        parse_result.func(**args)
    except Exception as ex:
        color.print_err(type(ex), ex)
        color.print_err('Invalid args')
Пример #13
0
def main(args=None):
    from argparse import ArgumentParser
    from pathlib import Path
    from sys import argv

    parser = ArgumentParser(description="Find peaks in an nD image")
    subparsers = parser.add_subparsers()

    find_parser = subparsers.add_parser("find")
    find_parser.add_argument("image", type=Path, help="The image to process")
    find_parser.add_argument("--size", type=int, nargs=2, default=(1, 1),
                             help="The range of sizes (in px) to search.")
    find_parser.add_argument("--threshold", type=float, default=5,
                             help="The minimum spot intensity")
    find_parser.add_argument("--format", choices={"csv", "txt", "pickle"}, default="csv",
                             help="The output format (for stdout)")
    find_parser.add_argument("--edge", type=int, default=0,
                             help="Minimum distance to edge allowed.")
    find_parser.set_defaults(func=find)

    plot_parser = subparsers.add_parser("plot")
    plot_parser.add_argument("image", type=Path, help="The image to process")
    plot_parser.add_argument("peaks", type=Path, help="The peaks to plot")
    plot_parser.add_argument("outfile", nargs='?', type=Path, default=None,
                             help="Where to save the plot (omit to display)")
    plot_parser.add_argument("--axes", type=int, nargs=2, default=(0, 1),
                             help="The axes to plot")
    plot_parser.set_defaults(func=plot)

    for p in (plot_parser, find_parser):
        p.add_argument("--scale", nargs="*", type=float,
                       help="The scale for the points along each axis.")

    args = parser.parse_args(argv[1:] if args is None else args)
    args.func(args)
Пример #14
0
def create_parser(defaults):
    description = """
Manage monitors and alert contacts at UptimeRobot.com

If file exists, application will take defaults from:
    ./.uptimerobot.yml
    ~/.uptimerobot.yml
    """

    parser = ArgumentParser(description=description,
                            formatter_class=RawTextHelpFormatter,
                            usage="uptimerobot [-h] SUBCOMMAND [OPTION, ...]")
    sub_commands = parser.add_subparsers(title='Subcommands',
                                         dest="subcommand")

    api_key = defaults["api_key"]

    parse_get_monitors(sub_commands, defaults["get_monitors"], api_key)
    parse_new_monitor(sub_commands, defaults["new_monitor"], api_key)
    parse_edit_monitor(sub_commands, defaults["edit_monitor"], api_key)
    parse_delete_monitor(sub_commands, api_key)

    parse_get_alerts(sub_commands, defaults["get_alerts"], api_key)
    parse_new_alert(sub_commands, defaults["new_alert"], api_key)
    parse_delete_alert(sub_commands, api_key)

    return parser
Пример #15
0
def arg_parser():
    parser = ArgumentParser()
    subparsers = parser.add_subparsers(help='Commands', dest='command')

    repmatch_parser = subparsers.add_parser('repmatch', help='compare two replicate samples')
    repmatch_parser.add_argument('vcf1', help='Sample 1 VCF/BCF input (- for stdin)')
    repmatch_parser.add_argument('vcf2', help='Sample 2 VCF/BCF input (- for stdin)')
    repmatch_parser.add_argument('--out1', help='Sample 1 VCF/BCF output (optional)')
    repmatch_parser.add_argument('--out2', help='Sample 2 VCF/BCF output (optional)')
    repmatch_parser.add_argument('--name1', metavar='N', default=0, type=tryint,
                                 help='Name or index of sample in sample 1 file (default=0)')
    repmatch_parser.add_argument('--name2', metavar='N', default=0, type=tryint,
                                 help='Name or index of sample in sample 2 file (default=0)')

    add_common_args(repmatch_parser)

    dbmatch_parser = subparsers.add_parser('dbmatch', help='compare a database of alleles to a sample')
    dbmatch_parser.add_argument('database', help='Database of alleles VCF/BCF input (- for stdin)')
    dbmatch_parser.add_argument('sample',   help='Sample VCF/BCF input (- for stdin)')
    dbmatch_parser.add_argument('--name', metavar='N', default=0, type=tryint,
                                 help='Name or index of sample in sample file (default=0)')
    dbmatch_parser.add_argument('-o', '--output', default='-', help='Sample VCF/BCF output')

    add_common_args(dbmatch_parser)

    parser.add_argument('--debug', action='store_true', help='Output extremely verbose debugging information')
    parser.add_argument('--profile', action='store_true', help='Profile code performance')

    return parser
Пример #16
0
def parse_cli():
    parser = ArgumentParser(description='Tool for managing laser job recording')

    parser.add_argument(
        'user',
        metavar='USER',
        action='store',
        type=str,
        help='Name of current user')

    subparsers = parser.add_subparsers(help='operation to be performed')

    submit_job_parser = subparsers.add_parser('submit')
    submit_job_parser.set_defaults(which='submit')

    submit_job_parser.add_argument(
        '-t', '--time',
        action='store',
        type=str,
        required=True,
        help='Duration (HH:MM:MM, MM:SS, or SSSS)')

    submit_job_parser.add_argument(
        '-d', '--description',
        action='store',
        type=str,
        help='Optional description of job')

    query_job_parser = subparsers.add_parser('query')
    query_job_parser.set_defaults(which='query')

    #TODO: query stuff

    return parser.parse_args()
Пример #17
0
def setup_parser():
    """Setup an object of class ArgumentParser and return it."""

    root_parser = ArgumentParser()
    root_parser.add_argument(
        '--version',
        action='version',
        version=__version__)

    file_parser = ArgumentParser(add_help=False)
    file_parser.add_argument(
        'file',
        metavar='FILE',
        nargs='?',
        type=FileType('r', encoding='utf-8'),
        help='JSON')

    subparsers = root_parser.add_subparsers(help='commands')
    parser = subparsers.add_parser(
        'twmods',
        parents=[file_parser],
        help='generate both skeleton scripts and modules for twmods')
    parser.set_defaults(func=twmods)

    parser = subparsers.add_parser(
        'pttdemo',
        parents=[file_parser],
        help='generate scripts for PTT demonstration')
    parser.set_defaults(func=pttdemo)

    return root_parser
Пример #18
0
def main():

    parser = ArgumentParser()
    sub_parser = parser.add_subparsers()

    # settings create
    create_parser = sub_parser.add_parser("create", help="create setup.py")
    create_parser.set_defaults(func=create_setuppy)

    # setttings show-classifiers
    show_parser = sub_parser.add_parser(
        "show-classifiers",
        help="show classifiers list"
    )
    show_parser.set_defaults(func=show_classifiers)

    # setup test-env
    test_env_parser = sub_parser.add_parser(
        "setup-test-env",
        help="setup test environment"
    )
    test_env_parser.set_defaults(func=setup_test_environment)

    args = parser.parse_args()

    if hasattr(args, "func"):
        args.func(args)
    else:
        parser.parse_args(["-h"])
Пример #19
0
def main():
    """
    """
    parser = ArgumentParser(description="Create a transcription datatest")
    subparsers = parser.add_subparsers(help="subcommand help")

    parser_master = subparsers.add_parser("MASTER", help="master process")
    parser_master.add_argument("command", action="store", help="remote cmd to execute")
    parser_master.set_defaults(type="master")

    parser_worker = subparsers.add_parser("WORKER", help="worker process")
    parser_worker.add_argument("host", action="store", help="name or ip of master host")
    parser_worker.add_argument("port", action="store", help="port number")
    parser_worker.add_argument("command", action="store", help="remote cmd to execute")
    parser_worker.set_defaults(type="worker")

    args = parser.parse_args()
    hostname = socket.getfqdn()
    port = pickUnusedPort()

    if args.type == "master":
        cmd = "{} {} WORKER {} {} '{}'".format(
            sys.executable, os.path.abspath(sys.argv[0]), hostname, port, args.command
        )
        master(port, cmd)

    if args.type == "worker":
        worker(args.host, args.port, args.command)
Пример #20
0
def main():
    """
    Tool for generating or simulating economies
    """
    parser = ArgumentParser(version=VERSION, description=main.__doc__)
    subparsers = parser.add_subparsers()

    # Handle the new command
    subparser = subparsers.add_parser('new', help=cmd_new.__doc__)
    subparser.set_defaults(func=cmd_new)

    # Handle the run command
    subparser = subparsers.add_parser('run', help=cmd_run.__doc__)
    subparser.add_argument('-s', '--steps', type=int, default=10000,
            help='Number of steps to simulate (default %(default)d)')
    subparser.add_argument('-i', '--report-interval', type=int, default=100,
            help='Number of steps between reports (default %(default)d)')
    subparser.add_argument('description_file', type=FileType('r'), nargs='+',
            help='One or more YAML files containing economic descriptions to be'
                 'read in order')
    subparser.set_defaults(func=cmd_run)

    # Parse options
    args = parser.parse_args()

    # Initialize logging
    logging.basicConfig(level=logging.INFO)

    # Run command
    args.func(args)
Пример #21
0
    def _cmd_parse(self):
        """Add command options, add options whthin this method."""
        blade_cmd_help = 'blade <subcommand> [options...] [targets...]'
        arg_parser = ArgumentParser(prog='blade', description=blade_cmd_help)

        sub_parser = arg_parser.add_subparsers(dest="command",
                        help="Available subcommands")

        build_parser = sub_parser.add_parser("build",
                        help="Build specified targets")

        run_parser = sub_parser.add_parser("run",
                        help="Build and runs a single target")

        test_parser = sub_parser.add_parser("test",
                        help="Build the specified targets and runs tests")

        clean_parser = sub_parser.add_parser("clean",
                        help="Remove all Blade-created output")

        query_parser = sub_parser.add_parser("query",
                        help="Execute a dependency graph query")

        self._add_build_arguments(build_parser)
        self._add_build_arguments(run_parser)
        self._add_build_arguments(test_parser)

        self._add_run_arguments(run_parser)
        self._add_test_arguments(test_parser)
        self._add_clean_arguments(clean_parser)
        self._add_query_arguments(query_parser)

        return arg_parser.parse_known_args()
Пример #22
0
def _parse_arguments():
    parser = ArgumentParser(
        prog='YATUFC',
        description='This program can crawl a given Twitter user timeline '
        'or simply search for a provided term, in order to output found tweets '
        'in a CSV file for further analysis. Also, it is possible to set a date '
        'range for which you are interested, therefore capturing only tweets in '
        'the desired timeslot.',
        epilog='ATTENTION: Twitter API is rate limited. The rates per endpoint '
        'are described in https://developer.twitter.com/en/docs/basics/rate-limits. '
        'If YATUFC hits one of those limits, it\'ll sleep for 15 minutes after when '
        'they\'re finally reset.')
    parser.add_argument(
        '-s', '--since', type=_create_date, required=False,
        default='0001-1-1', metavar='YEAR-MONTH-DAY',
        help='a date in the format YEAR-MONTH-DAY (default: no limit)')
    parser.add_argument(
        '-u', '--upTo', type=_create_date, required=False,
        default=date.today().isoformat(), metavar='YEAR-MONTH-DAY',
        help='a date in the format YEAR-MONTH-DAY (default: now)')
    parser.add_argument(
        '-o', '--outputFilePath', type=str, required=False,
        metavar='outputFilePath', default='output.csv',
        help='a path to save the output data (default: output.csv)')

    subparsers = parser.add_subparsers(help='sub-command help', dest='command')
    parser_profile = subparsers.add_parser('profile')
    parser_profile.add_argument('profileName', metavar='the profile name to crawl.')

    parser_search = subparsers.add_parser('search')
    parser_search.add_argument('searchTerm', metavar='the search term to crawl.')

    return parser.parse_args()
Пример #23
0
def parse_args():
    parser = ArgumentParser(description=__doc__)
    parser.add_argument("conf_file", help=u"configuration to use")
    parser.add_argument(
        "-b", "--badge", default=u"invited", help=u"badge" u" (title or id) which is used to mark invited users"
    )
    parser.add_argument("-i", "--instance", default=None)
    subparsers = parser.add_subparsers()

    invite_parser = subparsers.add_parser("invite", help=u"invite new users" u" to adhocracy")
    invite_parser.add_argument("csv_file", help=u"csv files of users to add")
    invite_parser.add_argument("template", help=u"text file with mail body")
    invite_parser.add_argument("-s", "--subject", default=u"Welcome to Adhocracy!", help=u"email subject")
    invite_parser.set_defaults(action=u"invite")

    reinvite_parser = subparsers.add_parser(
        "reinvite", help=u"invite again all users who have not yet activated" u" their accounts"
    )
    reinvite_parser.add_argument("template", help=u"text file with mail body")
    reinvite_parser.add_argument("-s", "--subject", default=u"Welcome to Adhocracy!", help=u"email subject")
    reinvite_parser.set_defaults(action=u"reinvite")

    revoke_parser = subparsers.add_parser(
        "revoke", help=u"revoke invitation for all users who have not" u" activated their accounts after invitation"
    )
    revoke_parser.set_defaults(action=u"revoke")

    uninvite_parser = subparsers.add_parser("uninvite", help=u'remove "invited"-badge from given users')
    uninvite_parser.add_argument("users", metavar="user", nargs="+")
    uninvite_parser.add_argument(
        "-r", "--revoke", action="store_true", help=u"also revoke invitation" u" if not already activated"
    )
    uninvite_parser.set_defaults(action=u"uninvite")

    return parser.parse_args()
Пример #24
0
def define_arguments():
    ap = ArgumentParser()
    sp = ap.add_subparsers(title="Subcommands", dest="subcommand")
    sp.required = True

    #=====
    grpscmd = sp.add_parser("groupdefs",
                            description=groupdefs.__doc__)
    grpscmd.add_argument("profile", help="AWS profile (from ~/.aws/config)")
    grpscmd.add_argument("region", help="AWS region")
    grpscmd.add_argument("vpc", help="VPC ID or 'classic'")
    grpscmd.set_defaults(do=groupdefs)

    std_args = ArgumentParser(add_help=False)
    std_args.add_argument("account")
    std_args.add_argument('--tty', action='store_true', default=False,
                          help="Allow input from a tty (default=False)")

    #=====
    rndrcmd = sp.add_parser("render", parents=[std_args],
                            description=render_rules.__doc__)
    rndrcmd.add_argument("vars_files", nargs="*", metavar="FILE", default=[])
    rndrcmd.set_defaults(do=render_rules)

    #=====
    rvrscmd = sp.add_parser("reverse", parents=[std_args],
                            description=reverse_rules.__doc__)
    rvrscmd.add_argument("--vars-files", nargs="*", metavar="VARS_FILE", default=[])
    rvrscmd.add_argument("--input-files", nargs="+", metavar="RULES_FILE", default=[])
    rvrscmd.set_defaults(do=reverse_rules)

    return ap
Пример #25
0
def main():
    '''Parse command-line arguments and execute bumpversion command.'''

    parser = ArgumentParser(prog='bumpversion',
                            description='Bumpversion wrapper')

    default_changelog = os.path.join(os.getcwd(), 'CHANGES.rst')

    subparsers = parser.add_subparsers(title='bumpversion wrapper commands')
    # release command
    release_doc = bump_release_version.__doc__
    subparser = subparsers.add_parser("release",
                                      description=release_doc,
                                      formatter_class=RawTextHelpFormatter)
    subparser.add_argument('--changelog', help='Project changelog',
                           type=FileType(),
                           default=default_changelog)
    subparser.set_defaults(func=bump_release_version)
    # newversion command
    newversion_doc = bump_new_version.__doc__
    subparser = subparsers.add_parser("newversion",
                                      description=newversion_doc,
                                      formatter_class=RawTextHelpFormatter)
    subparser.add_argument('--changelog', help='Project changelog',
                           type=FileType(),
                           default=default_changelog)
    subparser.add_argument('part', help='Part of the version to be bumped',
                           choices=['patch', 'minor', 'major'])
    subparser.set_defaults(func=bump_new_version)
    # Parse argv arguments
    args = parser.parse_args()
    args.func(args)
Пример #26
0
def get_option_parser():
    """Return the option parser for this program."""
    parser = ArgumentParser(description="Manage objects in Azure blob storage")
    parser.add_argument(
        '--account-name',
        default=os.environ.get('AZURE_STORAGE_ACCOUNT', None),
        help="The azure storage account, or env AZURE_STORAGE_ACCOUNT.")
    parser.add_argument(
        '--account-key',
        default=os.environ.get('AZURE_STORAGE_ACCESS_KEY', None),
        help="The azure storage account, or env AZURE_STORAGE_ACCESS_KEY.")
    subparsers = parser.add_subparsers(help='sub-command help', dest='command')
    for command in (LIST, PUBLISH, DELETE):
        subparser = subparsers.add_parser(command, help='Command to run')
        subparser.add_argument(
            'purpose', help="<{}>".format(' | '.join(PURPOSES)))
        if command == PUBLISH:
            subparser.add_argument('path', help='The path to publish')
            add_mutation_args(subparser, 'Do not publish')
        elif command == DELETE:
            subparser.add_argument('path', nargs="+",
                                   help='The files to delete')
            add_mutation_args(subparser, 'Do not delete')
    sync_parser = subparsers.add_parser('sync',
                                        help='Sync local files to remote.')
    sync_parser.add_argument('local_dir', metavar='LOCAL-DIR',
                             help='The local directory to sync')
    sync_parser.add_argument('prefix', metavar='PREFIX',
                             help='The remote prefix to sync to')
    add_mutation_args(sync_parser, 'Do not sync')
    return parser
Пример #27
0
    def __new__(mcs, name, bases, attrs):
        instance = super(Commando, mcs).__new__(mcs, name, bases, attrs)
        subcommands = []
        main_command = None
        for name, member in attrs.iteritems():
            if hasattr(member, "command"):
                main_command = member
            elif hasattr(member, "subcommand"):
                subcommands.append(member)
        main_parser = None

        def add_arguments(parser, params):
            """
            Adds parameters to the parser
            """
            for parameter in params:
                parser.add_argument(*parameter.args, **parameter.kwargs)

        if main_command:
            main_parser = ArgumentParser(*main_command.command.args,
                                        **main_command.command.kwargs)
            add_arguments(main_parser, main_command.params)
            subparsers = None
            if len(subcommands):
                subparsers = main_parser.add_subparsers()
                for sub in subcommands:
                    parser = subparsers.add_parser(*sub.subcommand.args,
                                                  **sub.subcommand.kwargs)
                    parser.set_defaults(run=sub)
                    add_arguments(parser, sub.params)

        instance.__parser__ = main_parser
        instance.__main__ = main_command
        return instance
def _get_args():
    parser = ArgumentParser(formatter_class=RawDescriptionHelpFormatter, description=PROG_DESCRIPTION)
    subparsers = parser.add_subparsers(dest="mode")

    parser_getgfid = subparsers.add_parser("gfid")
    parser_getgfid.add_argument("path", help="Path")

    parser_getxtime = subparsers.add_parser("xtime")
    parser_getxtime.add_argument("path", help="Path")
    parser_getxtime.add_argument("master_uuid", help="Master UUID")

    parser_getstime = subparsers.add_parser("stime")
    parser_getstime.add_argument("path", help="Path")
    parser_getstime.add_argument("master_uuid", help="Master UUID")
    parser_getstime.add_argument("slave_uuid", help="Master UUID")

    parser_archivelist = subparsers.add_parser("listfromtar")
    parser_archivelist.add_argument("path", help="Path of Archive(Tar file)")

    parser_volmark_master = subparsers.add_parser("volmarkmaster")
    parser_volmark_master.add_argument("path", help="Path")

    parser_volmark_slave = subparsers.add_parser("volmarkslave")
    parser_volmark_slave.add_argument("path", help="Path")

    return parser.parse_args()
Пример #29
0
def setup():
    parser = ArgumentParser(description='Create starting configs for a slimta instance.')
    parser.add_argument('--version', action='version', version='%(prog)s '+__version__)
    parser.add_argument('-f', '--force', action='store_true', default=False,
                           help='Force overwriting files if destination exists. The user is prompted by default.')
    subparsers = parser.add_subparsers(help='Sub-command Help')

    config_parser = subparsers.add_parser('config', help='Setup Configuration')
    config_parser.add_argument('-e', '--etc-dir', metavar='DIR', default=None,
                           help='Place new configs in DIR. By default, this script will prompt the user for a directory.')
    config_parser.set_defaults(action='config')

    init_parser = subparsers.add_parser('init', help='Setup Init Scripts')
    init_parser.add_argument('-t', '--type', required=True, choices=['lsb', 'systemd'],
                           help='Type of init script to create.')
    init_parser.add_argument('-n', '--name', metavar='NAME', default='slimta',
                           help='Use NAME as the name of the service, default \'%(default)s\'.')
    init_parser.add_argument('-c', '--config-file', metavar='FILE', required=True,
                           help='Use FILE as the slimta configuration file in the init script.')
    init_parser.add_argument('-d', '--daemon', required=True,
                           help='Use DAEMON as the command to execute in the init script.')
    init_parser.add_argument('--init-dir', metavar='DIR', default=None,
                           help='Put resulting init script in DIR instead of the system default.')
    init_parser.add_argument('--pid-dir', metavar='DIR', default='/var/run',
                           help='Put pid files in DIR, default %(default)s.')
    init_parser.add_argument('--enable', action='store_true',
                           help='Once the init script is created, enable it.')
    init_parser.set_defaults(action='init')

    args = parser.parse_args()

    if args.action == 'config':
        _setup_configs(args)
    elif args.action == 'init':
        _setup_inits(args)
Пример #30
0
class InspektorApp(object):

    """
    Basic inspektor application.
    """

    def __init__(self):
        self.arg_parser = ArgumentParser(description='Inspektor code check')
        self.arg_parser.add_argument('-v', '--verbose', action='store_true',
                                     help=('print extra debug messages '
                                           '(alters behavior of the lint '
                                           'subcommand)'),
                                     dest='verbose')
        self.arg_parser.add_argument('--exclude', type=str,
                                     help='Quoted string containing paths or '
                                          'patterns to be excluded from '
                                          'checking, comma separated')
        subparsers = self.arg_parser.add_subparsers(title='subcommands',
                                                    description='valid subcommands',
                                                    help='subcommand help')
        lint.set_arguments(subparsers)
        reindent.set_arguments(subparsers)
        style.set_arguments(subparsers)
        check.set_arguments(subparsers)
        license.set_arguments(subparsers)
        self.args = self.arg_parser.parse_args()

    def run(self):
        try:
            return self.args.func(self.args)
        except KeyboardInterrupt:
            log.error('User pressed Ctrl+C, exiting...')
            return ERROR_INTERRUPTED
Пример #31
0
def command_thread():
    global res
    res = -1
    desc = """an easy-to-use but powerful command-line tool.
              try \'coscmd -h\' to get more informations.
              try \'coscmd sub-command -h\' to learn all command usage, likes \'coscmd upload -h\'"""
    parser = ArgumentParser(description=desc)
    parser.add_argument('-d',
                        '--debug',
                        help="debug mode",
                        action="store_true",
                        default=False)
    parser.add_argument('-b',
                        '--bucket',
                        help="set bucket",
                        type=str,
                        default="")
    parser.add_argument('-r',
                        '--region',
                        help="set region",
                        type=str,
                        default="")
    parser.add_argument('-c',
                        '--config_path',
                        help="set config_path",
                        type=str,
                        default="~/.cos.conf")
    parser.add_argument('-l',
                        '--log_path',
                        help="set log_path",
                        type=str,
                        default="~/.cos.log")

    sub_parser = parser.add_subparsers()
    parser_config = sub_parser.add_parser(
        "config", help="config your information at first.")
    parser_config.add_argument('-a',
                               '--secret_id',
                               help='specify your secret id',
                               type=str,
                               required=True)
    parser_config.add_argument('-s',
                               '--secret_key',
                               help='specify your secret key',
                               type=str,
                               required=True)
    parser_config.add_argument('-b',
                               '--bucket',
                               help='specify your bucket',
                               type=str,
                               required=True)

    group = parser_config.add_mutually_exclusive_group(required=True)
    group.add_argument('-r', '--region', help='specify your region', type=str)
    group.add_argument('-e',
                       '--endpoint',
                       help='specify COS endpoint',
                       type=str)

    parser_config.add_argument(
        '-m',
        '--max_thread',
        help='specify the number of threads (default 5)',
        type=int,
        default=5)
    parser_config.add_argument(
        '-p',
        '--part_size',
        help='specify min part size in MB (default 1MB)',
        type=int,
        default=1)
    parser_config.add_argument('-u',
                               '--appid',
                               help='specify your appid',
                               type=str,
                               default="")
    parser_config.add_argument('--do-not-use-ssl',
                               help="use http://",
                               action="store_true",
                               default=False,
                               dest="use_http")
    parser_config.add_argument('--anonymous',
                               help="anonymous",
                               type=str,
                               default="False")
    parser_config.set_defaults(func=config)

    parser_upload = sub_parser.add_parser(
        "upload", help="upload file or directory to COS.")
    parser_upload.add_argument(
        'local_path',
        help="local file path as /tmp/a.txt or directory",
        type=str)
    parser_upload.add_argument("cos_path",
                               help="cos_path as a/b.txt",
                               type=str)
    parser_upload.add_argument('-r',
                               '--recursive',
                               help="upload recursively when upload directory",
                               action="store_true",
                               default=False)
    parser_upload.add_argument('-H',
                               '--headers',
                               help="set HTTP headers",
                               type=str,
                               default='{}')
    parser_upload.add_argument('-s',
                               '--sync',
                               help="Upload and skip the same file",
                               action="store_true",
                               default=False)
    parser_upload.add_argument(
        '--ignore',
        help=
        'Set ignored rules, separated by commas; Example: *.txt,*.docx,*.ppt',
        type=str,
        default="")
    parser_upload.add_argument('--skipmd5',
                               help='upload without x-cos-meta-md5',
                               action="store_true",
                               default=False)
    parser_upload.set_defaults(func=Op.upload)

    parser_download = sub_parser.add_parser(
        "download", help="download file from COS to local.")
    parser_download.add_argument("cos_path",
                                 help="cos_path as a/b.txt",
                                 type=str)
    parser_download.add_argument('local_path',
                                 help="local file path as /tmp/a.txt",
                                 type=str)
    parser_download.add_argument('-f',
                                 '--force',
                                 help="Overwrite the saved files",
                                 action="store_true",
                                 default=False)
    parser_download.add_argument(
        '-r',
        '--recursive',
        help="Download recursively when upload directory",
        action="store_true",
        default=False)
    parser_download.add_argument('-s',
                                 '--sync',
                                 help="Download and skip the same file",
                                 action="store_true",
                                 default=False)
    parser_download.add_argument(
        '--ignore',
        help=
        'Set ignored rules, separated by commas; Example: *.txt,*.docx,*.ppt',
        type=str,
        default="")
    parser_download.set_defaults(func=Op.download)

    parser_delete = sub_parser.add_parser("delete",
                                          help="delete file or files on COS")
    parser_delete.add_argument("cos_path",
                               nargs='?',
                               help="cos_path as a/b.txt",
                               type=str,
                               default='')
    parser_delete.add_argument(
        '-r',
        '--recursive',
        help=
        "delete files recursively, WARN: all files with the prefix will be deleted!",
        action="store_true",
        default=False)
    parser_delete.add_argument('-f',
                               '--force',
                               help="Delete directly without confirmation",
                               action="store_true",
                               default=False)
    parser_delete.set_defaults(func=Op.delete)

    parser_abort = sub_parser.add_parser("abort",
                                         help='aborts upload parts on COS')
    parser_abort.add_argument("cos_path",
                              nargs='?',
                              help="cos_path as a/b.txt",
                              type=str,
                              default='')
    parser_abort.set_defaults(func=Op.abort)

    parser_copy = sub_parser.add_parser("copy",
                                        help="copy file from COS to COS.")
    parser_copy.add_argument(
        'source_path',
        help=
        "source file path as 'bucket-appid.cos.ap-guangzhou.myqcloud.com/a.txt'",
        type=str)
    parser_copy.add_argument("cos_path", help="cos_path as a/b.txt", type=str)
    parser_copy.add_argument('-r',
                             '--recursive',
                             help="copy files recursively",
                             action="store_true",
                             default=False)
    parser_copy.add_argument(
        '-t',
        '--type',
        help='specify x-cos-storage-class of files to upload',
        type=str,
        choices=['STANDARD', 'STANDARD_IA', 'NEARLINE'],
        default='STANDARD')
    parser_copy.set_defaults(func=Op.copy)

    parser_list = sub_parser.add_parser("list", help='list files on COS')
    parser_list.add_argument("cos_path",
                             nargs='?',
                             help="cos_path as a/b.txt",
                             type=str,
                             default='')
    parser_list.add_argument('-a',
                             '--all',
                             help="list all the files",
                             action="store_true",
                             default=False)
    parser_list.add_argument('-r',
                             '--recursive',
                             help="list files recursively",
                             action="store_true",
                             default=False)
    parser_list.add_argument('-n',
                             '--num',
                             help='specify max num of files to list',
                             type=int,
                             default=100)
    parser_list.add_argument('--human',
                             help='humanized display',
                             action="store_true",
                             default=False)
    parser_list.set_defaults(func=Op.list)

    parser_info = sub_parser.add_parser(
        "info", help="get the information of file on COS")
    parser_info.add_argument("cos_path", help="cos_path as a/b.txt", type=str)
    parser_info.add_argument('--human',
                             help='humanized display',
                             action="store_true",
                             default=False)
    parser_info.set_defaults(func=Op.info)

    parser_mget = sub_parser.add_parser(
        "mget", help="download file from COS to local.")
    parser_mget.add_argument("cos_path", help="cos_path as a/b.txt", type=str)
    parser_mget.add_argument('local_path',
                             help="local file path as /tmp/a.txt",
                             type=str)
    parser_mget.set_defaults(func=Op.mget)

    parser_restore = sub_parser.add_parser("restore", help="restore")
    parser_restore.add_argument("cos_path",
                                help="cos_path as a/b.txt",
                                type=str)
    parser_restore.add_argument(
        '-d',
        '--day',
        help='specify lifetime of the restored (active) copy',
        type=int,
        default=7)
    parser_restore.add_argument('-t',
                                '--tier',
                                help='specify the data access tier',
                                type=str,
                                choices=['Expedited', 'Standard', 'Bulk'],
                                default='Standard')
    parser_restore.set_defaults(func=Op.restore)

    parser_signurl = sub_parser.add_parser("signurl", help="get download url")
    parser_signurl.add_argument("cos_path",
                                help="cos_path as a/b.txt",
                                type=str)
    parser_signurl.add_argument('-t',
                                '--timeout',
                                help='specify the signature valid time',
                                type=int,
                                default=10000)
    parser_signurl.set_defaults(func=Op.signurl)

    parser_create_bucket = sub_parser.add_parser("createbucket",
                                                 help='create bucket')
    parser_create_bucket.set_defaults(func=Op.create_bucket)

    parser_delete_bucket = sub_parser.add_parser("deletebucket",
                                                 help='delete bucket')
    parser_delete_bucket.set_defaults(func=Op.delete_bucket)

    parser_put_object_acl = sub_parser.add_parser("putobjectacl",
                                                  help='''set object acl''')
    parser_put_object_acl.add_argument("cos_path",
                                       help="cos_path as a/b.txt",
                                       type=str)
    parser_put_object_acl.add_argument('--grant-read',
                                       dest='grant_read',
                                       help='set grant-read',
                                       type=str,
                                       required=False)
    parser_put_object_acl.add_argument('--grant-write',
                                       dest='grant_write',
                                       help='set grant-write',
                                       type=str,
                                       required=False)
    parser_put_object_acl.add_argument('--grant-full-control',
                                       dest='grant_full_control',
                                       help='set grant-full-control',
                                       type=str,
                                       required=False)
    parser_put_object_acl.set_defaults(func=Op.put_object_acl)

    parser_get_object_acl = sub_parser.add_parser("getobjectacl",
                                                  help='get object acl')
    parser_get_object_acl.add_argument("cos_path",
                                       help="cos_path as a/b.txt",
                                       type=str)
    parser_get_object_acl.set_defaults(func=Op.get_object_acl)

    parser_put_bucket_acl = sub_parser.add_parser("putbucketacl",
                                                  help='''set bucket acl''')
    parser_put_bucket_acl.add_argument('--grant-read',
                                       dest='grant_read',
                                       help='set grant-read',
                                       type=str,
                                       required=False)
    parser_put_bucket_acl.add_argument('--grant-write',
                                       dest='grant_write',
                                       help='set grant-write',
                                       type=str,
                                       required=False)
    parser_put_bucket_acl.add_argument('--grant-full-control',
                                       dest='grant_full_control',
                                       help='set grant-full-control',
                                       type=str,
                                       required=False)
    parser_put_bucket_acl.set_defaults(func=Op.put_bucket_acl)

    parser_get_bucket_acl = sub_parser.add_parser("getbucketacl",
                                                  help='get bucket acl')
    parser_get_bucket_acl.set_defaults(func=Op.get_bucket_acl)

    parser.add_argument('-v',
                        '--version',
                        action='version',
                        version='%(prog)s ' + Version)

    args = parser.parse_args()

    logger = logging.getLogger('')
    logger.setLevel(logging.INFO)
    console = logging.StreamHandler()
    console.setLevel(logging.INFO)
    if args.debug:
        logger.setLevel(logging.DEBUG)
        console.setLevel(logging.DEBUG)
    handler = RotatingFileHandler(os.path.expanduser(args.log_path),
                                  maxBytes=20 * 1024 * 1024,
                                  backupCount=1)
    handler.setFormatter(
        logging.Formatter('%(asctime)s - [%(levelname)s]:  %(message)s'))
    logger.addHandler(handler)
    logging.getLogger('').addHandler(console)
    global pre_appid, pre_bucket, pre_region, config_path
    config_path = args.config_path
    pre_bucket = args.bucket
    pre_region = args.region
    try:
        pre_appid = pre_bucket.split('-')[-1]
        pre_bucket = pre_bucket.rstrip(pre_appid)
        pre_bucket = pre_bucket[:-1]
    except Exception:
        logger.warn("set bucket error")
    try:
        res = args.func(args)
        return res
    except:
        return 0
Пример #32
0
def ParseArgs(argv):
    """Parse the binman command-line arguments

    Args:
        argv: List of string arguments
    Returns:
        Tuple (options, args) with the command-line options and arugments.
            options provides access to the options (e.g. option.debug)
            args is a list of string arguments
    """
    if '-H' in argv:
        argv.append('build')

    epilog = '''Binman creates and manipulate images for a board from a set of binaries. Binman is
controlled by a description in the board device tree.'''

    parser = ArgumentParser(epilog=epilog)
    parser.add_argument('-B', '--build-dir', type=str, default='b',
        help='Directory containing the build output')
    parser.add_argument('-D', '--debug', action='store_true',
        help='Enabling debugging (provides a full traceback on error)')
    parser.add_argument('-H', '--full-help', action='store_true',
        default=False, help='Display the README file')
    parser.add_argument('--toolpath', type=str, action='append',
        help='Add a path to the directories containing tools')
    parser.add_argument('-T', '--threads', type=int,
          default=None, help='Number of threads to use (0=single-thread)')
    parser.add_argument('--test-section-timeout', action='store_true',
          help='Use a zero timeout for section multi-threading (for testing)')
    parser.add_argument('-v', '--verbosity', default=1,
        type=int, help='Control verbosity: 0=silent, 1=warnings, 2=notices, '
        '3=info, 4=detail, 5=debug')

    subparsers = parser.add_subparsers(dest='cmd')
    subparsers.required = True

    build_parser = subparsers.add_parser('build', help='Build firmware image')
    build_parser.add_argument('-a', '--entry-arg', type=str, action='append',
            help='Set argument value arg=value')
    build_parser.add_argument('-b', '--board', type=str,
            help='Board name to build')
    build_parser.add_argument('-d', '--dt', type=str,
            help='Configuration file (.dtb) to use')
    build_parser.add_argument('--fake-dtb', action='store_true',
            help='Use fake device tree contents (for testing only)')
    build_parser.add_argument('--fake-ext-blobs', action='store_true',
            help='Create fake ext blobs with dummy content (for testing only)')
    build_parser.add_argument('-i', '--image', type=str, action='append',
            help='Image filename to build (if not specified, build all)')
    build_parser.add_argument('-I', '--indir', action='append',
            help='Add a path to the list of directories to use for input files')
    build_parser.add_argument('-m', '--map', action='store_true',
        default=False, help='Output a map file for each image')
    build_parser.add_argument('-M', '--allow-missing', action='store_true',
        default=False, help='Allow external blobs to be missing')
    build_parser.add_argument('-n', '--no-expanded', action='store_true',
            help="Don't use 'expanded' versions of entries where available; "
                 "normally 'u-boot' becomes 'u-boot-expanded', for example")
    build_parser.add_argument('-O', '--outdir', type=str,
        action='store', help='Path to directory to use for intermediate and '
        'output files')
    build_parser.add_argument('-p', '--preserve', action='store_true',\
        help='Preserve temporary output directory even if option -O is not '
             'given')
    build_parser.add_argument('-u', '--update-fdt', action='store_true',
        default=False, help='Update the binman node with offset/size info')
    build_parser.add_argument('--update-fdt-in-elf', type=str,
        help='Update an ELF file with the output dtb: infile,outfile,begin_sym,end_sym')

    entry_parser = subparsers.add_parser('entry-docs',
        help='Write out entry documentation (see entries.rst)')

    list_parser = subparsers.add_parser('ls', help='List files in an image')
    list_parser.add_argument('-i', '--image', type=str, required=True,
                             help='Image filename to list')
    list_parser.add_argument('paths', type=str, nargs='*',
                             help='Paths within file to list (wildcard)')

    extract_parser = subparsers.add_parser('extract',
                                           help='Extract files from an image')
    extract_parser.add_argument('-i', '--image', type=str, required=True,
                                help='Image filename to extract')
    extract_parser.add_argument('-f', '--filename', type=str,
                                help='Output filename to write to')
    extract_parser.add_argument('-O', '--outdir', type=str, default='',
        help='Path to directory to use for output files')
    extract_parser.add_argument('paths', type=str, nargs='*',
                                help='Paths within file to extract (wildcard)')
    extract_parser.add_argument('-U', '--uncompressed', action='store_true',
        help='Output raw uncompressed data for compressed entries')

    replace_parser = subparsers.add_parser('replace',
                                           help='Replace entries in an image')
    replace_parser.add_argument('-C', '--compressed', action='store_true',
        help='Input data is already compressed if needed for the entry')
    replace_parser.add_argument('-i', '--image', type=str, required=True,
                                help='Image filename to update')
    replace_parser.add_argument('-f', '--filename', type=str,
                                help='Input filename to read from')
    replace_parser.add_argument('-F', '--fix-size', action='store_true',
        help="Don't allow entries to be resized")
    replace_parser.add_argument('-I', '--indir', type=str, default='',
        help='Path to directory to use for input files')
    replace_parser.add_argument('-m', '--map', action='store_true',
        default=False, help='Output a map file for the updated image')
    replace_parser.add_argument('paths', type=str, nargs='*',
                                help='Paths within file to replace (wildcard)')

    test_parser = subparsers.add_parser('test', help='Run tests')
    test_parser.add_argument('-P', '--processes', type=int,
        help='set number of processes to use for running tests')
    test_parser.add_argument('-T', '--test-coverage', action='store_true',
        default=False, help='run tests and check for 100%% coverage')
    test_parser.add_argument('-X', '--test-preserve-dirs', action='store_true',
        help='Preserve and display test-created input directories; also '
             'preserve the output directory if a single test is run (pass test '
             'name at the end of the command line')
    test_parser.add_argument('tests', nargs='*',
                             help='Test names to run (omit for all)')

    return parser.parse_args(argv)
Пример #33
0
          action=funcs([tuple, to_float, chop]))
        a("--decoder-spec", help="List of decoding function types", nargs='+',
          type=str, default=default(['sig']), action=funcs([tuple, chop, rep]))
        a("--zestbn", type=str, default=default(['bugfix']), nargs='+',
          choices=['bugfix', 'no'], help="How to do zest bn")

        # Hyperparameters used for Cifar training
        a("--contrast-norm", help="Scale of contrast normalization (0=off)",
          type=int, default=default([0]), nargs='+')
        a("--top-c", help="Have c at softmax?", action=funcs([to_bool]),
          default=default([True]), nargs='+')
        a("--whiten-zca", help="Whether to whiten the data with ZCA",
          type=int, default=default([0]), nargs='+')

    ap = ArgumentParser("Semisupervised experiment")
    subparsers = ap.add_subparsers(dest='cmd', help='sub-command help')

    # TRAIN
    train_cmd = subparsers.add_parser('train', help='Train a new model')
    add_train_params(train_cmd, use_defaults=True)

    # EVALUATE
    load_cmd = subparsers.add_parser('evaluate', help='Evaluate test error')
    load_cmd.add_argument('load_from', type=str,
                          help="Destination to load the state from")
    load_cmd.add_argument('--data-type', type=str, default='test',
                          help="Data set to evaluate on")

    args = ap.parse_args()

    subp = subprocess.Popen(['git', 'rev-parse', 'HEAD'],
Пример #34
0
def main():
    """
    Main function
    """
    if __name__ == "__main__":
        parser = ArgumentParser()

        subparsers = parser.add_subparsers(help="commands")

        parser.add_argument('--version', action='version', version=VERSION)

        # A display command
        display_parser = subparsers.add_parser("display",
                                               help="Display certificate.")
        display_parser.add_argument("--input",
                                    "-i",
                                    action="store",
                                    help="Certificate path.")
        display_parser.add_argument("--input-fqdn",
                                    "-u",
                                    action="store",
                                    help="Certificate FQDN.")
        display_parser.add_argument("--extensions",
                                    "-e",
                                    action="store_true",
                                    default=False,
                                    help="Display extensions and signature.")
        display_parser.add_argument("--port",
                                    "-p",
                                    action="store",
                                    default=443,
                                    help="Change HTTPs port.")

        # An verify command
        verify_parser = subparsers.add_parser(
            "verify", help="verifiy couple CA, CERTIFICATE")
        verify_parser.add_argument("--input",
                                   "-i",
                                   action="store",
                                   help="Certificate path.")
        verify_parser.add_argument("--ca", action="store", help="CA path.")
        verify_parser.add_argument("--input-fqdn",
                                   "-f",
                                   action="store",
                                   help="Certificate FQDN.")
        verify_parser.add_argument("--port",
                                   "-p",
                                   action="store",
                                   help="Change HTTPs port.",
                                   default=443)

        args = parser.parse_args()

        if len(argv) < 2:
            parser.print_usage()
        elif argv[1] == "display":
            if args.input is not None:
                display(args.input, extensions=args.extensions)
            elif args.input_fqdn is not None:
                display(args.input_fqdn,
                        fqdn=True,
                        extensions=args.extensions,
                        port=args.port)
            else:
                display_parser.print_usage()
        elif argv[1] == "verify":
            if args.input is not None and args.ca is not None:
                verify(args.input, args.ca, port=args.port)
            elif args.input_fqdn is not None and args.ca is not None:
                verify(args.input_fqdn, args.ca, fqdn=True, port=args.port)
            else:
                verify_parser.print_usage()
import os
import random
import sys
import shutil
import traceback
from errno import EEXIST

from configobj import ConfigObj
from jinja2 import Template
from argparse import ArgumentParser, RawTextHelpFormatter

parser = ArgumentParser(description=__doc__, formatter_class=RawTextHelpFormatter)
subparsers = parser.add_subparsers(help="Commands", dest='command')
run_parser = subparsers.add_parser("run", help="Run a pipeline")
run_parser.add_argument("-v",
                    "--verbose",
                    dest="verbose",
                    action="store_true",
                    default=False,
                    help="Be loud!")
run_parser.add_argument("--config",
                    dest="config",
                    required=True,
                    help="Config file")
run_parser.add_argument("--name-suffix",
                    dest="name_suffix",
                    default="test_run",
                    help="Suffix to add to pipeline name in order to easily differentiate between different run, defaults to test_run")
run_parser.add_argument("--filter-multimappers",
                    dest="filter_multimappers",
                    action="store_true",
Пример #36
0
    def make_cli_parser(self, add_subparsers: bool = True) -> ArgumentParser:
        """
        Parse commandline arguments using a git-like subcommands scheme.
        """

        common_parser = ArgumentParser(add_help=False)
        common_parser.add_argument(
            "--nxdrive-home",
            default=Options.nxdrive_home,
            help=f"Folder to store the {APP_NAME} configuration",
        )

        common_parser.add_argument(
            "--log-level-file",
            default=Options.log_level_file,
            choices=("TRACE", "DEBUG", "INFO", "WARNING", "ERROR"),
            help="Minimum log level for the file log",
        )

        common_parser.add_argument(
            "--log-level-console",
            default=Options.log_level_console,
            choices=("TRACE", "DEBUG", "INFO", "WARNING", "ERROR"),
            help="Minimum log level for the console log",
        )

        common_parser.add_argument("--log-filename",
                                   help="File used to store the logs")

        common_parser.add_argument("--locale",
                                   default=Options.locale,
                                   help="Select the default language")

        common_parser.add_argument("--force-locale", help="Force the language")

        common_parser.add_argument(
            "--update-site-url",
            default=Options.update_site_url,
            help="Website for client auto-update",
        )

        common_parser.add_argument(
            "--channel",
            default=DEFAULT_CHANNEL,
            choices=("alpha", "beta", "release", "centralized"),
            help="Update channel",
        )

        common_parser.add_argument(
            "--debug",
            default=Options.debug,
            action="store_true",
            help=
            "Fire a debugger one uncaught error and enable REST API parameter checks.",
        )

        common_parser.add_argument(
            "--nofscheck",
            default=Options.nofscheck,
            action="store_true",
            help=
            "Disable the standard check for binding, to allow installation on network filesystem.",
        )

        common_parser.add_argument("--proxy-server",
                                   help="Define proxy server")

        common_parser.add_argument(
            "--ssl-no-verify",
            default=Options.ssl_no_verify,
            action="store_true",
            help=
            "Allows invalid/custom certificates. Highly unadvised to enable this option.",
        )

        common_parser.add_argument(
            "--sync-and-quit",
            default=Options.sync_and_quit,
            action="store_true",
            help="Launch the synchronization and then exit the application.",
        )

        common_parser.add_argument(
            "--debug-pydev",
            default=Options.debug_pydev,
            action="store_true",
            help="Allow debugging with a PyDev server",
        )

        common_parser.add_argument(
            "--delay",
            default=Options.delay,
            type=int,
            help="Delay in seconds for remote polling",
        )

        common_parser.add_argument(
            "--handshake-timeout",
            default=Options.handshake_timeout,
            type=int,
            help="HTTP request timeout in seconds for the handshake",
        )

        common_parser.add_argument(
            "--timeout",
            default=Options.timeout,
            type=int,
            help="HTTP request timeout in seconds for sync Automation call",
        )

        common_parser.add_argument(
            "--update-check-delay",
            default=Options.update_check_delay,
            type=int,
            help="Delay in seconds between checks for application update",
        )

        common_parser.add_argument(
            "--max-errors",
            default=Options.max_errors,
            type=int,
            help="Maximum number of tries before giving up synchronization of "
            "a file in error",
        )

        common_parser.add_argument(
            "-v",
            "--version",
            action="version",
            version=self.get_version(),
            help=f"Print the current version of the {APP_NAME} client",
        )

        parser = ArgumentParser(
            parents=[common_parser],
            description=f"Command line interface for {APP_NAME} operations.",
            usage=USAGE,
        )

        if not add_subparsers:
            return parser

        subparsers = parser.add_subparsers(title="Commands")

        # Link to a remote Nuxeo server
        bind_server_parser = subparsers.add_parser(
            "bind-server",
            help="Attach a local folder to a Nuxeo server.",
            parents=[common_parser],
        )
        bind_server_parser.set_defaults(command="bind_server")
        bind_server_parser.add_argument("--password",
                                        help="Password for the Nuxeo account")
        bind_server_parser.add_argument(
            "--local-folder",
            help="Local folder that will host the list of synchronized "
            "workspaces with a remote Nuxeo server.",
            default=DEFAULT_LOCAL_FOLDER,
        )
        bind_server_parser.add_argument(
            "username", help="User account to connect to Nuxeo")
        bind_server_parser.add_argument("nuxeo_url",
                                        help="URL of the Nuxeo server.")
        bind_server_parser.add_argument(
            "--remote-repo",
            default=Options.remote_repo,
            help="Name of the remote repository.",
        )

        # Unlink from a remote Nuxeo server
        unbind_server_parser = subparsers.add_parser(
            "unbind-server",
            help="Detach from a remote Nuxeo server.",
            parents=[common_parser],
        )
        unbind_server_parser.set_defaults(command="unbind_server")
        unbind_server_parser.add_argument(
            "--local-folder",
            help="Local folder that hosts the list of synchronized "
            "workspaces with a remote Nuxeo server.",
            type=str,
            default=DEFAULT_LOCAL_FOLDER,
        )

        # Bind root folders
        bind_root_parser = subparsers.add_parser(
            "bind-root",
            help="Register a folder as a synchronization root.",
            parents=[common_parser],
        )
        bind_root_parser.set_defaults(command="bind_root")
        bind_root_parser.add_argument(
            "remote_root",
            help="Remote path or id reference of a folder to synchronize.",
        )
        bind_root_parser.add_argument(
            "--local-folder",
            help="Local folder that will host the list of synchronized "
            "workspaces with a remote Nuxeo server. Must be bound with the "
            '"bind-server" command.',
            default=DEFAULT_LOCAL_FOLDER,
        )
        bind_root_parser.add_argument(
            "--remote-repo",
            default=Options.remote_repo,
            help="Name of the remote repository.",
        )

        # Unlink from a remote Nuxeo root
        unbind_root_parser = subparsers.add_parser(
            "unbind-root",
            help="Unregister a folder as a synchronization root.",
            parents=[common_parser],
        )
        unbind_root_parser.set_defaults(command="unbind_root")

        unbind_root_parser.add_argument(
            "remote_root",
            help="Remote path or id reference of a folder to synchronize.",
        )
        unbind_root_parser.add_argument(
            "--local-folder",
            help="Local folder that will host the list of synchronized "
            "workspaces with a remote Nuxeo server. Must be bound with the "
            '"bind-server" command.',
            default=DEFAULT_LOCAL_FOLDER,
        )
        unbind_root_parser.add_argument(
            "--remote-repo",
            default=Options.remote_repo,
            help="Name of the remote repository.",
        )

        # Uninstall
        uninstall_parser = subparsers.add_parser("uninstall",
                                                 help="Remove app data",
                                                 parents=[common_parser])
        uninstall_parser.set_defaults(command="uninstall")

        # Run in console mode
        console_parser = subparsers.add_parser("console",
                                               help="Start in GUI-less mode.",
                                               parents=[common_parser])
        console_parser.set_defaults(command="console")

        # Clean the folder
        clean_parser = subparsers.add_parser(
            "clean-folder",
            help="Remove recursively extended attributes from a given folder.",
            parents=[common_parser],
        )
        clean_parser.add_argument("--local-folder",
                                  help="Local folder to clean.")
        clean_parser.set_defaults(command="clean_folder")

        # Context menu: Access online
        ctx_item1 = subparsers.add_parser(
            "access-online",
            help="Open the document in the browser.",
            parents=[common_parser],
        )
        ctx_item1.set_defaults(command="ctx_access_online")
        ctx_item1.add_argument("--file", default="", help="File path.")

        # Context menu: Copy the share-link
        ctx_item2 = subparsers.add_parser(
            "copy-share-link",
            help="Copy the document's share-link to the clipboard.",
            parents=[common_parser],
        )
        ctx_item2.set_defaults(command="ctx_copy_share_link")
        ctx_item2.add_argument("--file", default="", help="File path.")

        # Context menu: Edit metadata
        ctx_item3 = subparsers.add_parser(
            "edit-metadata",
            help="Display the metadata window for a given file.",
            parents=[common_parser],
        )
        ctx_item3.set_defaults(command="ctx_edit_metadata")
        ctx_item3.add_argument("--file", default="", help="File path.")

        # Context menu: Direct Transfer
        ctx_item4 = subparsers.add_parser(
            "direct-transfer",
            help="Direct Transfer of a given file to anywhere on the server.",
            parents=[common_parser],
        )
        ctx_item4.set_defaults(command="ctx_direct_transfer")
        ctx_item4.add_argument("--file", default="", help="File path.")

        return parser
Пример #37
0
def create_parser():
    parser = ArgumentParser(
        description='versatile benchmark output compare tool')

    parser.add_argument(
        '-a',
        '--display_aggregates_only',
        dest='display_aggregates_only',
        action="store_true",
        help="If there are repetitions, by default, we display everything - the"
        " actual runs, and the aggregates computed. Sometimes, it is "
        "desirable to only view the aggregates. E.g. when there are a lot "
        "of repetitions. Do note that only the display is affected. "
        "Internally, all the actual runs are still used, e.g. for U test.")

    utest = parser.add_argument_group()
    utest.add_argument(
        '--no-utest',
        dest='utest',
        default=True,
        action="store_false",
        help=
        "The tool can do a two-tailed Mann-Whitney U test with the null hypothesis that it is equally likely that a randomly selected value from one sample will be less than or greater than a randomly selected value from a second sample.\nWARNING: requires **LARGE** (no less than {}) number of repetitions to be meaningful!\nThe test is being done by default, if at least {} repetitions were done.\nThis option can disable the U Test."
        .format(report.UTEST_OPTIMAL_REPETITIONS,
                report.UTEST_MIN_REPETITIONS))
    alpha_default = 0.05
    utest.add_argument(
        "--alpha",
        dest='utest_alpha',
        default=alpha_default,
        type=float,
        help=
        ("significance level alpha. if the calculated p-value is below this value, then the result is said to be statistically significant and the null hypothesis is rejected.\n(default: %0.4f)"
         ) % alpha_default)

    subparsers = parser.add_subparsers(
        help='This tool has multiple modes of operation:', dest='mode')

    parser_a = subparsers.add_parser(
        'benchmarks',
        help=
        'The most simple use-case, compare all the output of these two benchmarks'
    )
    baseline = parser_a.add_argument_group('baseline',
                                           'The benchmark baseline')
    baseline.add_argument('test_baseline',
                          metavar='test_baseline',
                          type=argparse.FileType('r'),
                          nargs=1,
                          help='A benchmark executable or JSON output file')
    contender = parser_a.add_argument_group(
        'contender',
        'The benchmark that will be compared against the baseline')
    contender.add_argument('test_contender',
                           metavar='test_contender',
                           type=argparse.FileType('r'),
                           nargs=1,
                           help='A benchmark executable or JSON output file')
    parser_a.add_argument(
        'benchmark_options',
        metavar='benchmark_options',
        nargs=argparse.REMAINDER,
        help='Arguments to pass when running benchmark executables')

    parser_b = subparsers.add_parser(
        'filters', help='Compare filter one with the filter two of benchmark')
    baseline = parser_b.add_argument_group('baseline',
                                           'The benchmark baseline')
    baseline.add_argument('test',
                          metavar='test',
                          type=argparse.FileType('r'),
                          nargs=1,
                          help='A benchmark executable or JSON output file')
    baseline.add_argument(
        'filter_baseline',
        metavar='filter_baseline',
        type=str,
        nargs=1,
        help='The first filter, that will be used as baseline')
    contender = parser_b.add_argument_group(
        'contender',
        'The benchmark that will be compared against the baseline')
    contender.add_argument(
        'filter_contender',
        metavar='filter_contender',
        type=str,
        nargs=1,
        help='The second filter, that will be compared against the baseline')
    parser_b.add_argument(
        'benchmark_options',
        metavar='benchmark_options',
        nargs=argparse.REMAINDER,
        help='Arguments to pass when running benchmark executables')

    parser_c = subparsers.add_parser(
        'benchmarksfiltered',
        help=
        'Compare filter one of first benchmark with filter two of the second benchmark'
    )
    baseline = parser_c.add_argument_group('baseline',
                                           'The benchmark baseline')
    baseline.add_argument('test_baseline',
                          metavar='test_baseline',
                          type=argparse.FileType('r'),
                          nargs=1,
                          help='A benchmark executable or JSON output file')
    baseline.add_argument(
        'filter_baseline',
        metavar='filter_baseline',
        type=str,
        nargs=1,
        help='The first filter, that will be used as baseline')
    contender = parser_c.add_argument_group(
        'contender',
        'The benchmark that will be compared against the baseline')
    contender.add_argument(
        'test_contender',
        metavar='test_contender',
        type=argparse.FileType('r'),
        nargs=1,
        help=
        'The second benchmark executable or JSON output file, that will be compared against the baseline'
    )
    contender.add_argument(
        'filter_contender',
        metavar='filter_contender',
        type=str,
        nargs=1,
        help='The second filter, that will be compared against the baseline')
    parser_c.add_argument(
        'benchmark_options',
        metavar='benchmark_options',
        nargs=argparse.REMAINDER,
        help='Arguments to pass when running benchmark executables')

    return parser
Пример #38
0
import qpc.messages as messages
from qpc.cli import CLI
from qpc.cred import CREDENTIAL_URI
from qpc.request import CONNECTION_ERROR_MSG, SSL_ERROR_MSG
from qpc.source import SOURCE_URI
from qpc.source.edit import SourceEditCommand
from qpc.tests_utilities import DEFAULT_CONFIG, HushUpStderr, redirect_stdout
from qpc.utils import (get_server_location, read_in_file, write_server_config)

import requests

import requests_mock

TMP_HOSTFILE = '/tmp/testhostsfile'
PARSER = ArgumentParser()
SUBPARSER = PARSER.add_subparsers(dest='subcommand')


class SourceEditCliTests(unittest.TestCase):
    """Class for testing the source edit commands for qpc."""
    def setUp(self):
        """Create test setup."""
        write_server_config(DEFAULT_CONFIG)
        # Temporarily disable stderr for these tests, CLI errors clutter up
        # nosetests command.
        self.orig_stderr = sys.stderr
        sys.stderr = HushUpStderr()
        if os.path.isfile(TMP_HOSTFILE):
            os.remove(TMP_HOSTFILE)
        with open(TMP_HOSTFILE, 'w') as test_hostfile:
            test_hostfile.write('1.2.3.4\n')
Пример #39
0
def main():
    parser = ArgumentParser(description="Shell Manager")
    parser.add_argument("-d",
                        "--debug",
                        action="store_true",
                        default=False,
                        help="show debug information")
    parser.add_argument("--colorize",
                        default="auto",
                        choices=["auto", "never"],
                        help="support colored output")
    subparsers = parser.add_subparsers()

    problem_package_parser = subparsers.add_parser(
        "package", help="problem package management")
    problem_package_parser.add_argument(
        "-s",
        "--staging-dir",
        help="use an explicit directory for problem staging.")
    problem_package_parser.add_argument(
        "-o", "--out", help="folder to store problem package.")
    problem_package_parser.add_argument(
        "-i",
        "--ignore",
        dest="ignore",
        default=[],
        action="append",
        help="list of files to ignore adding to the deb")
    problem_package_parser.add_argument("problem_paths",
                                        nargs="*",
                                        type=str,
                                        help="paths to problems.")
    problem_package_parser.set_defaults(func=problem_builder)

    publish_repo_parser = subparsers.add_parser(
        "publish_repo", help="publish packaged problems")
    publish_repo_parser.add_argument("-r",
                                     "--repository",
                                     default="/usr/local/ctf-packages",
                                     help="Location of problem repository.")
    publish_repo_parser.add_argument("repo_type", choices=["local", "remote"])
    publish_repo_parser.add_argument("package_paths",
                                     nargs="+",
                                     type=str,
                                     help="problem packages to publish.")
    publish_repo_parser.set_defaults(func=update_repo)

    migration_parser = subparsers.add_parser(
        "migrate", help="migrate legacy problem formats")
    migration_parser.add_argument("-i",
                                  "--interactive",
                                  action="store_true",
                                  help="update problem fields interactively")
    migration_parser.add_argument("-d",
                                  "--dry",
                                  action="store_true",
                                  help="don't make persistent changes.")
    migration_parser.add_argument(
        "-l",
        "--legacy-format",
        default="cyberstakes2014",
        choices=["cyberstakes2014"],
        help="what format the problems are currently in.")
    migration_parser.add_argument(
        "-s",
        "--set-defaults",
        type=str,
        action="append",
        default=[],
        help="field:value used to override new defaults.")
    migration_parser.add_argument("problem_paths",
                                  nargs="+",
                                  type=str,
                                  help="paths to problems.")
    migration_parser.set_defaults(func=migrate_problems)

    bundle_parser = subparsers.add_parser("bundle",
                                          help="create a bundle of problems")
    bundle_parser.add_argument("bundle_path",
                               type=str,
                               help="the name of the bundle.")
    bundle_parser.add_argument(
        "-s",
        "--staging-dir",
        help="use an explicit directory for problem staging.")
    bundle_parser.add_argument("-o",
                               "--out",
                               type=str,
                               help="folder to store the bundle.")
    bundle_parser.set_defaults(func=bundle_problems)

    deploy_parser = subparsers.add_parser("deploy", help="problem deployment")
    deploy_parser.add_argument(
        "-n",
        "--num-instances",
        type=int,
        default=1,
        help="number of instances to generate (numbers 0 through n-1).")
    deploy_parser.add_argument("-i",
                               "--instances",
                               action="append",
                               type=int,
                               help="particular instance(s) to generate.")
    deploy_parser.add_argument("-d",
                               "--dry",
                               action="store_true",
                               help="don't make persistent changes.")
    deploy_parser.add_argument(
        "-r",
        "--redeploy",
        action="store_true",
        help="redeploy instances that have already been deployed")
    deploy_parser.add_argument(
        "-s",
        "--secret",
        action="store",
        type=str,
        help="use a different deployment secret for this invocation.")
    deploy_parser.add_argument("-D",
                               "--deployment-directory",
                               type=str,
                               default=None,
                               help="the directory to deploy to")
    deploy_parser.add_argument("-b",
                               "--bundle",
                               action="store_true",
                               help="specify a bundle of problems to deploy.")
    deploy_parser.add_argument("problem_paths",
                               nargs="*",
                               type=str,
                               help="paths to problems.")
    deploy_parser.set_defaults(func=deploy_problems)

    undeploy_parser = subparsers.add_parser(
        "undeploy",
        help=
        "problem undeployment. cannot guarantee full removal of problem files")
    undeploy_parser.add_argument(
        "-n",
        "--num-instances",
        type=int,
        default=1,
        help="number of instances to undeploy (numbers 0 through n-1).")
    undeploy_parser.add_argument("-i",
                                 "--instances",
                                 action="append",
                                 type=int,
                                 help="particular instance(s) to generate.")
    undeploy_parser.add_argument(
        "-b",
        "--bundle",
        action="store_true",
        help="specify a bundle of problems to undeploy.")
    undeploy_parser.add_argument("problem_paths",
                                 nargs="*",
                                 type=str,
                                 help="paths to problems.")
    undeploy_parser.set_defaults(func=undeploy_problems)

    clean_parser = subparsers.add_parser(
        "clean",
        help="Clean up the intermediate staging data stored during deployments"
    )
    clean_parser.set_defaults(func=clean)

    status_parser = subparsers.add_parser(
        "status",
        help=
        "List the installed problems and bundles and any instances associated with them."
    )
    status_parser.add_argument(
        "-a",
        "--all",
        action="store_true",
        help="Show information about all problem instanes.")
    status_parser.add_argument(
        "-p",
        "--problem",
        type=str,
        default=None,
        help="Display status information for a given problem.")
    status_parser.add_argument(
        "-b",
        "--bundle",
        type=str,
        default=None,
        help="Display status information for a given bundle.")
    status_parser.add_argument(
        "-j",
        "--json",
        action="store_true",
        default=None,
        help="Display status information in json format")
    status_parser.add_argument(
        "-e",
        "--errors-only",
        action="store_true",
        help="Only print problems with failing service status.")
    status_parser.set_defaults(func=status)

    publish_parser = subparsers.add_parser(
        "publish",
        help=
        "Generate the information needed by the web server for this deployment."
    )
    publish_parser.set_defaults(func=publish)

    config_parser = subparsers.add_parser(
        "config", help="View or modify configuration options")
    config_parser.add_argument(
        "-f",
        "--file",
        type=str,
        default=None,
        help=
        "Which configuration file to access. If none is provided, the system wide configuration file will be used."
    )
    config_parser.add_argument(
        "-j",
        "--json",
        action="store_true",
        default=False,
        help=
        "Whether to display the configuration options in JSON form or pretty printed. Defaults to False."
    )
    config_parser.set_defaults(func=print_configuration)
    config_subparsers = config_parser.add_subparsers()

    config_set_parser = config_subparsers.add_parser(
        "set", help="Set configuration options")
    config_set_parser.add_argument("-f",
                                   "--field",
                                   type=str,
                                   required=True,
                                   help="which field to set")
    config_set_parser.add_argument("-v",
                                   "--value",
                                   type=str,
                                   required=True,
                                   help="options's new value")
    config_set_parser.add_argument("-j",
                                   "--json",
                                   action="store_true",
                                   default=False,
                                   help="interpret the given value as JSON")
    config_set_parser.add_argument(
        "--allow-type-change",
        action="store_true",
        default=False,
        help="Allow the supplied field to change types if already specified")
    config_set_parser.set_defaults(func=set_configuration_option)

    config_new_parser = config_subparsers.add_parser(
        "new", help="Make a new configuration files with defaults")
    config_new_parser.add_argument("files",
                                   nargs="+",
                                   help="Configuration files to make")
    config_new_parser.add_argument(
        "--overwrite",
        action="store_true",
        default=False,
        help="whether to overwrite files that already exist")
    config_new_parser.set_defaults(func=new_configuration_file)

    args = parser.parse_args()

    if args.colorize == "never":
        coloredlogs.DEFAULT_LEVEL_STYLES = {}
        coloredlogs.DEFAULT_FIELD_STYLES = {}

    coloredlogs.install()

    if args.debug:
        coloredlogs.set_level(logging.DEBUG)
    try:
        try:
            config = get_hacksports_config()
        except PermissionError:
            logger.error("You must run shell_manager with sudo.")
            raise FatalException
        except FileNotFoundError:
            place_default_config()
            logger.info(
                "There was no default configuration. One has been created for you. Please edit it accordingly using the 'shell_manager config' subcommand before deploying any instances."
            )
            raise FatalException

        #Call the default function
        if "func" in args:
            args.func(args, config)
        else:
            parser.print_help()
    except FatalException:
        exit(1)
Пример #40
0
        plot_masked_predictions(predictions, test_iter, args.dataset)
    else:

        details, confusion_matrix = test_model_binary(model, args.dataset)

        model_dir = os.path.dirname(path_from_model_name(model_name))
        with open(os.path.join(model_dir, 'results.csv'), 'w') as f:
            write_dict_to_csv(details, f)

        plot_confusion_chart(confusion_matrix)
        plot_predictions(details['Percent'], args.dataset)


if __name__ == '__main__':
    p = ArgumentParser()
    sp = p.add_subparsers()

    # Arguments for train mode
    train = sp.add_parser('train', help='Train a new model')
    train.add_argument('model', help='Name of the model to save: example_net')
    train.add_argument('dataset', nargs='?', default='dataset_calibrated')
    train.add_argument('--overwrite',
                       '-o',
                       action='store_true',
                       help='Replace the file if it exists')
    train.add_argument('--continue',
                       '-c',
                       action='store_true',
                       dest='cont',
                       help='Continue training from existing model')
    train.add_argument('--epochs', '-e', type=int, default=10)
Пример #41
0
    python example_cli.py
Or, if you want other people to be able to install your package and write
their own scripts by calling into your tool, you can import it instead
    from example_cli import cli
    cli.login()
    cli.say_hello()
    cli.logout()
"""

from argparse import ArgumentParser
from globus_sdk import AuthClient
from fair_research_login import (NativeClient, ConfigParserTokenStorage,
                                 LoadError)

parser = ArgumentParser(prog='Example Client')
subparsers = parser.add_subparsers(dest='subcommand')

login = subparsers.add_parser('login', help='Login to My Client')
login.add_argument('--no-local-server', action='store_true')
login.add_argument('--no-browser', action='store_true')
login.add_argument('--remember-me', action='store_true')

logout = subparsers.add_parser('logout', help='Revoke and clear tokens')

hello = subparsers.add_parser('hello', help='A friendly welcome')


class MyClient(NativeClient):
    def __init__(self):
        client_id = 'd719c82f-3a11-4de1-9d87-d52d28ec31b6'
        # You can provide `default_scopes` for the scopes you need for your
Пример #42
0
        except AssertionError:
            model.load_state_dict(torch.load(args.state,
                map_location=lambda storage, loc: storage))

    if args.mode == 'eval':
        evaluate(args, model)
    if args.mode == 'train':
        train(args, model)

if __name__ == '__main__':
    parser = ArgumentParser()
    parser.add_argument('--cuda', action='store_true')
    parser.add_argument('--model', required=True)
    parser.add_argument('--state')

    subparsers = parser.add_subparsers(dest='mode')
    subparsers.required = True

    parser_eval = subparsers.add_parser('eval')
    parser_eval.add_argument('image')
    parser_eval.add_argument('label')

    parser_train = subparsers.add_parser('train')
    parser_train.add_argument('--port', type=int, default=80)
    parser_train.add_argument('--datadir', required=True)
    parser_train.add_argument('--num-epochs', type=int, default=32)
    parser_train.add_argument('--num-workers', type=int, default=4)
    parser_train.add_argument('--batch-size', type=int, default=1)
    parser_train.add_argument('--steps-loss', type=int, default=50)
    parser_train.add_argument('--steps-plot', type=int, default=0)
    parser_train.add_argument('--steps-save', type=int, default=500)
Пример #43
0
def setup_parser(logger, demo_modes):
    help_title = 'Bootstrapping utility for BFT-SMaRt demos'
    parser_description = help_title + '\n\nDemos:\n\t' + '\n\t'.join(
        '%s' % (v.mode) for k, v in demo_modes.iteritems())

    parser = ArgumentParser(description=parser_description,
                            formatter_class=RawTextHelpFormatter)
    parser.add_argument("-v",
                        "--verbose",
                        dest="verbose",
                        action="store_true",
                        help="More verbose output")
    parser.add_argument("-d",
                        "--debug",
                        dest="debug",
                        action="store_true",
                        help="Set up remote debugging")
    parser.add_argument("-p",
                        "--classpath",
                        dest="classpath",
                        type=str,
                        default="bin/*:lib/*",
                        help="The classpath to execute [default: %(default)s]")
    parser.add_argument("-e",
                        "--environment",
                        dest="environment",
                        type=str,
                        default="~/projects/optSCORE/bft-smart/",
                        help="The execution directory [default: %(default)s]")
    parser.add_argument(
        "--server-port",
        dest="server_port",
        type=int,
        default=5000,
        help=
        "The first remote debugging port for the servers [default: %(default)d] "
    )
    parser.add_argument(
        "--client-port",
        dest="client_port",
        type=int,
        default=6000,
        help=
        "The first remote debugging port for the clients [default: %(default)d] "
    )
    parser.add_argument(
        "-r",
        "--replicas",
        dest="replicas",
        type=int,
        default=4,
        help="The number of replicas to use [default: %(default)d] ")
    parser.add_argument(
        "-c",
        "--clients",
        dest="clients",
        type=int,
        default=1,
        help="The number of clients to use [default: %(default)d] ")

    subparsers = parser.add_subparsers(title='demos',
                                       description='Some description')
    bftmap_parser = subparsers.add_parser(
        'bftmap',
        help=
        'BFTMap is a table of tables simulating a database. It creates a HashMap in the server and the replicas maintain the state of the table with the operations executed by the clients.'
    )
    bftmap_parser.set_defaults(func=parse_bftmap)

    counter_parser = subparsers.add_parser(
        'counter',
        help=
        'CounterServer is an application where clients submits messages to replica, messages are ordered and the throughput is displayed to the user. It has no real application but is useful to verify the system functioning and performance.'
    )
    counter_parser.add_argument(
        "-i",
        "--increment",
        dest="increment",
        type=int,
        default=1,
        help=
        "Specifies how much the counter will be incremented, if 0 the request will be read-only [default: %(default)d] "
    )
    counter_parser.add_argument(
        "-o",
        "--operations",
        dest="operations",
        type=int,
        default=1000,
        help="How many operations to perform [default: %(default)d] ")
    counter_parser.set_defaults(func=parse_counter)

    latency_parser = subparsers.add_parser(
        'latency', help='Microbenchmark for measurirng the request latency.')
    latency_parser.add_argument(
        "-q",
        "--requestSize",
        dest="requestSize",
        type=int,
        default=1024,
        help="Specifies the size of the request in byte [default: %(default)d] "
    )
    latency_parser.add_argument(
        "-p",
        "--replySize",
        dest="replySize",
        type=int,
        default=1024,
        help=
        "Specifies the size of the response in byte [default: %(default)d] ")
    latency_parser.add_argument(
        "-t",
        "--stateSize",
        dest="stateSize",
        type=int,
        default=102400,
        help="Specifies the size of the state in byte [default: %(default)d] ")
    latency_parser.add_argument(
        "-o",
        "--operations",
        dest="operations",
        type=int,
        default=1000,
        help="How many operations to perform [default: %(default)d] ")
    latency_parser.add_argument(
        "-m",
        "--measurementInterval",
        dest="measurementInterval",
        type=int,
        default=100,
        help=
        "At which intreval measurements are performed [default: %(default)d] ")
    latency_parser.add_argument(
        "-i",
        "--interval",
        dest="interval",
        type=int,
        default=100,
        help=
        "Time to sleep between two contigious messages in ms [default: %(default)d] "
    )
    latency_parser.add_argument(
        "-r",
        "--readOnly",
        dest="readOnly",
        type=str,
        default="false",
        help="If the requests are read only [default: %(default)s] ")

    latency_parser.set_defaults(func=parse_latency)

    return parser
Пример #44
0
            for config in progress.bar(asyncio.as_completed(tasks),
                                       label='configs',
                                       expected_size=len(tasks)):
                try:
                    config = await config
                except aiohttp.client_exceptions.ClientResponseError as e:
                    log.warn("{.request_info.url} not found".format(e))
                    continue
                json.dump(config, f)
                f.write('\n')


if __name__ == "__main__":
    from argparse import ArgumentParser
    parser = ArgumentParser(description=__doc__)
    subparsers = parser.add_subparsers(help='command help', dest='command')
    subparsers.required = True

    p = subparsers.add_parser('logs')
    p.set_defaults(func=fetch_logs)
    p.add_argument('-d',
                   '--datasets',
                   dest='include_datasets',
                   default=[],
                   nargs='+',
                   help='fetch only these datasets')

    p = subparsers.add_parser('configs')
    p.set_defaults(func=fetch_configs)

    for p in subparsers._name_parser_map.values():
Пример #45
0
def command_line():
    """
    Parameterze training and prediction scripts for encoder and decoder character RNN's
    """
    parser = ArgumentParser(prog='charrnn',
                            description='Train a neural network')
    parser.add_argument('--version',
                        action='version',
                        version='%(prog)s {version} {build}'.format(
                            version=version, build=build))
    parser.add_argument('--verbose',
                        '-v',
                        action='count',
                        default=0,
                        help='Keras verbose output')

    # Options
    model, window, batch, datasets = 'model.h5', 40, 128, 'datasets'
    parser.add_argument(
        '--model',
        '-m',
        default=model,
        type=str,
        metavar='file',
        help=
        'Specify the model hdf5 file to save to or load from: [default]: {model}'
        .format(model=model))
    parser.add_argument(
        '--batch',
        '-b',
        metavar='size',
        default=batch,
        type=int,
        help='Specify the input batch size for LSTM layers: [default]: {batch}'
        .format(batch=batch))
    parser.add_argument(
        '--datasets',
        '-t',
        metavar='directory',
        default=datasets,
        type=str,
        help=
        'Specify the directory where the datasets are located [default]: {datasets}'
        .format(datasets=datasets))

    # Subparser
    subparsers = parser.add_subparsers(
        help='Help train or produce output from your neural network')

    # Setup Defaults
    encoder = subparsers.add_parser(
        'train', help='Train your character recurrent neural net')
    encoder.set_defaults(which='encode')

    decoder = subparsers.add_parser(
        'decode', help='Output from previously trained network')
    decoder.set_defaults(which='decode')

    # Encoder
    dropout, layers, log_dir, lr = 0.2, 3, None, None
    epochs, optimizer, monitor, split = 100, 'nadam', 'val_loss', 0.15
    decay, decay_freq = 0.5, None

    encoder.add_argument(
        '--resume',
        action='count',
        help=
        'Resume from saved model file rather than creating a new model at {model}'
        .format(model=model))
    encoder.add_argument(
        '--window',
        '-w',
        default=window,
        type=int,
        metavar='length',
        help=
        'Specify the size of the window size to train on: [default]: {window}'.
        format(window=window))
    encoder.add_argument(
        '--log_dir',
        '-r',
        default=log_dir,
        type=str,
        metavar='directory',
        help=
        'Specify the output directory for tensorflow logs: [default]: {log_dir}'
        .format(log_dir=log_dir))
    encoder.add_argument(
        '--split',
        '-p',
        default=split,
        type=float,
        metavar='size',
        help=
        'Specify the split between validation and training data [default]: {split}'
        .format(split=split))
    encoder.add_argument(
        '--layers',
        '-l',
        default=layers,
        type=int,
        metavar='deep',
        help=
        'Specify the number of layers deep of LSTM nodes: [default]: {layers}'.
        format(layers=layers))
    encoder.add_argument(
        '--dropout',
        '-d',
        default=dropout,
        type=float,
        metavar='amount',
        help=
        'Amount of LSTM dropout to apply between 0.0 - 1.0: [default]: {dropout}'
        .format(dropout=dropout))
    encoder.add_argument(
        '--epochs',
        '-e',
        default=epochs,
        type=int,
        metavar='num',
        help='Specify for however many epochs to train over [default]: {epochs}'
        .format(epochs=epochs))
    encoder.add_argument(
        '--optimizer',
        '-o',
        default=optimizer,
        type=str,
        metavar='optimizer',
        help=
        'Specify optimizer used to train gradient descent: [default]: {optimizer}'
        .format(optimizer=optimizer))
    encoder.add_argument(
        '--monitor',
        '-n',
        default=monitor,
        type=str,
        metavar='monitor',
        help=
        'Specify value to monitor for training/building model: [defaut]: {monitor}'
        .format(monitor=monitor))
    encoder.add_argument(
        '--lr',
        '-a',
        default=lr,
        type=float,
        metavar='rate',
        help=
        'Set the learning rate for gradient descet optimizer: [default]: {lr}'.
        format(lr=lr))
    encoder.add_argument(
        '--decay',
        '-y',
        default=decay,
        type=float,
        metavar='rate',
        help=
        'The rate in which to reduce the learning rate on plateau [default]: {decay}'
        .format(decay=decay))
    encoder.add_argument(
        '--decay-freq',
        '-f',
        default=decay_freq,
        type=int,
        metavar='frequency',
        help=
        'The frequency in which to reduce the learning rate [default]: {decay_freq}'
        .format(decay_freq=decay_freq))

    # Decoder
    layers, temperature, output = 3, 0.8, 4000

    decoder.add_argument(
        '--temperature',
        '-t',
        default=temperature,
        type=float,
        metavar='t',
        help=
        'Set the temperature value for prediction on batch: [default]: {temperature}'
        .format(temperature=temperature))
    decoder.add_argument(
        '--output',
        '-o',
        default=output,
        type=int,
        metavar='size',
        help=
        'Set the desired size of the characters decoded: [default]: {output}'.
        format(output=output))

    return parser.parse_args()
Пример #46
0
def setup_parser(parser: ArgumentParser):
    """
    Parser setup for CLI

    :param parser: ArgumentParser
    :return: None
    """
    subparsers = parser.add_subparsers(help='Choose command')
    # Build parser
    build_parser = subparsers.add_parser(
        "build",
        help="build inverted index and save in binary format on hard drive",
        formatter_class=ArgumentDefaultsHelpFormatter)
    build_parser.add_argument(
        '-d',
        '--dataset',
        dest='dataset_path',
        required=True,
        help='Load target dataset',
    )
    build_parser.add_argument(
        '--stop-words',
        dest='stop_words',
        required=False,
        help='Path for file with stop words',
    )
    build_parser.add_argument(
        '-o',
        '--output',
        dest='output_path',
        required=True,
        help='Path to output index',
    )
    build_parser.set_defaults(command="build",
                              callback=build_and_dump_index_callback)
    # Query parser
    query_parser = subparsers.add_parser(
        "query",
        help="Query words and find in documents",
        formatter_class=ArgumentDefaultsHelpFormatter)
    query_parser.add_argument('-i',
                              '--index',
                              dest='index_path',
                              required=True,
                              help='Path for ready index')
    query_command_group = query_parser.add_mutually_exclusive_group(
        required=True)
    query_command_group.add_argument("--query-file-utf8",
                                     nargs=1,
                                     dest='query_file',
                                     metavar="QUERY_FILE_PATH",
                                     type=FileType('r', encoding="utf8"))
    query_command_group.add_argument("--query-file-cp1251",
                                     nargs=1,
                                     dest='query_file',
                                     metavar="QUERY_FILE_PATH",
                                     type=FileType('r', encoding="cp1251"))
    query_command_group.add_argument('-q',
                                     '--query',
                                     nargs="+",
                                     metavar='WORD',
                                     dest='words',
                                     help='Search query')
    query_parser.set_defaults(command="query", callback=query_callback)
Пример #47
0
def _get_openmdao_parser():
    """Sets up the plugin arg parser and all of its subcommand parsers."""

    top_parser = ArgumentParser()
    subparsers = top_parser.add_subparsers(title='commands')

    parser = subparsers.add_parser('list_testhosts',
                                   help='list hosts in testhosts config file')
    parser.add_argument(
        "-c",
        "--config",
        action='store',
        dest='cfg',
        metavar='CONFIG',
        default=get_cfg_file(),
        help=
        "Path of config file where info for remote testing/building hosts is located."
    )
    parser.add_argument("--filter",
                        action='append',
                        dest='filters',
                        default=[],
                        help="boolean expression to filter hosts")
    parser.add_argument("--host",
                        action='append',
                        dest='hosts',
                        metavar='HOST',
                        default=[],
                        help="Select host from config file to run on. "
                        "To run on multiple hosts, use multiple --host args.")
    parser.add_argument("--all",
                        action="store_true",
                        dest='allhosts',
                        help="Use all hosts found in testhosts.cfg file.")
    parser.set_defaults(func=list_testhosts)

    parser = subparsers.add_parser('docs', help='view the docs')
    parser.add_argument('plugin_dist_name',
                        nargs='?',
                        help='name of plugin distribution or class')
    parser.add_argument("-b",
                        "--browser",
                        action="store",
                        type=str,
                        dest='browser',
                        choices=webbrowser._browsers.keys(),
                        help="browser name")
    parser.set_defaults(func=openmdao_docs)

    parser = subparsers.add_parser('test',
                                   add_help=False,
                                   description="run the OpenMDAO test suite")
    parser.add_argument('-v',
                        '--verbose',
                        action='store_true',
                        help='display test progress')
    parser.add_argument('--skip-gui',
                        action='store_true',
                        help='skip GUI functional tests')
    parser.add_argument('packages',
                        metavar='package',
                        type=str,
                        nargs='*',
                        help='package to be tested')
    parser.set_defaults(func=test_openmdao)

    # the following subcommands will only be available in a dev build, because
    # openmdao.devtools is not part of a normal OpenMDAO release
    try:
        # these commands will only be available on windows machines if pywin32 is available
        import fabric
        from openmdao.devtools.push_docs import push_docs
        from openmdao.devtools.remotetst import test_branch
        from openmdao.devtools.remote_cfg import add_config_options

        parser = subparsers.add_parser('test_branch',
                                       help='run tests on remote machines')
        parser.add_argument(
            "-k",
            "--keep",
            action="store_true",
            dest='keep',
            help="Don't delete the temporary build directory. "
            "If testing on EC2, stop the instance instead of terminating it.")
        parser.add_argument("-f",
                            "--file",
                            action="store",
                            type=str,
                            dest='fname',
                            help="Pathname of a tarfile or URL of a git repo. "
                            "Defaults to the current repo.")
        parser.add_argument(
            "-b",
            "--branch",
            action="store",
            type=str,
            dest='branch',
            help="If file is a git repo, supply branch name here")
        parser.add_argument("--testargs",
                            action="store",
                            type=str,
                            dest='testargs',
                            default='',
                            help="args to be passed to openmdao test")
        parser.add_argument('-v',
                            '--verbose',
                            action='store_true',
                            help='display test progress')
        parser.add_argument('--skip-gui',
                            action='store_true',
                            help='skip GUI functional tests')
        parser = add_config_options(parser)
        parser.set_defaults(func=test_branch)

        parser = subparsers.add_parser(
            'push_docs', help='push the dev docs up to the server')
        parser.add_argument('host', help='host to push docs to')
        parser.add_argument(
            "-d",
            "--destination",
            action="store",
            type=str,
            dest="docdir",
            default='downloads',
            help="directory where dev_docs directory will be placed")
        parser.add_argument(
            "-n",
            "--nodocbuild",
            action="store_true",
            dest="nodocbuild",
            help=
            "Used for testing. The docs will not be rebuilt if they already exist."
        )
        parser.set_defaults(func=push_docs)

    except ImportError:
        pass

    try:
        from openmdao.devtools.build_docs import build_docs, test_docs
        parser = subparsers.add_parser('build_docs',
                                       help='build OpenMDAO docs')
        parser.add_argument("-v",
                            "--version",
                            action="store",
                            type=str,
                            dest="version",
                            help="the OpenMDAO version")
        parser.set_defaults(func=build_docs)

        parser = subparsers.add_parser('test_docs',
                                       help='run tests on the OpenMDAO docs')
        parser.set_defaults(func=test_docs)

    except ImportError:
        pass

    try:
        from openmdao.lib.architectures.mdao_test_suite import cli_arch_test_suite
        parser = subparsers.add_parser(
            'test_arch', help='run the MDAO architecture test suite')
        parser.set_defaults(func=cli_arch_test_suite)
        parser.add_argument(
            "-ea",
            "--exclude_arch",
            action="store",
            type=str,
            nargs="+",
            dest="excl_arch",
            help="Architectures class names to exclude from the test run.",
            default=[],
            metavar="arch_class_name")
        parser.add_argument(
            "-ia",
            "--include_arch",
            action="store",
            type=str,
            nargs="+",
            dest="inc_arch",
            help="Architectures class names to include in the test run.",
            default=[],
            metavar="arch_class_name")
        parser.add_argument(
            "-ip",
            "--include_prob",
            action="store",
            type=str,
            nargs="+",
            dest="inc_prob",
            help="OptProblems class names to include in the test run.",
            default=[],
            metavar="prob_class_name")
        parser.add_argument(
            "-ep",
            "--exclude_prob",
            action="store",
            type=str,
            nargs="+",
            dest="excl_prob",
            help="OptProblems class names to exclude from the test run.",
            default=[],
            metavar="prob_class_name")

    except ImportError:
        pass

    # the following subcommands will only be available in a gui build
    try:
        import openmdao.gui.omg as gui
        parser = subparsers.add_parser(
            'gui', help='launch the graphical user interface')
        # I'd like to do this but argparse doesn't have this signature
        #parser = subparsers.add_parser('gui', gui.get_argument_parser())
        # so I'll just copy and paste from openmdao.gui.omg :(
        parser.add_argument(
            "-p",
            "--port",
            type=int,
            dest="port",
            default=0,
            help="port to run server on (defaults to any available port)")
        parser.add_argument("-b",
                            "--browser",
                            dest="browser",
                            default="chrome",
                            help="preferred browser")
        parser.add_argument("-s",
                            "--server",
                            action="store_true",
                            dest="serveronly",
                            help="don't launch browser, just run server")
        parser.add_argument("-r",
                            "--reset",
                            action="store_true",
                            dest="reset",
                            help="reset project database")
        parser.add_argument("-d",
                            "--dev",
                            action="store_true",
                            dest="development",
                            help="enable development options")
        parser.set_defaults(func=gui.run)

    except ImportError:
        pass

    return top_parser
Пример #48
0
def create_parser() -> ArgumentParser:
    """
    Create a parser for the lookout.style.typos utility.

    :return: an ArgumentParser with an handler defined in the handler attribute.
    """
    parser = ArgumentParser(
        formatter_class=ArgumentDefaultsHelpFormatterNoNone)

    # General options
    slogging.add_logging_args(parser)
    subparsers = parser.add_subparsers(help="Commands")

    def add_parser(name, help):
        return subparsers.add_parser(
            name,
            help=help,
            formatter_class=ArgumentDefaultsHelpFormatterNoNone)

    # Prepare raw data for corrector
    prepare_parser = add_parser("prepare-data",
                                "Prepare raw dataset for corrector training.")
    prepare_parser.set_defaults(handler=prepare_data)
    add_config_arg(prepare_parser)

    # Train new fasttext model on gien data
    fasttext_parser = add_parser(
        "train-fasttext", "Train fasttext model on the given dataset"
        "of code identifiers.")
    fasttext_parser.set_defaults(handler=cli_train_fasttext)
    add_data_path_arg(fasttext_parser)
    add_config_arg(fasttext_parser)

    # Create train and test datasets with artificial typos
    datasets_parser = add_parser(
        "get-datasets", "Create the train and the test datasets of typos.")
    datasets_parser.set_defaults(handler=cli_get_datasets)
    add_data_path_arg(datasets_parser)
    add_config_arg(datasets_parser)

    # Create, train and evaluate new corrector model
    train_parser = add_parser(
        "train", "Create and train TyposCorrector model on the given data.")
    train_parser.set_defaults(handler=cli_train_corrector)
    train_parser.add_argument(
        "--train",
        required=False,
        type=str,
        default=DEFAULT_CORRECTOR_CONFIG["datasets"]["train_path"],
        help=
        ".csv dump of a Dataframe with columns Columns.Split and Columns.Frequency.",
    )
    train_parser.add_argument(
        "--test",
        required=False,
        type=str,
        default=DEFAULT_CORRECTOR_CONFIG["datasets"]["test_path"],
        help=
        ".csv dump of a Dataframe with columns Columns.Split and Columns.Frequency.",
    )
    train_parser.add_argument(
        "-v",
        "--vocabulary-path",
        required=False,
        type=str,
        default=os.path.join(
            DEFAULT_CORRECTOR_CONFIG["preparation"]["data_dir"],
            DEFAULT_CORRECTOR_CONFIG["preparation"]["vocabulary_filename"]),
        help="Path to a .csv file with vocabulary.",
    )
    train_parser.add_argument(
        "-f",
        "--frequencies-path",
        required=False,
        type=str,
        default=os.path.join(
            DEFAULT_CORRECTOR_CONFIG["preparation"]["data_dir"],
            DEFAULT_CORRECTOR_CONFIG["preparation"]["frequencies_filename"]),
        help="Path to a .csv file with tokens' frequencies.",
    )
    train_parser.add_argument(
        "-e",
        "--fasttext-path",
        required=False,
        type=str,
        default=DEFAULT_CORRECTOR_CONFIG["fasttext"]["path"],
        help="Path to a FastText model's dump (.bin).",
    )
    add_config_arg(train_parser)
    add_corrector_path_arg(train_parser)

    ########################################
    # One command to rule them all
    ########################################
    train_from_scratch_parser = add_parser(
        "train-from-scratch",
        "Create and train TyposCorrector model on the given data.")
    train_from_scratch_parser.set_defaults(handler=train_from_scratch)
    add_config_arg(train_from_scratch_parser)

    # Report for Typo Commits Dataset
    typo_commits_report_parser = add_parser(
        "typo-commits-report", "Generate report for Typo Commits Dataset.")
    typo_commits_report_parser.set_defaults(
        handler=generate_typos_report_entry)
    add_config_arg(typo_commits_report_parser)
    typo_commits_report_parser.add_argument(
        "-i",
        "--dataset",
        required=True,
        help=
        "csv file with commits with typos. Must contain wrong_id, correct_id, file, line, "
        "commit_fix, repo, commit_typo columns. It is possible to specify the xz compressed "
        "file.")
    typo_commits_report_parser.add_argument(
        "-o",
        "--output",
        required=True,
        help="Directory where to save results.")
    typo_commits_report_parser.add_argument("-b",
                                            "--bblfsh",
                                            help="Bblfsh address to use.")
    typo_commits_report_parser.add_argument(
        "--database",
        default=None,
        help="sqlite3 database path to store the models."
        "Temporary file is used if not set.")
    typo_commits_report_parser.add_argument(
        "--fs",
        default=None,
        help="Model repository file system root. "
        "Temporary directory is used if not set.")
    typo_commits_report_parser.add_argument(
        "--repos-cache",
        default=None,
        required=False,
        help=
        "Directory where to download repositories from the dataset. It is strongly "
        "recommended to set this parameter if there are more than 20 repositories "
        "in the dataset. Temporary directory is used if not set.")
    typo_commits_report_parser.add_argument(
        "--checkpoint-dir",
        default=None,
        help=
        "Directory where to save the intermediate reports, so that we do not have to start "
        "from scratch in case of an error. If a checkpoint is found in that directory the "
        "corresponding report is not calculated until --force flag is set.")
    typo_commits_report_parser.add_argument(
        "--force",
        action="store_true",
        default=False,
        help=
        "Always calculate reports from scratch disregarding`--checkpoint-dir`."
    )

    # Report for typos on identifiers datasets
    typos_report_parser = add_parser(
        "evaluate-fixes", "Generate report for typo-ed identifiers dataset.")
    typos_report_parser.set_defaults(handler=evaluate_typos_on_identifiers)
    add_config_arg(typos_report_parser)
    typos_report_parser.add_argument(
        "-d",
        "--dataset",
        required=False,
        help=
        "CSV file with with typos. The first two columns are wrong_id and correct_id."
        "It is possible to specify the xz compressed file. By default the "
        "identifiers from the Typo Commits Dataset are used.")
    typos_report_parser.add_argument(
        "-o",
        "--mistakes-output",
        required=False,
        help="CSV file where to write the wrong corrections.")

    return parser
def add_subparsers(parser: ArgumentParser):
    sp = parser.add_subparsers(dest='action')
    sp.required = True
    detect_usage.apply(sp.add_parser('detect'))
    collect_usage.apply(sp.add_parser('collect'))
Пример #50
0
def main():
    """Run the core."""
    parser = ArgumentParser()
    subs = parser.add_subparsers(dest='cmd')
    setup_parser = subs.add_parser('setup')
    setup_parser.add_argument('-e',
                              '--email',
                              dest='email',
                              required=True,
                              help='Email of the Google user.',
                              type=str)
    setup_parser.add_argument('-p',
                              '--password',
                              dest='pwd',
                              required=True,
                              help='Password of the Google user.',
                              type=str)
    setup_parser = subs.add_parser('seed')
    setup_parser.add_argument(
        '-d',
        '--driver',
        dest='driver',
        required=True,
        type=str,
        help=
        'Location of the Chrome driver. This can be downloaded by visiting http://chromedriver.chromium.org/downloads',
    )
    setup_parser.add_argument('-t',
                              '--timeout',
                              dest='timeout',
                              required=False,
                              type=int,
                              default=20)
    setup_parser = subs.add_parser('list')
    setup_parser = subs.add_parser('create')
    setup_parser.add_argument('-t',
                              '--term',
                              dest='term',
                              required=True,
                              help='Term to store.',
                              type=str)
    setup_parser.add_argument('--exact',
                              dest='exact',
                              action='store_true',
                              help='Exact matches only for term.')
    setup_parser.add_argument('-d',
                              '--delivery',
                              dest='delivery',
                              required=True,
                              choices=['rss', 'mail'],
                              help='Delivery method of results.')
    setup_parser.add_argument(
        '-f',
        '--frequency',
        dest='frequency',
        default="realtime",
        choices=['realtime', 'daily', 'weekly'],
        help='Frequency to send results. RSS only allows for realtime alerting.'
    )
    setup_parser = subs.add_parser('delete')
    setup_parser.add_argument('--id',
                              dest='term_id',
                              required=True,
                              help='ID of the term to find for deletion.',
                              type=str)
    args = parser.parse_args()

    if args.cmd == 'setup':
        if not os.path.exists(CONFIG_PATH):
            os.makedirs(CONFIG_PATH)
        if not os.path.exists(CONFIG_FILE):
            json.dump(CONFIG_DEFAULTS,
                      open(CONFIG_FILE, 'w'),
                      indent=4,
                      separators=(',', ': '))
        config = CONFIG_DEFAULTS
        config['email'] = args.email
        config['password'] = str(obfuscate(args.pwd, 'store'))
        json.dump(config,
                  open(CONFIG_FILE, 'w'),
                  indent=4,
                  separators=(',', ': '))

    config = json.load(open(CONFIG_FILE))
    if config.get('py2', PY2) != PY2:
        raise Exception(
            "Python versions have changed. Please run `setup` again to reconfigure the client."
        )
    if config['password'] == '':
        raise Exception("Run setup before any other actions!")

    if args.cmd == 'seed':
        config['password'] = obfuscate(str(config['password']), 'fetch')
        ga = GoogleAlerts(config['email'], config['password'])
        with contextlib.closing(webdriver.Chrome(args.driver)) as driver:
            driver.get(ga.LOGIN_URL)
            wait = ui.WebDriverWait(driver, 10)  # timeout after 10 seconds
            inputElement = driver.find_element_by_name('Email')
            inputElement.send_keys(config['email'])
            inputElement.submit()
            print("[*] Filled in email address and submitted.")
            time.sleep(3)
            inputElement = driver.find_element_by_id('Passwd')
            inputElement.send_keys(config['password'])
            inputElement.submit()
            print("[*] Filled in password and submitted.")
            print("[!] Waiting for the authentication cookie or %d seconds" %
                  args.timeout)
            for _ in range(0, args.timeout):
                cookies = driver.get_cookies()
                if [x for x in cookies if x['name'] == AUTH_COOKIE_NAME]:
                    break
                time.sleep(1)
            collected = dict()
            for cookie in cookies:
                collected[str(cookie['name'])] = str(cookie['value'])
            with open(SESSION_FILE, 'wb') as f:
                pickle.dump(collected, f, protocol=2)
        print("[$] Session has been seeded, google-alerts is ready for use.")

    if args.cmd == 'list':
        config['password'] = obfuscate(str(config['password']), 'fetch')
        ga = GoogleAlerts(config['email'], config['password'])
        ga.authenticate()
        print(json.dumps(ga.list(), indent=4))

    if args.cmd == 'create':
        config['password'] = obfuscate(str(config['password']), 'fetch')
        ga = GoogleAlerts(config['email'], config['password'])
        ga.authenticate()
        alert_frequency = 'as_it_happens'
        if args.frequency == 'realtime':
            alert_frequency = 'as_it_happens'
        elif args.frequency == 'daily':
            alert_frequency = 'at_most_once_a_day'
        else:
            alert_frequency = 'at_most_once_a_week'

        monitor = ga.create(
            args.term, {
                'delivery': args.delivery.upper(),
                'alert_frequency': alert_frequency.upper(),
                'exact': args.exact
            })
        print(json.dumps(monitor, indent=4))

    if args.cmd == 'delete':
        config['password'] = obfuscate(str(config['password']), 'fetch')
        ga = GoogleAlerts(config['email'], config['password'])
        ga.authenticate()
        result = ga.delete(args.term_id)
        if result:
            print("%s was deleted" % args.term_id)
Пример #51
0
    queryString = queryString.rstrip("&")
    if queryString == '?':
        queryString = ''
    print entity_list(baseUrl, args['auth'], endpoint, queryString)

if __name__ == "__main__":
    # The main argument parser
    parser = ArgumentParser(description="CLI for accessing the AGORA methods repository. Currently only handles method push")
    
    # Core application arguments
    parser.add_argument('-a', '--auth', dest='auth', action='store', help='Oath token key=value pair for passing in request cookies')
    parser.add_argument('-u', '--url', dest='agoraUrl', default='agora-prod.broadinstitute.org', action='store', help='Agora location. Default is agora-prod.broadinstitute.org')
    endpoint_group = parser.add_mutually_exclusive_group(required=True)
    endpoint_group.add_argument('-c', '--configurations', action='store_true', help='Operate on task-configurations, via the /configurations endpoint')
    endpoint_group.add_argument('-m', '--methods', action='store_true', help='Operate on tasks and workflows, via the /methods endpoint')    
    subparsers = parser.add_subparsers(help='Agora Methods Repository actions')
    
    # POST arguments
    push_parser = subparsers.add_parser('push', description='Push a method to the Agora Methods Repository', help='Push a method to the Agora Methods Repository')
    push_parser.add_argument('-s', '--namespace', dest='namespace', action='store', help='The namespace for method addition. Default value is your user login name')
    push_parser.add_argument('-n', '--name', dest='name', action='store', help='The method name to provide for method addition. Default is the name of the PAYLOAD_FILE.')
    push_parser.add_argument('-d', '--documentation', dest='docs', action='store', help='A file containing user documentation. Must be <10kb. May be plain text. Marking languages such as HTML or Github markdown are also supported')
    push_parser.add_argument('-t', '--entityType', dest='entityType', action='store', help='The type of the entities you are trying to get', choices=['Task', 'Workflow', 'Configuration'], required=True)
    push_parser.add_argument('-y', '--synopsis', dest='synopsis', action='store', help='The synopsis for the entity you are pushing')
    push_parser.add_argument('PAYLOAD_FILE', help='A file containing the payload. For configurations, JSON. For tasks + workflows, the method description in WDL')
    push_parser.set_defaults(func=push)
    
    # GET (namespace/name/id) arguments
    pull_parser = subparsers.add_parser('pull', description='Get a specific method snapshot from the Agora Methods Repository', help='Get a specific method snapshot from the Agora Methods Repository')
    pull_parser.add_argument('-s', '--namespace', dest='namespace', action='store', help='The namespace for the entity you are trying to get', required=True)
    pull_parser.add_argument('-n', '--name', dest='name', action='store', help='The name of the entity you are trying to get', required=True)
Пример #52
0
    if args.cmd == 'export':
        export_data(args)
    elif args.cmd == 'import':
        import_data(args)


    

if __name__ == "__main__":
    arg_parser = ArgumentParser(description="import/export ams data")
    
    arg_parser.add_argument(
        "--mongo", help="ams mongo host", dest="mongo", default="localhost:27017", metavar="string")
    arg_parser.add_argument(
        "--brokers", help="kafka broker list", dest="brokers", default="localhost:9092", metavar="string")
    arg_parser.add_argument(
        "--timeout", help="broker consume timeout (ms)", dest="timeout", default=300, metavar="int")
    arg_parser.add_argument(
        "--data", help="path where to export/import data", dest="data", default="./", metavar="int")
    arg_parser.add_argument(
        "--advance-offset", help="when importing advance offset to be aligned with original cluster", dest="advance", default=False, metavar="bool")
    arg_parser.add_argument(
        "--batch", help="how many messages per batch should be published", dest="batch_size", default=1000, metavar="int")
    cmd = arg_parser.add_subparsers(dest="cmd")
    cmd.add_parser('import', help='import ams data to kafka')
    cmd.add_parser('export', help='export ams data from kafka')
    # Parse the command line arguments accordingly and introduce them to
    # main...
    sys.exit(main(arg_parser.parse_args()))

Пример #53
0
def construct_parser(description, epilog=''):

    # construct main module
    module_args = {
        'description': description,
        'usage': __command__,
        'formatter_class':
        SubcommandHelpFormatter  # remove sub-command braces in help
    }
    if epilog:
        module_args['epilog'] = epilog
    parser = ArgumentParser(**module_args)
    current_version = '%s %s' % (__module__, __version__)
    parser.add_argument('-v',
                        '--version',
                        action='version',
                        version=current_version)

    # construct command parsing method
    help_details = {
        'title': 'list of commands'  # title for sub-commands list in help
    }
    subparsers = parser.add_subparsers(**help_details)

    # retrieve module path
    module_path = find_spec(__module__).submodule_search_locations[0]

    # compile command models
    compile_kwargs = {
        'folder_path': '%s/commands/' % module_path,
        'module_name': __module__,
        'fields_model': fields_model,
        'preferred_order': __order__
    }
    command_list = compile_commands(**compile_kwargs)

    # construct each command
    for command_details in command_list:

        # add command details to parser
        try:
            details = {
                'description':
                command_details['description'],
                'help':
                command_details['help'],
                'formatter_class':
                lambda prog:
                HelpFormatter(prog, max_help_position=30, width=80
                              )  # adjusts column width to options
            }
            if command_details['epilog']:
                details['epilog'] = command_details['epilog']
            cmd_args = subparsers.add_parser(command_details['name'],
                                             **details)

            # construct default arguments
            cmd_args.set_defaults(**command_details['default_args'])

            # construct positional arguments
            for argument in command_details['positional_args']:
                cmd_args.add_argument(argument['args'], **argument['kwargs'])

    # construct optional arguments
            for argument in command_details['optional_args']:
                cmd_args.add_argument(*argument['args'], **argument['kwargs'])

    # construct mutually exclusive arguments
            for key in command_details['exclusive_args'].keys():
                exclusive_options = cmd_args.add_mutually_exclusive_group()
                for argument in command_details['exclusive_args'][key]:
                    exclusive_options.add_argument(*argument['args'],
                                                   **argument['kwargs'])

    # remove command from module if there is model parsing error
        except Exception as err:
            # print(err)
            pass

    return parser
Пример #54
0
class Command(OrderedDict):
    def __init__(self,
                 args=None,
                 parent_commands=None,
                 identifier=None,
                 help_string=None):
        OrderedDict.__init__(self)
        LOGGER.verbose("Initialized a %s Command", identifier)
        if args is None:
            self.args = argv[1:]
        else:
            self.args = args
        LOGGER.debug("Received args %s", self.args)
        self.identifier = identifier
        self.help_string = help_string
        LOGGER.spam("help_string: %s", help_string)
        self.parser = None
        if parent_commands:
            self.prog = "%s %s" % (parent_commands, identifier)
        else:
            self.prog = identifier
        LOGGER.spam("PROG: %s", self.prog)
        self.subparsers = None
        self.arguments = []
        self.results = []
        self.pre_execution = OrderedDict()
        self.handlers = OrderedDict()
        self.post_execution = OrderedDict()

    def add_parser(self, subparsers=None):
        LOGGER.debug("Defining the root parser on %s", self.identifier)
        self.parser = ArgumentParser(prog="git %s" % self.prog,
                                     add_help=False,
                                     description=self.help_string,
                                     conflict_handler='resolve')

    def add_subparsers(self):
        LOGGER.debug("Attaching a subparser on %s", self.identifier)
        self.subparsers = self.parser.add_subparsers(dest='next_command',
                                                     metavar='Action',
                                                     help='Available actions')

    def attach_actions(self):
        if len(self.items()) > 0:
            LOGGER.verbose("Adding %s's Action arguments", self.identifier)
            self.add_subparsers()
        else:
            LOGGER.verbose("%s has no actions to add", self.identifier)
        for _, action in self.items():
            action.attach_arguments(self.subparsers)

    def attach_arguments(self):
        LOGGER.debug("Adding %s's own arguments", self.identifier)
        for argument in self.arguments:
            LOGGER.spam(argument)
            argument.attach_arguments(self.parser)

    def parse_args(self):
        LOGGER.debug('Attempting to parse args')
        return self.parser.parse_known_args(self.args)

    def parse(self, *args, **kwargs):
        self.add_parser()
        self.attach_actions()
        self.attach_arguments()
        self.results = self.parse_args()
        LOGGER.spam("%s parsed out %s", self.identifier, self.results[0])
        LOGGER.spam("%s left %s", self.identifier, self.results[0])

    def process(self, *args, **kwargs):
        if hasattr(self.results[0],
                   'next_command') and self.results[0].next_command:
            action = self.results[0].next_command
            LOGGER.info("%s triggered Action %s", self.identifier, action)
            return self[action].process(self.prog, *self.results)
        LOGGER.notice("%s.process() did not fire an action", self.identifier)

    def load_specific_handler(self, source=None, destination=None):
        LOGGER.debug('Loading specific handler')
        if source is None:
            return
        for key, args in source.items():
            destination[key] = args

    def load_handlers(self, *args, **kwargs):
        LOGGER.debug('Loading argument handlers')
        for argument in self.arguments:
            self.load_specific_handler(argument.load_handlers(), self.handlers)
            self.load_specific_handler(argument.assign_pre_tasks(),
                                       self.pre_execution)
            self.load_specific_handler(argument.assign_post_tasks(),
                                       self.post_execution)

    def run_handlers(self, handlers):
        LOGGER.debug('Running specific handler')
        for key, args in handlers.items():
            LOGGER.spam("Handler: %s", key)
            LOGGER.spam("Args: %s", args)
            self.handlers[key](self, self.results[0], *args)

    def __pre_execute(self, *args, **kwargs):
        LOGGER.debug("Running %s's pre_execute handlers", self.identifier)
        self.run_handlers(self.pre_execution)
        self.pre_execute(*args, **kwargs)

    def pre_execute(self, *args, **kwargs):
        """"""

    def execute(self, *args, **kwargs):
        """"""

    def __post_execute(self, *args, **kwargs):
        LOGGER.debug("Running %s's post_execution handlers", self.identifier)
        self.run_handlers(self.post_execution)
        self.post_execute(*args, **kwargs)

    def post_execute(self, *args, **kwargs):
        """"""

    def prosecute_command(self, *args, **kwargs):
        LOGGER.debug("Fully executing %s", self.identifier)
        self.__pre_execute(self, *args, **kwargs)
        self.execute(self, *args, **kwargs)
        self.__post_execute(self, *args, **kwargs)

    def complete(self, *args, **kwargs):
        self.parse(self, *args, **kwargs)
        self.process(self, *args, **kwargs)
        self.load_handlers(self, *args, **kwargs)
        self.prosecute_command(self, *args, **kwargs)
        LOGGER.info("%s has finished everything", self.identifier)
Пример #55
0
class CLI:
    """ A CLI Based On argparse
        @command: used to command without arguments
        @option: used to command with arguments
        Don't mix this two decorators!
    """
    # Don't used this string as an argument
    SUBCOMMAND_MAGIC_FUNC = '__SUBCOMMAND_MAGIC_FUNC__'

    def __init__(self,
                 prog,
                 version=None,
                 usage=None,
                 description=None,
                 epilog=None,
                 add_help=True):
        settings = dict(
            prog=prog,
            usage=usage,
            description=description,
            epilog=epilog,
            add_help=add_help,
        )
        self.parser = ArgumentParser(**settings)
        if version:
            self.parser.add_argument('-v',
                                     '--version',
                                     action='version',
                                     version='%(prog)s v{}'.format(version))
        self.subparsers = self.parser.add_subparsers(title='subcommands')
        self.subcommands = {}

    def command(self, **kwargs):
        def wrapper(_callable):
            title = kwargs.pop('title', None)
            description = kwargs.pop('description', None)
            if not title:
                title = _callable.__name__
            _parser = self.subparsers.add_parser(title,
                                                 description=description)
            _parser.set_defaults(**{self.SUBCOMMAND_MAGIC_FUNC: _callable})
            self.subcommands[title] = _parser
            return _callable

        return wrapper

    def add_command(self, title, _callable, description=None):
        _parser = self.subparsers.add_parser(title, description=description)
        _parser.set_defaults(**{self.SUBCOMMAND_MAGIC_FUNC: _callable})
        self.subcommands[title] = _parser
        return self

    def option(self, *args, **kwargs):
        def wrapper(_callable):
            title = _callable.__name__
            _parser = self.subcommands.get(title, None)
            if not _parser:
                _parser = self.subparsers.add_parser(title)
            _parser.set_defaults(**{self.SUBCOMMAND_MAGIC_FUNC: _callable})
            _parser.add_argument(*args, **kwargs)
            self.subcommands[title] = _parser
            return _callable

        return wrapper

    def add_argument(self, *args, **kwargs):
        self.parser.add_argument(*args, **kwargs)
        return self

    def run(self):
        namespace = self.parser.parse_args()
        args = namespace.__dict__
        callback = args.pop(self.SUBCOMMAND_MAGIC_FUNC, None)
        if callback:
            callback(**args)
Пример #56
0
from identifiers_client.identifiers_api import (identifiers_client,
                                                IdentifierClientError,
                                                IdentifierNotLoggedIn)
from identifiers_client.config import config
from identifiers_client.login import (LOGGED_IN_RESPONSE, LOGGED_OUT_RESPONSE,
                                      check_logged_in, do_link_login_flow,
                                      do_local_server_login_flow,
                                      revoke_tokens)
from identifiers_client.helpers import (subcommand, argument,
                                        clear_internal_args)
from argparse import ArgumentParser

log = logging.getLogger(__name__)

cli = ArgumentParser()
subparsers = cli.add_subparsers(dest="subcommand")

_namespace_skin_props = [
    'header_background', 'header_icon_url', 'header_icon_link', 'header_text',
    'page_title', 'favicon_url', 'preamble_text'
]


@subcommand(
    [
        argument('--force',
                 action='store_true',
                 default=False,
                 help=('Do a fresh login, ignoring any existing credentials')),
        argument("--no-local-server",
                 action='store_true',
Пример #57
0
def main():
    psr = ArgumentParser(description="RadVel: The Radial Velocity Toolkit",
                         prog='radvel')

    subpsr = psr.add_subparsers(title="subcommands", dest='subcommand')

    # In the parent parser, we define arguments and options common to
    # all subcommands.
    psr_parent = ArgumentParser(add_help=False)
    psr_parent.add_argument(
        '-d',
        dest='outputdir',
        type=str,
        help="Working directory. Default is the same as the \
        configuration file (without .py)")
    psr_parent.add_argument('-s',
                            '--setup',
                            dest='setupfn',
                            type=str,
                            help="Setup file.")
    psr_parent.add_argument('--decorr',
                            dest='decorr',
                            action='store_true',
                            default=False,
                            help="Include decorrelation in likelihood.")

    # Fitting
    psr_fit = subpsr.add_parser('fit',
                                parents=[psr_parent],
                                description="Perform max-likelihood fitting")
    psr_fit.set_defaults(func=radvel.driver.fit)

    # Plotting
    psr_plot = subpsr.add_parser(
        'plot',
        parents=[psr_parent],
    )
    psr_plot.add_argument('-t',
                          '--type',
                          type=str,
                          nargs='+',
                          choices=['rv', 'corner', 'trend', 'derived'],
                          help="type of plot(s) to generate")
    psr_plot.add_argument(
        '--plotkw',
        dest='plotkw',
        action='store',
        default="{}",
        type=eval,
        help='''
        Dictionary of keywords sent to rv_multipanel_plot. 
        E.g. --plotkw "{'yscale_auto': True}"'
        ''',
    )

    psr_plot.set_defaults(func=radvel.driver.plots)

    # MCMC
    psr_mcmc = subpsr.add_parser('mcmc',
                                 parents=[psr_parent],
                                 description="Perform MCMC exploration")
    psr_mcmc.add_argument(
        '--nsteps',
        dest='nsteps',
        action='store',
        default=10000,
        type=float,
        help='Number of steps per chain [10000]',
    )
    psr_mcmc.add_argument(
        '--nwalkers',
        dest='nwalkers',
        action='store',
        default=50,
        type=int,
        help='Number of walkers. [50]',
    )
    psr_mcmc.add_argument('--nensembles',
                          dest='ensembles',
                          action='store',
                          default=8,
                          type=int,
                          help='''\
Number of ensembles. Will be run in parallel on separate CPUs [8]
''')
    psr_mcmc.set_defaults(func=radvel.driver.mcmc)

    # Derive hysical parameters
    psr_physical = subpsr.add_parser(
        'derive',
        parents=[psr_parent],
        description="Multiply MCMC chains by physical parameters. MCMC must" +
        "be run first")

    psr_physical.set_defaults(func=radvel.driver.derive)

    # BIC
    psr_bic = subpsr.add_parser(
        'bic',
        parents=[psr_parent],
    )
    psr_bic.add_argument('-t',
                         '--type',
                         type=str,
                         nargs='+',
                         choices=['nplanets'],
                         help="type of BIC comparison to perform")
    psr_bic.set_defaults(func=radvel.driver.bic)

    # Tables
    psr_table = subpsr.add_parser(
        'table',
        parents=[psr_parent],
    )
    psr_table.add_argument('-t',
                           '--type',
                           type=str,
                           nargs='+',
                           choices=['params', 'priors', 'nplanets'],
                           help="type of plot(s) to generate")
    psr_table.add_argument(
        '--header',
        action='store_true',
        help="included latex column header. Default just prints data rows")

    psr_table.set_defaults(func=radvel.driver.tables)

    # Report
    psr_report = subpsr.add_parser(
        'report',
        parents=[psr_parent],
        description="Merge output tables and plots into LaTeX report")
    psr_report.add_argument(
        '--comptype',
        dest='comptype',
        action='store',
        default='nplanets',
        type=str,
        help='Type of BIC model comparison table to include. \
        Default: nplanets')

    psr_report.add_argument('--latex-compiler',
                            default='pdflatex',
                            type=str,
                            help='Path to latex compiler')

    psr_report.set_defaults(func=radvel.driver.report)

    args = psr.parse_args()

    if args.outputdir is None:
        setupfile = args.setupfn
        print(setupfile)
        system_name = os.path.basename(setupfile).split('.')[0]
        outdir = os.path.join('./', system_name)
        args.outputdir = outdir

    if not os.path.isdir(args.outputdir):
        os.mkdir(outdir)

    args.func(args)
    def _generate_args(self, prog):
        def add_options(parser, positional, kwargs):
            kwargs_opts = {
                "template": (
                    "-t",
                    "--template",
                    dict(
                        default="generic",
                        type=str,
                        help="Setup template for use with 'init'",
                    ),
                ),
                "message": (
                    "-m",
                    "--message",
                    dict(
                        type=str, help="Message string to use with 'revision'"
                    ),
                ),
                "sql": (
                    "--sql",
                    dict(
                        action="store_true",
                        help="Don't emit SQL to database - dump to "
                        "standard output/file instead. See docs on "
                        "offline mode.",
                    ),
                ),
                "tag": (
                    "--tag",
                    dict(
                        type=str,
                        help="Arbitrary 'tag' name - can be used by "
                        "custom env.py scripts.",
                    ),
                ),
                "head": (
                    "--head",
                    dict(
                        type=str,
                        help="Specify head revision or <branchname>@head "
                        "to base new revision on.",
                    ),
                ),
                "splice": (
                    "--splice",
                    dict(
                        action="store_true",
                        help="Allow a non-head revision as the "
                        "'head' to splice onto",
                    ),
                ),
                "depends_on": (
                    "--depends-on",
                    dict(
                        action="append",
                        help="Specify one or more revision identifiers "
                        "which this revision should depend on.",
                    ),
                ),
                "rev_id": (
                    "--rev-id",
                    dict(
                        type=str,
                        help="Specify a hardcoded revision id instead of "
                        "generating one",
                    ),
                ),
                "version_path": (
                    "--version-path",
                    dict(
                        type=str,
                        help="Specify specific path from config for "
                        "version file",
                    ),
                ),
                "branch_label": (
                    "--branch-label",
                    dict(
                        type=str,
                        help="Specify a branch label to apply to the "
                        "new revision",
                    ),
                ),
                "verbose": (
                    "-v",
                    "--verbose",
                    dict(action="store_true", help="Use more verbose output"),
                ),
                "resolve_dependencies": (
                    "--resolve-dependencies",
                    dict(
                        action="store_true",
                        help="Treat dependency versions as down revisions",
                    ),
                ),
                "autogenerate": (
                    "--autogenerate",
                    dict(
                        action="store_true",
                        help="Populate revision script with candidate "
                        "migration operations, based on comparison "
                        "of database to models.",
                    ),
                ),
                "head_only": (
                    "--head-only",
                    dict(
                        action="store_true",
                        help="Deprecated.  Use --verbose for "
                        "additional output",
                    ),
                ),
                "rev_range": (
                    "-r",
                    "--rev-range",
                    dict(
                        action="store",
                        help="Specify a revision range; "
                        "format is [start]:[end]",
                    ),
                ),
                "indicate_current": (
                    "-i",
                    "--indicate-current",
                    dict(
                        action="store_true",
                        help="Indicate the current revision",
                    ),
                ),
            }
            positional_help = {
                "directory": "location of scripts directory",
                "revision": "revision identifier",
                "revisions": "one or more revisions, or 'heads' for all heads",
            }
            for arg in kwargs:
                if arg in kwargs_opts:
                    args = kwargs_opts[arg]
                    args, kw = args[0:-1], args[-1]
                    parser.add_argument(*args, **kw)

            for arg in positional:
                if arg == "revisions":
                    subparser.add_argument(
                        arg, nargs="+", help=positional_help.get(arg)
                    )
                else:
                    subparser.add_argument(arg, help=positional_help.get(arg))

        parser = ArgumentParser(prog=prog)
        parser.add_argument(
            "-c",
            "--config",
            type=str,
            default="alembic.ini",
            help="Alternate config file",
        )
        parser.add_argument(
            "-n",
            "--name",
            type=str,
            default="alembic",
            help="Name of section in .ini file to " "use for Alembic config",
        )
        parser.add_argument(
            "-x",
            action="append",
            help="Additional arguments consumed by "
            "custom env.py scripts, e.g. -x "
            "setting1=somesetting -x setting2=somesetting",
        )
        parser.add_argument(
            "--raiseerr",
            action="store_true",
            help="Raise a full stack trace on error",
        )
        subparsers = parser.add_subparsers()

        for fn in [getattr(command, n) for n in dir(command)]:
            if (
                inspect.isfunction(fn)
                and fn.__name__[0] != "_"
                and fn.__module__ == "alembic.command"
            ):

                spec = compat.inspect_getargspec(fn)
                if spec[3]:
                    positional = spec[0][1 : -len(spec[3])]
                    kwarg = spec[0][-len(spec[3]) :]
                else:
                    positional = spec[0][1:]
                    kwarg = []

                # parse first line(s) of helptext without a line break
                help_ = fn.__doc__
                if help_:
                    help_text = []
                    for line in help_.split("\n"):
                        if not line.strip():
                            break
                        else:
                            help_text.append(line.strip())
                else:
                    help_text = ""
                subparser = subparsers.add_parser(
                    fn.__name__, help=" ".join(help_text)
                )
                add_options(subparser, positional, kwarg)
                subparser.set_defaults(cmd=(fn, positional, kwarg))
        self.parser = parser
Пример #59
0
def _get_plugin_parser():
    """Sets up the plugin arg parser and all of its subcommand parsers."""

    top_parser = ArgumentParser()
    subparsers = top_parser.add_subparsers(title='commands')

    parser = subparsers.add_parser('list', help="List installed plugins")
    parser.usage = "plugin list [options]"
    parser.add_argument("--github",
                        help='List plugins in the official Openmdao-Plugins'
                        ' repository on github',
                        action='store_true')
    parser.add_argument("-b",
                        "--builtin",
                        help='List all installed plugins that are part of the'
                        ' OpenMDAO distribution',
                        action='store_true')
    parser.add_argument("-e",
                        "--external",
                        help='List all installed plugins that are not part of'
                        ' the OpenMDAO distribution',
                        action='store_true')
    parser.add_argument(
        "-g",
        "--group",
        action="append",
        type=str,
        dest='groups',
        default=[],
        choices=[p.split('.', 1)[1] for p in plugin_groups.keys()],
        help="specify plugin group")
    parser.set_defaults(func=plugin_list)

    parser = subparsers.add_parser('install',
                                   help="install an OpenMDAO plugin into the"
                                   " current environment")
    parser.usage = "plugin install [plugin_distribution] [options]"
    parser.add_argument('dist_name',
                        help='name of plugin distribution'
                        ' (defaults to distrib found in current dir)',
                        nargs='?')
    parser.add_argument("--github",
                        help='Find plugin in the official OpenMDAO-Plugins'
                        ' repository on github',
                        action='store_true')
    parser.add_argument("-f",
                        "--find-links",
                        action="store",
                        type=str,
                        dest='findlinks',
                        default='http://openmdao.org/dists',
                        help="URL of find-links server")
    parser.add_argument("--all",
                        help='Install all plugins in the official'
                        ' OpenMDAO-Plugins repository on github',
                        action='store_true')
    parser.set_defaults(func=plugin_install)

    parser = subparsers.add_parser('build_docs',
                                   help="build sphinx doc files for a plugin")
    parser.usage = "plugin build_docs <dist_dir_path>"
    parser.add_argument('dist_dir_path',
                        default='.',
                        help='path to distribution source directory')
    parser.add_argument("-s",
                        "--srcdir",
                        action="store",
                        type=str,
                        dest='srcdir',
                        default='src',
                        help="top directory in the distribution where python"
                        " source is located")
    parser.set_defaults(func=plugin_build_docs)

    parser = subparsers.add_parser('docs', help="display docs for a plugin")
    parser.usage = "plugin docs <plugin_dist_name>"

    parser.add_argument('plugin_dist_name', help='name of plugin distribution')
    parser.add_argument("-b",
                        "--browser",
                        action="store",
                        type=str,
                        dest='browser',
                        choices=webbrowser._browsers.keys(),
                        help="browser name")
    parser.set_defaults(func=plugin_docs)

    parser = subparsers.add_parser('quickstart',
                                   help="generate some skeleton"
                                   " files for a plugin")
    parser.usage = "plugin quickstart <dist_name> [options]"
    parser.add_argument('dist_name', help='name of distribution')
    parser.add_argument("-v",
                        "--version",
                        action="store",
                        type=str,
                        dest='version',
                        default='0.1',
                        help="version id of the plugin (defaults to 0.1)")
    parser.add_argument("-c",
                        "--class",
                        action="store",
                        type=str,
                        dest='classname',
                        help="plugin class name")
    parser.add_argument("-d",
                        "--dest",
                        action="store",
                        type=str,
                        dest='dest',
                        default='.',
                        help="directory where new plugin directory will be"
                        " created (defaults to current dir)")
    parser.add_argument("-g",
                        "--group",
                        action="store",
                        type=str,
                        dest='group',
                        default='openmdao.component',
                        help="specify plugin group %s (defaults to"
                        " 'openmdao.component')" % plugin_groups.keys())
    parser.set_defaults(func=plugin_quickstart)

    parser = subparsers.add_parser('makedist',
                                   help="create a source"
                                   " distribution for a plugin")
    parser.usage = "plugin makedist [dist_dir_path]"
    parser.add_argument('dist_dir_path',
                        nargs='?',
                        default='.',
                        help='directory where plugin distribution is found'
                        ' (defaults to current dir')
    parser.add_argument("-s",
                        "--srcdir",
                        action="store",
                        type=str,
                        dest='srcdir',
                        default='src',
                        help="top directory in the distribution where python"
                        " source is located")
    parser.set_defaults(func=plugin_makedist)

    return top_parser
Пример #60
0
class MainArgumentParser(object):
    def __init__(self, environment_registry):
        self.environments = environment_registry
        self.arg_parser = ArgumentParser(
            'swid_generator',
            description='Generate SWID tags and Software IDs'
            'from dpkg, pacman or rpm package manager')
        self.arg_parser.add_argument('-v',
                                     '--version',
                                     action='version',
                                     version='%(prog)s ' + meta.version)

        # Parent parser for common options
        parent_parser = ArgumentParser(add_help=False)

        parent_parser.add_argument(
            '--env',
            choices=environment_registry.get_environment_strings(),
            default='auto',
            help=
            'The package manager environment to be used. Defaults to "auto". '
            'If the environment can not be autodetected, '
            'the exit code is set to 3.')
        parent_parser.add_argument(
            '--doc-separator',
            dest='document_separator',
            default='\n',
            help='The separator string by which the SWID XML '
            'documents are separated. Example: For '
            'one newline, use $\'\\n\'.')
        parent_parser.add_argument(
            '--regid',
            dest='regid',
            type=regid_string,
            default=regid_string(settings.DEFAULT_REGID),
            help='The regid to use in the generated output. '
            'May not contain any whitespace '
            'characters. Default is "%s".' % settings.DEFAULT_REGID)
        parent_parser.add_argument(
            '--id-prefix',
            dest='id_prefix',
            help='Override the default {os}-{arch}- tagId prefix.')
        parent_parser.add_argument(
            '--dpkg-include-package-arch',
            action='store_true',
            default=False,
            help='Include package architecture in tagId and version, for dpkg.'
        )

        subparsers = self.arg_parser.add_subparsers(help='Commands: ',
                                                    dest='command')

        # Subparser for swid command
        swid_parser = subparsers.add_parser('swid',
                                            help='SWID tag output',
                                            parents=[parent_parser],
                                            description='Generate SWID tags.')

        swid_parser.add_argument(
            '--entity-name',
            dest='entity_name',
            type=entity_name_string,
            default=entity_name_string(settings.DEFAULT_ENTITY_NAME),
            help='The entity name used in the <Entity> XML tag. '
            'Default is "%s".' % settings.DEFAULT_ENTITY_NAME)
        swid_parser.add_argument(
            '--os',
            dest='os_string',
            type=os_string,
            default=None,
            help='The OS string used in the tagId attribute. '
            'Default is derived from the OS of the local host.')
        swid_parser.add_argument(
            '--arch',
            dest='architecture',
            type=arch_string,
            default=None,
            help='The HW architecture used in the tagId attribute. '
            'Default is derived from the HW architecture of the local host.')
        swid_parser.add_argument(
            '--meta-for',
            dest='meta_for',
            type=meta_for_string,
            default='os',
            help='Specify whether the Meta element should hold information '
            'about OS ("os", the default), or about the package ("package").')
        swid_parser.add_argument(
            '--schema-location',
            action='store_true',
            default=False,
            help=
            'Add xsi:schemaLocation attribute with schema URIs to validate the '
            'resulting XML documents.')
        swid_parser.add_argument('--lang',
                                 dest='xml_lang',
                                 type=str,
                                 default=str(settings.DEFAULT_XML_LANG),
                                 help='Value of xml:lang attribute. '
                                 'Default is "%s".' %
                                 settings.DEFAULT_XML_LANG)
        swid_parser.add_argument('--pretty',
                                 action='store_true',
                                 default=False,
                                 help='Indent the XML output.')
        swid_parser.add_argument(
            '--full',
            action='store_true',
            default=False,
            help=
            'Dump the full SWID tags including directory/file tags for each package.'
        )
        swid_parser.add_argument(
            '--hierarchic',
            action='store_true',
            default=False,
            help='Change directory structure to hierarchic.')
        swid_parser.add_argument(
            '--hash',
            dest='hash_algorithms',
            type=hash_string,
            default=hash_string(settings.DEFAULT_HASH_ALGORITHM),
            help=
            'Define the algorithm for the file hashes ("sha256", "sha384", "sha512"). '
            'Multiple hashes can be added with comma separated. ("sha256,sha384") '
            'Default is "%s"' % settings.DEFAULT_HASH_ALGORITHM)
        swid_parser.add_argument(
            '--pkcs12',
            dest='pkcs12',
            type=certificate_path,
            action=RequirementCheckAction,
            const=environment_registry,
            help=
            'The PKCS#12 container with key and certificate to sign the xml output.'
        )
        swid_parser.add_argument(
            '--pkcs12-pwd',
            dest='password',
            help='If the PKCS#12 file is password protected, '
            'the password needs to be provided.')

        swid_parser.set_defaults(matcher=all_matcher)

        targeted_group = swid_parser.add_argument_group(
            title='targeted requests',
            description=
            'You may do a targeted request against either a Software-ID, a package name, '
            'a package file or a folder structure. '
            'The output only contains a SWID tag if the argument fully matches '
            'the given target. If no matching SWID tag is found, the output is empty '
            'and the exit code is set to 1. ')

        # mutually exclusive arguments --package/--software-id
        mutually_group = targeted_group.add_mutually_exclusive_group()
        mutually_group.add_argument(
            '--software-id',
            dest='match_software_id',
            metavar='SOFTWARE-ID',
            action=TargetAction,
            help='Do a targeted request for the specified Software-ID. '
            'A Software-ID is made up as follows: "{regid}__{unique-id}". '
            'Example: '
            '"strongswan.org__Ubuntu_12.04-i686-strongswan-4.5.2-1.2". '
            'If no matching package is found, the output is empty and the '
            'exit code is set to 1.')
        mutually_group.add_argument(
            '--package',
            dest='package_name',
            metavar='PACKAGE',
            action=TargetAction,
            help='Do a targeted request for the specified package name. '
            'The package name corresponds to a package name returned by the '
            'environment\'s package manager, e.g "glibc-headers" on a '
            'dpkg managed environment. '
            'If no matching package is found, the output is empty and the '
            'exit code is set to 1.')
        mutually_group.add_argument(
            '--package-file',
            dest='file_path',
            type=package_path,
            action=RequirementCheckAction,
            const=environment_registry,
            help='Create SWID-Tag based on information of a Package-File. '
            'Rpm-Environment: *.rpm File, Dpkg-Environment: *.deb File, '
            'Pacman-Environment: *.pgk.tar.xz File')
        targeted_group.add_argument(
            '--evidence',
            dest='evidence_paths',
            action='append',
            metavar='PATH',
            help=
            'Create a SWID Tag from one or more directories on the filesystem. '
            'This changes the payload element to an evidence element.')
        targeted_group.add_argument(
            '--name',
            dest='name',
            default=None,
            type=entity_name_string,
            help='Specify a name for a directory based SWID-Tag. '
            'Default is "{first-evidence-path}_{os-string}"')
        targeted_group.add_argument(
            '--version-string',
            dest='version',
            type=entity_name_string,
            default=None,
            help='Specify the version for a directory based SWID-Tag. '
            'Default is "1.0.0"')
        targeted_group.add_argument(
            '--new-root',
            dest='new_root',
            metavar='PATH',
            type=entity_name_string,
            default=None,
            help=
            'Change the displayed "root"-folder from the provided directory to '
            'a different path.')
        # Subparser for software-id command
        subparsers.add_parser('software-id',
                              help='Software id output',
                              parents=[parent_parser],
                              description='Generate Software-IDs.')

    def parse(self, arguments=None):
        return self.arg_parser.parse_args(arguments)

    def print_usage(self):
        self.arg_parser.print_usage()