Example #1
0
File: pbs.py Project: esheldon/espy
    def __init__(self, 
                 filename,
                 command, 
                 job_name=None, 
                 queue='fast', 
                 walltime=None, # e.g. '24:00:00'
                 nodes=1, 
                 ppn=1, 
                 setups=None,
                 no_redirect=False):

        filename = expand_path(filename)
        self.filename = filename

        pbslog=filename+'.pbslog'
        logf = filename+'.log'

        # don't put job name there at all if not sent
        if job_name is not None:
            jobstring = "#PBS -N %s" % job_name
        else:
            jobstring=""
        if walltime is not None:
            timestring = '#PBS -l walltime=' % walltime
        else:
            timestring = ''

        if setups is not None:
            if not isstring(setups):
                setups = '\n'.join(setups) 
        else:
            setups=""


        script="""# vim: set ft=sh :
#PBS -S /bin/bash
#PBS -l nodes={nodes}:ppn={ppn}
#PBS -q {queue}
#PBS -j oe
#PBS -o {pbslog}
#PBS -m a
#PBS -V
#PBS -r n
#PBS -W umask=0022
{timestring}
{jobstring}

{setups}

logf="{logf}"

{command}"""
        if not no_redirect:
            command += ''' &> "$logf"'''

        script += "\n"

        script=script.format(nodes=nodes,
                             ppn=ppn,
                             queue=queue,
                             pbslog=pbslog,
                             timestring=timestring,
                             jobstring=jobstring,
                             setups=setups,
                             logf=logf,
                             command=command)

        self.script=script
Example #2
0
File: pbs.py Project: esheldon/espy
    def __init__(self, 
                 filename,
                 commands, 
                 job_name=None, 
                 queue='fast', 
                 walltime=None, # e.g. '24:00:00', 
                 nodes=1, 
                 ppn=1, 
                 setups=None,
                 buffer=False):

        filename = expand_path(filename)
        self.filename = filename

        pbslog=filename+'.pbslog'
        logf = filename+'.log'

        # don't put job name there at all if not sent
        if job_name is not None:
            jobstring = "#PBS -N %s" % job_name
        else:
            jobstring=""

        if walltime is not None:
            timestring = '#PBS -l walltime=' % walltime
        else:
            timestring = ''

        if setups is not None:
            if not isstring(setups):
                setups = '\n'.join(setups) 
        else:
            setups=""

        # now the python commands
        if isinstance(commands, basestring):
            commands = [commands]

        commands = [c.strip() for c in commands]

        commands = '\n'.join(commands)

        if buffer:
            ex='python'
        else:
            ex='python -u'



        self.script="""
#PBS -S /bin/bash
#PBS -l nodes={nodes}:ppn={ppn}
#PBS -q {queue}
#PBS -j oe
#PBS -o {pbslog}
#PBS -m a
#PBS -V
#PBS -r n
#PBS -W umask=0022
{timestring}
{jobstring}

{setups}

logf="{logf}"

{ex} &> "$logf" <<EOF
{commands}
EOF

        \n""".format(nodes=nodes,
                     ppn=ppn,
                     queue=queue,
                     pbslog=pbslog,
                     timestring=timestring,
                     jobstring=jobstring,
                     setups=setups,
                     logf=logf,
                     ex=ex,
                     commands=commands)