def _remote_build_and_test(fname=None, pyversion='python', keep=False,
                           branch=None, testargs='', hostname='', cfg=None,
                           **kwargs):
    if fname is None:
        raise RuntimeError("_remote_build_and_test: missing arg 'fname'")

    remotedir = get_tmp_user_dir()
    remote_mkdir(remotedir)

    locbldtstfile = os.path.join(os.path.dirname(__file__), 'loc_bld_tst.py')

    pushfiles = [locbldtstfile]

    build_type = 'release' if fname.endswith('.py') else 'dev'

    if cfg and cfg.has_option(hostname, 'pull_docs')and build_type == 'dev':
        pull_docs = cfg.getboolean(hostname, 'pull_docs')
    else:
        pull_docs = False

    if os.path.isfile(fname):
        pushfiles.append(fname)
        remoteargs = ['-f', os.path.basename(fname)]
    elif os.path.isdir(fname):
        put_dir(fname, os.path.join(remotedir, os.path.basename(fname)))
        if sys.platform.startswith('win'):
            vername = 'latest'  # readlink doesn't work on windows, so try 'latest'
        else:
            vername = os.readlink(os.path.join(fname,
                                               'downloads',
                                               'latest'))
        remoteargs = ['-f', os.path.join(os.path.basename(fname),
                                         'downloads',
                                         vername,
                                         'go-openmdao-{}.py'.format(vername))]
    else:
        remoteargs = ['-f', fname]

    if branch:
        remoteargs.append('--branch=%s' % branch)

    if testargs:
        remoteargs.append('--testargs="%s"' % testargs)

    try:
        result = push_and_run(pushfiles, runner=pyversion,
                              remotedir=remotedir,
                              args=remoteargs)
        if pull_docs:
            print "pulling docs from %s" % hostname
            retrieve_docs(os.path.join('~', remotedir))
            print "doc retrieval successful"
        else:
            print "not pulling docs from %s because pull_docs is False" % hostname

        return result.return_code
    finally:
        if build_type == 'dev':
            print "pulling any pngs from %s" % hostname
            try:
                retrieve_pngs(os.path.join('~', remotedir))
                print "png retrieval successful"
            except Exception as exc:
                print "png retrieval failed:", exc

        if not keep:
            print "removing remote directory: %s" % remotedir
            rm_remote_tree(remotedir)
Example #2
0
def _remote_build_and_test(fname=None,
                           pyversion='python',
                           keep=False,
                           branch=None,
                           testargs='',
                           hostname='',
                           cfg=None,
                           **kwargs):
    if fname is None:
        raise RuntimeError("_remote_build_and_test: missing arg 'fname'")

    remotedir = get_tmp_user_dir()
    remote_mkdir(remotedir)

    locbldtstfile = os.path.join(os.path.dirname(__file__), 'loc_bld_tst.py')

    pushfiles = [locbldtstfile]

    build_type = 'release' if fname.endswith('.py') else 'dev'

    if cfg and cfg.has_option(hostname, 'pull_docs') and build_type == 'dev':
        pull_docs = cfg.getboolean(hostname, 'pull_docs')
    else:
        pull_docs = False

    if os.path.isfile(fname):
        pushfiles.append(fname)
        remoteargs = ['-f', os.path.basename(fname)]
    elif os.path.isdir(fname):
        put_dir(fname, os.path.join(remotedir, os.path.basename(fname)))
        if sys.platform.startswith('win'):
            vername = 'latest'  # readlink doesn't work on windows, so try 'latest'
        else:
            vername = os.readlink(os.path.join(fname, 'downloads', 'latest'))
        remoteargs = [
            '-f',
            os.path.join(os.path.basename(fname), 'downloads', vername,
                         'go-openmdao.py')
        ]
    else:
        remoteargs = ['-f', fname]

    if branch:
        remoteargs.append('--branch=%s' % branch)

    if testargs:
        remoteargs.append('--testargs="%s"' % testargs)

    try:
        result = push_and_run(pushfiles,
                              runner=pyversion,
                              remotedir=remotedir,
                              args=remoteargs)
        if pull_docs:
            print "pulling docs from %s" % hostname
            retrieve_docs(os.path.join('~', remotedir))
            print "doc retrieval successful"
        else:
            print "not pulling docs from %s because pull_docs is False" % hostname

        return result.return_code
    finally:
        if build_type == 'dev':
            print "pulling any pngs from %s" % hostname
            try:
                retrieve_pngs(os.path.join('~', remotedir))
                print "png retrieval successful"
            except Exception as exc:
                print "png retrieval failed:", exc

        if not keep:
            print "removing remote directory: %s" % remotedir
            rm_remote_tree(remotedir)