123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152 |
- #! /usr/bin/env python3
- # -----------------------------------------------
- # help
- # -----------------------------------------------
- """
- NAME
- submit_tm5_step_all
-
- DESCRIPTION
- Script to call init, run, and done in sequence. This is to roll
- up the preprocessing ("init"), run, and postprocessing ("done")
- into one single batch job, suitable for queue submission. We use
- this at NOAA for situations in which the queue wait time for three
- separate jobs in a given step becomes too great a fraction of the
- total step execution time. Using this feature will require "all"
- job definitions in places where you define variables for "init",
- etc. For us, this is in pycasso-queue-qsub-noaa-jet.rc. You also
- need to set job.steps to "all", without "init", "run", or "done".
- This, for us, is in pycasso-tm5-expert-noaa-jet.rc.
-
- REVISION HISTORY
- 26 Aug 2011, Andy Jacobson (NOAA): Code here was adapted from
- Arjo's submit_tm5_tools.py
- """
- # -----------------------------------------------
- # external
- # -----------------------------------------------
- # standard modules:
- import sys
- import os
- import shutil
- import fnmatch
- import optparse
- import logging
- import datetime
- import subprocess
- # -----------------------------------------------
- # logging
- # -----------------------------------------------
- # setup messages:
- logging.basicConfig( format='%(lineno)-4s:%(filename)-30s [%(levelname)-8s] %(message)s', level=logging.INFO, stream=sys.stdout )
- # -----------------------------------------------
- # default values
- # -----------------------------------------------
- # location of auxilary scripts:
- bindir_default = os.curdir
- # -----------------------------------------------
- # arguments
- # -----------------------------------------------
- # set text for 'usage' help line:
- usage = "%prog <rcfile> [--bindir=<bindir>]"
- # initialise the option parser:
- parser = optparse.OptionParser(usage=usage)
- # define options:
- parser.add_option( "--bindir",
- help="location of auxilary scripts (%s)" % bindir_default,
- dest="bindir", action="store", default=bindir_default )
- # now parse the actual arguments;
- # return an object 'opts' with fields 'verbose' etc,
- # and the unnamed arguments in the list 'args' :
- opts,args = parser.parse_args()
- # only one argument ...
- if len(args) != 1 :
- if opts.verbose : logging.error( 'single argument command should be specified, found : %i' % len(args) )
- parser.print_usage()
- sys.exit(1)
- #endif
- # extract ...
- rcfile = args[0]
- # -----------------------------------------------
- # toolboxes
- # -----------------------------------------------
- # location of scripts:
- bindir = opts.bindir
- # prepend locations of python modules to search path:
- sys.path.insert( 0, bindir )
- # local modules:
- import rc
- import go
- from submit_tm5_tools import Command_Line
- # -----------------------------------------------
- # begin
- # -----------------------------------------------
- # info ...
- logging.info( 'start' )
- # read settings:
- rcf = rc.RcFile( rcfile )
- for step in ('init','run','done') :
- # call to acutal script:
- if step == 'run' :
- # get command line:
- exe = os.path.join( os.curdir, rcf.get('job.step.%s.exe' % step) )
- args = rcfile
- indb = rcf.get('submit.debugger','bool')
- cmndline = Command_Line( rcf, exe, args, indb )
- # <script> <commandline>
- step_command = ["%s/submit_tm5_step_%s" % (bindir,step),"%s" % cmndline]
- else :
- # <script> <rcfile>
- step_command = ["%s/submit_tm5_step_%s" % (bindir, step) ,"%s" % rcfile, "--bindir=%s" % bindir]
- #endif
- logging.info( 'Executing step command "%s" ' % step_command )
- retcode = subprocess.call(step_command)
- if retcode != 0 :
- logging.error( sys.exc_info()[1] )
- logging.error( 'exception from subprocess call to : %s' % step_command )
- sys.exit(1)
- #endif
- # info ...
- logging.info( 'end' )
- # -----------------------------------------------
- # end
- # -----------------------------------------------
|