submit_tm5_step_all 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. #! /usr/bin/env python
  2. # -----------------------------------------------
  3. # help
  4. # -----------------------------------------------
  5. """
  6. NAME
  7. submit_tm5_step_all
  8. DESCRIPTION
  9. Script to call init, run, and done in sequence. This is to roll
  10. up the preprocessing ("init"), run, and postprocessing ("done")
  11. into one single batch job, suitable for queue submission. We use
  12. this at NOAA for situations in which the queue wait time for three
  13. separate jobs in a given step becomes too great a fraction of the
  14. total step execution time. Using this feature will require "all"
  15. job definitions in places where you define variables for "init",
  16. etc. For us, this is in pycasso-queue-qsub-noaa-jet.rc. You also
  17. need to set job.steps to "all", without "init", "run", or "done".
  18. This, for us, is in pycasso-tm5-expert-noaa-jet.rc.
  19. REVISION HISTORY
  20. 26 Aug 2011, Andy Jacobson (NOAA): Code here was adapted from
  21. Arjo's submit_tm5_tools.py
  22. """
  23. # -----------------------------------------------
  24. # external
  25. # -----------------------------------------------
  26. # standard modules:
  27. import sys
  28. import os
  29. import shutil
  30. import fnmatch
  31. import optparse
  32. import logging
  33. import datetime
  34. import subprocess
  35. # -----------------------------------------------
  36. # logging
  37. # -----------------------------------------------
  38. # setup messages:
  39. logging.basicConfig( format='%(lineno)-4s:%(filename)-30s [%(levelname)-8s] %(message)s', level=logging.INFO, stream=sys.stdout )
  40. # -----------------------------------------------
  41. # default values
  42. # -----------------------------------------------
  43. # location of auxilary scripts:
  44. bindir_default = os.curdir
  45. # -----------------------------------------------
  46. # arguments
  47. # -----------------------------------------------
  48. # set text for 'usage' help line:
  49. usage = "%prog <rcfile> [--bindir=<bindir>]"
  50. # initialise the option parser:
  51. parser = optparse.OptionParser(usage=usage)
  52. # define options:
  53. parser.add_option( "--bindir",
  54. help="location of auxilary scripts (%s)" % bindir_default,
  55. dest="bindir", action="store", default=bindir_default )
  56. # now parse the actual arguments;
  57. # return an object 'opts' with fields 'verbose' etc,
  58. # and the unnamed arguments in the list 'args' :
  59. opts,args = parser.parse_args()
  60. # only one argument ...
  61. if len(args) != 1 :
  62. if opts.verbose : logging.error( 'single argument command should be specified, found : %i' % len(args) )
  63. parser.print_usage()
  64. sys.exit(1)
  65. #endif
  66. # extract ...
  67. rcfile = args[0]
  68. # -----------------------------------------------
  69. # toolboxes
  70. # -----------------------------------------------
  71. # location of scripts:
  72. bindir = opts.bindir
  73. # prepend locations of python modules to search path:
  74. sys.path.insert( 0, bindir )
  75. # local modules:
  76. import rc
  77. import go
  78. from submit_tm5_tools import Command_Line
  79. # -----------------------------------------------
  80. # begin
  81. # -----------------------------------------------
  82. # info ...
  83. logging.info( 'start' )
  84. # read settings:
  85. rcf = rc.RcFile( rcfile )
  86. for step in ('init','run','done') :
  87. # call to acutal script:
  88. if step == 'run' :
  89. # get command line:
  90. exe = os.path.join( os.curdir, rcf.get('job.step.%s.exe' % step) )
  91. args = rcfile
  92. indb = rcf.get('submit.debugger','bool')
  93. cmndline = Command_Line( rcf, exe, args, indb )
  94. # <script> <commandline>
  95. step_command = ["%s/submit_tm5_step_%s" % (bindir,step),"%s" % cmndline]
  96. else :
  97. # <script> <rcfile>
  98. step_command = ["%s/submit_tm5_step_%s" % (bindir, step) ,"%s" % rcfile, "--bindir=%s" % bindir]
  99. #endif
  100. logging.info( 'Executing step command "%s" ' % step_command )
  101. retcode = subprocess.call(step_command)
  102. if retcode != 0 :
  103. logging.error( sys.exc_info()[1] )
  104. logging.error( 'exception from subprocess call to : %s' % step_command )
  105. sys.exit(1)
  106. #endif
  107. # info ...
  108. logging.info( 'end' )
  109. # -----------------------------------------------
  110. # end
  111. # -----------------------------------------------