def main(argv=None):
    import paramiko.util

    atexit.register(fabric_cleanup, True)
    paramiko.util.log_to_file('paramiko.log')
    if argv is None:
        argv = sys.argv[1:]

    parser = add_config_options(ArgumentParser())
    
    parser.add_argument("-d", "--dest", action="store", type=str, 
                        dest="dest", default='.',
                        help="destination directory where built package will go")
    parser.add_argument("-s", "--src", action="append", type=str, 
                        dest="srcs", default=[],
                        help="source directory where package is located")  
    parser.add_argument("-b", "--buildtype", action="store", type=str, 
                        dest="btype", default='bdist_egg',
                        help="type of distribution to build")
    parser.add_argument("--py", action="store", type=str, 
                        dest="py", default='python',
                        help="which python to use (default='python'")
    parser.add_argument("-k","--keep", action="store_true", dest='keep',
                        help="if there are build failures, don't delete "
                           "the temporary build directory "
                           "or terminate the remote instance if testing on EC2.")

    options = parser.parse_args()
    
    config, conn, image_hosts = process_options(options)
    
    if not options.srcs:
        print "You must specify one or more source directories"
        parser.print_help()
        sys.exit(-1)
        
    options.srcs = [os.path.abspath(os.path.expanduser(s)) for s in options.srcs]

    funct_kwargs = { 'keep': options.keep,
                     'srcdirs': options.srcs,
                     'destdir': os.path.abspath(os.path.expanduser(options.dest)), 
                     'build_type': options.btype,
                     'py': options.py,
                     }
    
    retval = run_host_processes(config, conn, image_hosts, options, 
                                funct=remote_build, 
                                funct_kwargs=funct_kwargs,
                                done_functs=[print_host_codes])
    
    if retval == 0:
        cleanup('paramiko.log')

    sys.exit(retval)
Example #2
0
def main(argv=None):
    import paramiko.util

    atexit.register(fabric_cleanup, True)
    paramiko.util.log_to_file('paramiko.log')
    if argv is None:
        argv = sys.argv[1:]

    parser = add_config_options(ArgumentParser())

    parser.add_argument("-d", "--dest", action="store", type=str,
                        dest="dest", default='.',
                        help="destination directory where built package will go")
    parser.add_argument("-s", "--src", action="append", type=str,
                        dest="srcs", default=[],
                        help="source directory where package is located")
    parser.add_argument("-b", "--buildtype", action="store", type=str,
                        dest="btype", default='bdist_egg',
                        help="type of distribution to build")
    parser.add_argument("--py", action="store", type=str,
                        dest="py", default='python',
                        help="which python to use (default='python'")
    parser.add_argument("-k", "--keep", action="store_true", dest='keep',
                        help="if there are build failures, don't delete "
                             "the temporary build directory "
                             "or terminate the remote instance if testing on EC2.")

    options = parser.parse_args()

    config, conn, image_hosts = process_options(options)

    if not options.srcs:
        print "You must specify one or more source directories"
        parser.print_help()
        sys.exit(-1)

    options.srcs = [os.path.abspath(os.path.expanduser(s)) for s in options.srcs]

    funct_kwargs = {'keep': options.keep,
                    'srcdirs': options.srcs,
                    'destdir': os.path.abspath(os.path.expanduser(options.dest)),
                    'build_type': options.btype,
                    'py': options.py,
                    }

    retval = run_host_processes(config, conn, image_hosts, options,
                                funct=remote_build,
                                funct_kwargs=funct_kwargs,
                                done_functs=[print_host_codes])

    if retval == 0:
        cleanup('paramiko.log')

    sys.exit(retval)
def _get_release_parser():
    """Sets up the 'release' arg parser and all of its subcommand parsers."""
    
    top_parser = ArgumentParser()
    subparsers = top_parser.add_subparsers(title='subcommands')
        
    parser = subparsers.add_parser('finalize',
               description="push the release to the production area and tag the production repository")
    parser.add_argument("-v", "--version", action="store", type=str, 
                        dest="version",
                        help="release version of OpenMDAO to be finalized")
    parser.add_argument("-d","--dryrun", action="store_true", dest='dry_run',
                        help="don't actually push any changes up to github or openmdao.org")
    parser.add_argument("--tutorials", action="store_true", dest="tutorials",
                        help="Only upload the tutorials, no other action will be taken")
    parser.add_argument("--nogists", action="store_true", dest="nogists",
                        help="Do not upload gists when finalizing the release")
    parser.set_defaults(func=finalize_release)

    parser = subparsers.add_parser('push',
               description="push release dists and docs into an OpenMDAO release directory structure (downloads, dists, etc.)")
    parser.usage="%(prog)s releasedir destdir [options] "
    
    parser.add_argument('releasedir', nargs='?',
                        help='directory where release files are located')
    parser.add_argument('destdir', nargs='?',
                        help='location where structured release files will be placed')
    parser.add_argument("--py", action="store", type=str, dest="py",
                        default="python",
                        help="python version to use on target host")
    parser.set_defaults(func=push_release)

    
    parser = subparsers.add_parser('test',
                                   description="test an OpenMDAO release")
    parser.add_argument('fname', nargs='?',
                        help='pathname of release directory or go-openmdao.py file')
    add_config_options(parser)
    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("--testargs", action="store", type=str, dest='testargs',
                        default='',
                        help="args to be passed to openmdao test")
    parser.set_defaults(func=test_release)
    
    
    parser = subparsers.add_parser('build',
                                   description="create release versions of all OpenMDAO dists")
    parser.add_argument("-d", "--dest", action="store", type=str, 
                        dest="destdir",
                        help="directory where all release distributions and docs will be placed")
    parser.add_argument("-v", "--version", action="store", type=str, 
                        dest="version",
                        help="version string applied to all openmdao distributions")
    parser.add_argument("-m", action="store", type=str, dest="comment",
                        help="optional comment for version tag")
    parser.add_argument("--basebranch", action="store", type=str, 
                        dest="base", default='dev', 
                        help="base branch for release. defaults to dev")
    parser.add_argument("-t", "--test", action="store_true", dest="test",
                        help="used for testing. A release branch will not be created")
    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.add_argument("-b", "--binaries", action="store_true", 
                        dest="binaries",
                        help="build binary distributions where necessary")
    parser.add_argument("--host", action='append', dest='hosts', metavar='HOST',
                        default=[],
                        help="host from config file to build bdist_eggs on. "
                           "Multiple --host args are allowed.")
    parser.add_argument("-c", "--config", action='store', dest='cfg', 
                        metavar='CONFIG', default=get_cfg_file(),
                        help="path of config file where info for hosts is located")
    parser.set_defaults(func=build_release)
    
    return top_parser
Example #4
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
Example #5
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('--gui',
                        action='store_true',
                        help='do GUI functional tests, regardless of default')
    parser.add_argument(
        '--skip-gui',
        action='store_true',
        help='skip GUI functional tests, regardless of default')
    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
        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(
            '--gui',
            action='store_true',
            dest='gui',
            help='do GUI functional tests, regardless of default')
        parser.add_argument(
            '--skip-gui',
            action='store_true',
            dest='skip_gui',
            help='skip GUI functional tests, regardless of default')
        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('-x',
                            '--external',
                            action='store_true',
                            dest='external',
                            help='allow access to server from external clients'
                            ' (WARNING: Not Safe or Secure!!)')
        parser.set_defaults(func=gui.run)

    except ImportError:
        pass

    return top_parser
Example #6
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('--gui', action='store_true',
                        help='do GUI functional tests, regardless of default')
    parser.add_argument('--skip-gui', action='store_true',
                        help='skip GUI functional tests, regardless of default')
    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
        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('--gui', action='store_true', dest='gui',
                            help='do GUI functional tests, regardless of default')
        parser.add_argument('--skip-gui', action='store_true', dest='skip_gui',
                            help='skip GUI functional tests, regardless of default')
        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('-x', '--external', action='store_true', dest='external',
                            help='allow access to server from external clients'
                                 ' (WARNING: Not Safe or Secure!!)')
        parser.set_defaults(func=gui.run)

    except ImportError:
        pass

    return top_parser
Example #7
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('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_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
Example #8
0
def _get_release_parser():
    """Sets up the 'release' arg parser and all of its subcommand parsers."""

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

    parser = subparsers.add_parser(
        'finalize',
        description=
        "push the release to the production area and tag the production repository"
    )
    parser.add_argument("-v",
                        "--version",
                        action="store",
                        type=str,
                        dest="version",
                        help="release version of OpenMDAO to be finalized")
    parser.add_argument(
        "-d",
        "--dryrun",
        action="store_true",
        dest='dry_run',
        help="don't actually push any changes up to github or openmdao.org")
    parser.add_argument(
        "--tutorials",
        action="store_true",
        dest="tutorials",
        help="Only upload the tutorials, no other action will be taken")
    parser.set_defaults(func=finalize_release)

    parser = subparsers.add_parser(
        'push',
        description=
        "push release dists and docs into an OpenMDAO release directory structure (downloads, dists, etc.)"
    )
    parser.usage = "%(prog)s releasedir destdir [options] "

    parser.add_argument('releasedir',
                        nargs='?',
                        help='directory where release files are located')
    parser.add_argument(
        'destdir',
        nargs='?',
        help='location where structured release files will be placed')
    parser.add_argument("--py",
                        action="store",
                        type=str,
                        dest="py",
                        default="python",
                        help="python version to use on target host")
    parser.set_defaults(func=push_release)

    parser = subparsers.add_parser('test',
                                   description="test an OpenMDAO release")
    parser.add_argument(
        'fname',
        nargs='?',
        help='pathname of release directory or go-openmdao-<version>.py file')
    add_config_options(parser)
    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("--testargs",
                        action="store",
                        type=str,
                        dest='testargs',
                        default='',
                        help="args to be passed to openmdao test")
    parser.set_defaults(func=test_release)

    parser = subparsers.add_parser(
        'build', description="create release versions of all OpenMDAO dists")
    parser.add_argument(
        "-d",
        "--dest",
        action="store",
        type=str,
        dest="destdir",
        help="directory where all release distributions and docs will be placed"
    )
    parser.add_argument(
        "-v",
        "--version",
        action="store",
        type=str,
        dest="version",
        help="version string applied to all openmdao distributions")
    parser.add_argument("-m",
                        action="store",
                        type=str,
                        dest="comment",
                        help="optional comment for version tag")
    parser.add_argument("--basebranch",
                        action="store",
                        type=str,
                        dest="base",
                        default='master',
                        help="base branch for release. defaults to master")
    parser.add_argument(
        "-t",
        "--test",
        action="store_true",
        dest="test",
        help="used for testing. A release branch will not be created")
    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.add_argument("-b",
                        "--binaries",
                        action="store_true",
                        dest="binaries",
                        help="build binary distributions where necessary")
    parser.add_argument("--host",
                        action='append',
                        dest='hosts',
                        metavar='HOST',
                        default=[],
                        help="host from config file to build bdist_eggs on. "
                        "Multiple --host args are allowed.")
    parser.add_argument(
        "-c",
        "--config",
        action='store',
        dest='cfg',
        metavar='CONFIG',
        default=get_cfg_file(),
        help="path of config file where info for hosts is located")
    parser.set_defaults(func=build_release)

    return top_parser
Example #9
0
def test_branch(argv=None):
    atexit.register(fabric_cleanup, True)
    paramiko.util.log_to_file('paramiko.log')
    
    if argv is None:
        argv = sys.argv[1:]
        
    parser = ArgumentParser()
    add_config_options(parser)
    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")

    options = parser.parse_args()
    
    options.filters = ['test_branch==true']
    config, conn, ec2_hosts = process_options(options)
    
    if not options.hosts:
        parser.print_help()
        print "nothing to do - no hosts specified"
        sys.exit(0)
    
    startdir = os.getcwd()
    
    if options.fname is None: # assume we're testing the current repo
        print 'creating tar file of current branch: ',
        options.fname = os.path.join(os.getcwd(), 'testbranch.tar')
        ziptarname = options.fname+'.gz'
        cleanup(ziptarname) # clean up the old tar file
        make_git_archive(options.fname)
        subprocess.check_call(['gzip', options.fname])
        options.fname = os.path.abspath(ziptarname)
        print options.fname
        cleanup_tar = True
    else:
        cleanup_tar = False
        
    fname = options.fname
    if not (fname.startswith('http') or fname.startswith('git:') or fname.startswith('git@')):
        fname = os.path.abspath(os.path.expanduser(options.fname))
    
    if fname.endswith('.tar.gz') or fname.endswith('.tar'):
        if not os.path.isfile(fname):
            print "can't find file '%s'" % fname
            sys.exit(-1)
    elif fname.endswith('.git') or (fname.startswith('http') and os.path.splitext(fname)[1]==''):
        pass
    else:
        parser.print_help()
        print "\nfilename '%s' must specify a tar file or git repository" % fname
        sys.exit(-1)
        
    funct_kwargs = { 'keep': options.keep,
                     'testargs': options.testargs,
                     'fname': fname,
                     'remotedir': get_tmp_user_dir(),
                     'branch': options.branch,
                     }
    try:
        retcode = run_host_processes(config, conn, ec2_hosts, options, 
                                     funct=_remote_build_and_test, 
                                     funct_kwargs=funct_kwargs,
                                     done_functs=[print_host_codes])
    finally:
        if cleanup_tar:
            cleanup(ziptarname)
    
    if retcode == 0:
        cleanup('paramiko.log')
        
    return retcode
Example #10
0
def _get_openmdao_parser():
    """Sets up the plugin arg parser and all of its subcommand parsers."""

    top_parser = ArgumentParser()
    top_parser.add_argument('-v', '--version', action='version',
                            version='OpenMDAO %s' % __version__)

    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', default=True,
                        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('--gui', action='store_true',
                        help='do GUI functional tests, regardless of default')
    parser.add_argument('--skip-gui', action='store_true',
                        help='skip GUI functional tests, regardless of default')
    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
        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('--gui', action='store_true', dest='gui',
                            help='do GUI functional tests, regardless of default')
        parser.add_argument('--skip-gui', action='store_true', dest='skip_gui',
                            help='skip GUI functional tests, regardless of default')
        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

    # case data viewer (i.e. html_post_processor)
    try:
        import openmdao.lib.casehandlers.html_post_processor as viewer
        parser = subparsers.add_parser('view_case_data', help='visualize JSON case data')
        parser.add_argument('json_file', type=str, metavar='json_file',
                            help='JSON format case data file')
        parser.set_defaults(func=viewer.run)
    except ImportError:
        pass

    return top_parser
Example #11
0
def test_branch(argv=None):
    atexit.register(fabric_cleanup, True)
    paramiko.util.log_to_file('paramiko.log')

    if argv is None:
        argv = sys.argv[1:]

    parser = ArgumentParser()
    add_config_options(parser)
    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")

    options = parser.parse_args()

    options.filters = ['test_branch==true']
    config, conn, ec2_hosts = process_options(options)

    if not options.hosts:
        parser.print_help()
        print "nothing to do - no hosts specified"
        sys.exit(0)

    startdir = os.getcwd()

    if options.fname is None:  # assume we're testing the current repo
        print 'creating tar file of current branch: ',
        options.fname = os.path.join(os.getcwd(), 'testbranch.tar')
        ziptarname = options.fname + '.gz'
        cleanup(ziptarname)  # clean up the old tar file
        make_git_archive(options.fname)
        subprocess.check_call(['gzip', options.fname])
        options.fname = os.path.abspath(ziptarname)
        print options.fname
        cleanup_tar = True
    else:
        cleanup_tar = False

    fname = options.fname
    if not (fname.startswith('http') or fname.startswith('git:')
            or fname.startswith('git@')):
        fname = os.path.abspath(os.path.expanduser(options.fname))

    if fname.endswith('.tar.gz') or fname.endswith('.tar'):
        if not os.path.isfile(fname):
            print "can't find file '%s'" % fname
            sys.exit(-1)
    elif fname.endswith('.git') or (fname.startswith('http')
                                    and os.path.splitext(fname)[1] == ''):
        pass
    else:
        parser.print_help()
        print "\nfilename '%s' must specify a tar file or git repository" % fname
        sys.exit(-1)

    funct_kwargs = {
        'keep': options.keep,
        'testargs': options.testargs,
        'fname': fname,
        'remotedir': get_tmp_user_dir(),
        'branch': options.branch,
    }
    try:
        retcode = run_host_processes(config,
                                     conn,
                                     ec2_hosts,
                                     options,
                                     funct=_remote_build_and_test,
                                     funct_kwargs=funct_kwargs,
                                     done_functs=[print_host_codes])
    finally:
        if cleanup_tar:
            cleanup(ziptarname)

    if retcode == 0:
        cleanup('paramiko.log')

    return retcode
Example #12
0
def _get_openmdao_parser():
    """Sets up the plugin arg parser and all of its subcommand parsers."""

    top_parser = ArgumentParser()
    top_parser.add_argument("-v", "--version", action="version", version="OpenMDAO %s" % __version__)

    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("--gui", action="store_true", help="do GUI functional tests, regardless of default")
    parser.add_argument("--skip-gui", action="store_true", help="skip GUI functional tests, regardless of default")
    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
        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(
            "--gui", action="store_true", dest="gui", help="do GUI functional tests, regardless of default"
        )
        parser.add_argument(
            "--skip-gui", action="store_true", dest="skip_gui", help="skip GUI functional tests, regardless of default"
        )
        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(
            "-x",
            "--external",
            action="store_true",
            dest="external",
            help="allow access to server from external clients" " (WARNING: Not Safe or Secure!!)",
        )
        parser.set_defaults(func=gui.run)

    except ImportError as err:
        print str(err)

    return top_parser