Exemplo n.º 1
0
def generateTestScripts(env, TestGroups):
    try:
        if IS_WINDOWS:
            script_name, env1, env2 = 'test.py', '%', '%'
        else:
            script_name, env1, env2 = 'test.sh', '$', ''
        utest=open('u'+script_name,'w')
        utest.write(GroupTest.makeHeader(env['PLATFORM'], env['prefix'], False))
        for tests in TestGroups:
            utest.write(tests.makeString())
        utest.write(tests.makeFooter())
        utest.close()
        env.Execute(Chmod('u'+script_name, 0o755))
        print('Generated u'+script_name+'.')
        # This version contains only python tests - I want this to be usable
        # from a binary only install if you have the test files
        utest=open('i'+script_name,'w')
        utest.write(GroupTest.makeHeader(env['PLATFORM'], env['prefix'], True))
        for tests in TestGroups:
          if tests.exec_cmd==env1+'PYTHONRUNNER'+env2+' ':
            utest.write(tests.makeString())
        utest.write(tests.makeFooter())
        utest.close()
        env.Execute(Chmod('i'+script_name, 0o755))
        print('Generated i'+script_name+'.')
    except IOError:
        env['warnings'].append("Error attempting to write unit test script(s).")

    # delete scripts upon cleanup
    env.Clean('target_init', 'u'+script_name)
    env.Clean('target_init', 'i'+script_name)
Exemplo n.º 2
0
def write_launcher(env):
    reps={'%n':env1+'ESCRIPT_NUM_NODES'+env2, '%p':env1+'ESCRIPT_NUM_PROCS'+env2,
          '%N':env1+'TOTPROC'+env2, '%t':env1+'ESCRIPT_NUM_THREADS'+env2, '%f':env1+'HOSTFILE'+env2,
          '%h':env1+'HOSTLIST'+env2, '%e':env1+'EXPORT_ENV'+env2, '%b':env1+'EXEC_CMD'+env2}
    pre=env['prelaunch']
    cmd=env['launcher']
    post=env['postlaunch']
    # %b should be present in launcher at least
    if not '%b' in cmd:
        raise RuntimeError('option "launcher" must contain %b!')

    import sys
    if sys.version_info > (3,0):
        for k, v in reps.items():
            pre = pre.replace(k, v)
            cmd = cmd.replace(k, v)
            post = post.replace(k, v)
    else:
        for k, v in reps.iteritems():
            pre = pre.replace(k, v)
            cmd = cmd.replace(k, v)
            post = post.replace(k, v)
    try:
        if not env['stdlocationisprefix']:
            usestdlocation='0'
            stdlocation='/usr/lib/python-escript'
        else:
            usestdlocation='1'
            stdlocation=env['prefix']     
        pylaunchscript = os.path.join('escript', 'py_src', 'run_escript.py')
        pylauncher=open(pylaunchscript, 'w')
        with open('run_escript_py.in','r') as f:
            pylauncher.write(f.read() % {'PRELAUNCH': pre, 'LAUNCH': cmd, 'POSTLAUNCH': post,
                'STDLOCATION': usestdlocation, 'ESROOT': stdlocation})
        pylauncher.close()
        launchscript = os.path.join(env['bininstall'], 'run-escript')
        if IS_WINDOWS:
            with open(launchscript+'.cmd', 'w') as cmdfile:
                cmdfile.write('@echo off\n')
                cmdfile.write('python %~dp0\\'+launchscript+' %*')
            with open(launchscript+'.py', 'w') as cmdfile:
                cmdfile.write('import esys.escript.run_escript\n')
                cmdfile.write('esys.escript.run_escript.main()')
        else:
            launcher=open(launchscript, 'w')
            for line in open('run-escript.in','r').readlines():
                s=line.replace('@@PRELAUNCH', pre).replace('@@LAUNCH', cmd).replace('@@POSTLAUNCH', post)
                s=s.replace('@@STDLOCATION', usestdlocation).replace('@@ESROOT',stdlocation)
                launcher.write(s)
            launcher.close()
            env.Execute(Chmod(launchscript, 0o755))
    except IOError:
        env['warnings'].append("Error attempting to write launcher script.")
Exemplo n.º 3
0
def write_launcher(env):
    reps = {
        '%n': '${ESCRIPT_NUM_NODES}',
        '%p': '${ESCRIPT_NUM_PROCS}',
        '%N': '${TOTPROC}',
        '%t': '${ESCRIPT_NUM_THREADS}',
        '%f': '${HOSTFILE}',
        '%h': '${HOSTLIST}',
        '%e': '${EXPORT_ENV}',
        '%b': '${EXEC_CMD}'
    }
    pre = env['prelaunch']
    cmd = env['launcher']
    post = env['postlaunch']
    # %b should be present in launcher at least
    if not '%b' in cmd:
        raise RuntimeError('option "launcher" must contain %b!')

    import sys
    if sys.version_info > (3, 0):
        for k, v in reps.items():
            pre = pre.replace(k, v)
            cmd = cmd.replace(k, v)
            post = post.replace(k, v)
    else:
        for k, v in reps.iteritems():
            pre = pre.replace(k, v)
            cmd = cmd.replace(k, v)
            post = post.replace(k, v)
    try:
        launchscript = os.path.join(env['bininstall'], 'run-escript')
        launcher = open(launchscript, 'w')
        if not env['stdlocationisprefix']:
            usestdlocation = '0'
            stdlocation = '/usr/lib/python-escript'
        else:
            usestdlocation = '1'
            stdlocation = env['prefix']
        for line in open('run-escript.in', 'r').readlines():
            s = line.replace('@@PRELAUNCH',
                             pre).replace('@@LAUNCH',
                                          cmd).replace('@@POSTLAUNCH', post)
            s = s.replace('@@STDLOCATION',
                          usestdlocation).replace('@@ESROOT', stdlocation)
            launcher.write(s)
        launcher.close()
        env.Execute(Chmod(launchscript, 0o755))
    except IOError:
        env['warnings'].append("Error attempting to write launcher script.")