def main():
    environ_CONFhafs = os.environ.get('CONFhafs', 'NO_CONFhafs')
    conf = hafs.launcher.HAFSLauncher().read(environ_CONFhafs)
    if not conf.getstr('archive', 'fv3out', ''):
        jlogger.info(
            'No fv3out option in [archive] section.  Will not make fv3out archive.'
        )
        sys.exit(0)

    logger = conf.log()

    files = list()
    WORKhafs = conf.getdir('WORKhafs', '/can/not/find/WORKhafs/dir')
    forecastdir = os.path.join(WORKhafs, 'forecast')
    with produtil.cd.NamedDir(forecastdir):
        files.append(glob.glob('*.nc'))
        thearchive = conf.timestrinterp('archive', '{fv3out}', 0)
        if thearchive[0:5] != 'hpss:':
            logger.error('The fv3out archive path must begin with "hpss:": ' +
                         thearchive)
            sys.exit(1)
        thearchive = thearchive[5:]
        adir = os.path.dirname(thearchive)
        mkdir = batchexe(conf.getexe('hsi'))['-P', 'mkdir', '-p', adir]
        run(mkdir, logger=logger)
        cmd = batchexe(conf.getexe('htar'))['-vcpf', thearchive][files]
        checkrun(cmd, logger=logger)
def main_tape():
    postmsg('hwrf_archive tape step starting')
    conf = hwrf_expt.conf
    logger = conf.log('archive.disk')
    archive = conf.getloc('archive', 'NONE')
    if conf.has_section('archive'):
        makethedir = conf.getbool('archive', 'mkdir', False)
    else:
        makethedir = False
    if archive == 'NONE':
        logger.info('No archive location specified.  Exiting.')
        postmsg('hwrf_archive disk step has nothing to do when archiving is '
                'disabled.')
        return
    with NamedDir(conf.getdir('com')):
        flist = [filename + '\n' for filename in glob.glob('*')]
        flist.sort()
        files = ''.join(flist)
        assert (len(files) > 0)

        if archive.lower() == 'none':
            postmsg('Archiving is disabled: archive=none')
            return
        elif archive[0:5] == 'disk:':
            logger.info('Disk archiving enabled.')
            logger.info('Nothing to do in the HPSS archiving step.')
            logger.info('Returning successfully after doing nothing.')
            postmsg('hwrf_archive tape step does nothing when using disk '
                    'archives.')
            return
        elif archive[0:5] != 'hpss:' and archive[0:5] != 'hpsz:':
            jlogger.error('Ignoring invalid archive method %s in %s' %
                          (archive[0:4], archive))
            return

        if makethedir:
            adir = os.path.dirname(archive[5:])
            logger.info('%s: make this HPSS directory, even if it exists' %
                        (adir, ))
            mcmd = exe(conf.getexe('hsi'))['-P', 'mkdir', '-p', adir]
            run(mcmd, logger=logger)

        if archive[0:5] == 'hpss:':
            path = archive[5:]
            flags = '-cvp'
            cmd = exe(conf.getexe('htar'))[flags + 'f', path, '-L',
                                           '-'] << files
        elif archive[0:5] == 'hpsz:':

            topath = archive[5:]
            frompath = conf.strinterp('config',
                                      '{WORKhwrf}/stage-archive.tar.gz')
            cmd = exe(conf.getexe('hsi'))['put', frompath, ':', topath]
        checkrun(cmd, logger=logger)
    postmsg('hwrf_archive tape step completed')
def starter(dryrun):
    conf = hwrf_expt.conf
    myrank = int(os.environ['SCR_COMM_RANK'])
    count = int(os.environ['SCR_COMM_SIZE'])
    logger = conf.log('exhwrf_products')
    extra_trackers = conf.getbool('config', 'extra_trackers', False)
    ngribbers = 0
    ncopiers = 0
    run = None
    for rank in xrange(count):
        if rank == 0:
            logger.info('Rank %d runs d03 tracker' % rank)
            if rank == myrank:
                run = lambda: tracker(3)
                whoami = 'tracker'
        elif rank == 1 and extra_trackers:
            logger.info('Rank %d runs d02 tracker' % rank)
            if rank == myrank:
                run = lambda: tracker(2)
                whoami = 'd02tracker'
        elif rank == 2 and extra_trackers:
            logger.info('Rank %d runs d01 tracker' % rank)
            if rank == myrank:
                run = lambda: tracker(1)
                whoami = 'd01tracker'
        elif rank == count - 1:
            logger.info('Rank %d runs wrfcopier' % rank)
            ncopiers += 1
            if rank == myrank:
                run = lambda: copier()
                whoami = 'copier%d' % ncopiers
        else:
            logger.info('Rank %d runs gribber' % rank)
            ngribbers += 1
            if rank == myrank:
                run = lambda: gribber()
                whoami = 'gribber%d' % ngribbers
    if ncopiers < 1 or ngribbers < 2:
        need = 2 + 1 + 1
        if extra_trackers: need += 2
        msg='Cannot run products job with %d processors with these settings.'\
            ' I require at least %d.'%(count,need)
        logger.critical(msg)
        sys.exit(2)
    if dryrun:
        return whoami
    else:
        run()
def main():
    hwrf_expt.init_module()
    conf = hwrf_expt.conf
    if not conf.has_option('archive', 'wrfout'):
        jlogger.info(
            'No wrfout option in [archive] section.  Will not make wrfout archive.'
        )
        sys.exit(0)

    logger = conf.log()

    files = list()
    dt = hwrf.numerics.to_timedelta('6:00:00')
    t0 = conf.cycle
    wrf = hwrf_expt.runwrf.wrf()
    with produtil.cd.NamedDir(hwrf_expt.runwrf.location):
        for i in xrange(22):
            for dom in wrf:
                t = t0 + dt * i
                out = dom.get_output('auxhist3', t)
                if out is None:
                    out = dom.get_output('history', t)
                if out is None:
                    out = dom.get_output('auxhist2', t)
                if out is None:
                    logger.error('%s: could not determine wrfout for '
                                 'domain %s' %
                                 (t.strftime('%Y%m%d%H'), str(dom)))
                if not os.path.exists(out.path()):
                    logger.error('%s: does not exist' % (out.path(), ))
                if not produtil.fileop.isnonempty(out.path(), ):
                    logger.error('%s: is empty' % (out.path(), ))
                files.append(out.path())

        thearchive = conf.timestrinterp('archive', '{wrfout}', 0)
        if thearchive[0:5] != 'hpss:':
            logger.error('The wrfout archive path must begin with "hpss:": ' +
                         thearchive)
            sys.exit(1)
        thearchive = thearchive[5:]
        adir = os.path.dirname(thearchive)
        mkdir = exe(conf.getexe('hsi'))['-P', 'mkdir', '-p', adir]
        run(mkdir, logger=logger)
        cmd = exe(conf.getexe('htar'))['-cpf', thearchive][files]
        checkrun(cmd, logger=logger)
示例#5
0
 def __call__(self,**kwargs):
     """!Expands strings specified in the constructor and calls
     dbn_alert with the results.  If dbn alerts are disabled, then
     the fact that a dbn alert would be run is logged, but
     dbn_alert is NOT called.
     @param kwargs string formatting variables for the dbn alert arguments"""
     assert(job is not None)
     kwargs['job']=str(job)
     alert_args=[ s.format(**kwargs) for s in self.alert_args ]
     if send_dbn_alerts:
         if isinstance(self.alert_exe,basestring):
             cmd=exe(self.alert_exe)[alert_args]
         else:
             cmd=self.alert_exe[alert_args]
         log.log(self.loglevel,'DBN Alert: '+repr(cmd))
         ret=run(cmd)
         log.log(self.loglevel,'Exit status %s from dbn_alert.'%(repr(ret), ))
     else:
         log.log(self.loglevel,'dbn_alert is disabled')
         log.log(self.loglevel,'would run: dbn_alert '+( " ".join(alert_args) ))
示例#6
0
 def __call__(self, **kwargs):
     """!Expands strings specified in the constructor and calls
     dbn_alert with the results.  If dbn alerts are disabled, then
     the fact that a dbn alert would be run is logged, but
     dbn_alert is NOT called.
     @param kwargs string formatting variables for the dbn alert arguments"""
     assert (job is not None)
     kwargs['job'] = str(job)
     alert_args = [s.format(**kwargs) for s in self.alert_args]
     if send_dbn_alerts:
         if isinstance(self.alert_exe, str):
             cmd = batchexe(self.alert_exe)[alert_args]
         else:
             cmd = self.alert_exe[alert_args]
         log.log(logging.INFO, 'DBN Alert: ' + repr(cmd))
         ret = run(cmd)
         exit_log_level = (logging.INFO if ret == 0 else logging.ERROR)
         log.log(exit_log_level,
                 'Exit status %s from dbn_alert.' % (repr(ret), ))
     else:
         log.log(self.loglevel, 'dbn_alert is disabled')
         log.log(self.loglevel,
                 'would run: dbn_alert ' + (" ".join(alert_args)))
示例#7
0
import produtil.setup
import produtil.run
from produtil.run import run, checkrun, exe, mpirun, mpi, alias, \
    ExitStatusException, runstr

# Initialize produtil.  The arguments I send are not necessary, but
# they do make the output more elegant.
produtil.setup.setup(
    send_dbn=False,  # eliminate two "I can't find dbn_alert" warnings
    jobname="example")  # Set the name of the job

logger = logging.getLogger('my/logging/domain')

logger.info('hello world examples')
logger.info('single argument to echo')
run(exe("echo")["hello world"])  # prints => hello world

logger.info('two arguments to echo')
run(exe("echo")["hello", "world"])  # prints => hello world

logger.info('generate command step-by-step')
cmd = exe("echo")
for s in ["hello", "world"]:
    cmd = cmd[s]
run(cmd)  # prints => hello world

logger.info('pass environment variables to sh')
cmd = exe("sh")['-c', '$COMMAND $ENVAR1 $ENVAR2'].env(COMMAND='echo',
                                                      ENVAR1='hello',
                                                      ENVAR2='world')
run(cmd)  # runs sh to print => hello world
示例#8
0
def main_tape():
    """!Main program for tape archiving.  

    Does one of two things:

    * hpss:/path/to/archive.tar --- will use the htar command to
      archive COM directory outputs
    * hpsz:/path/to/archive.tar.gz --- will copy a tar.gz file from a
      temporary area, made by the disk archiving step, to a tape
      destination using the "hsi put" command."""
    postmsg('hafs_archive tape step starting')
    environ_CONFhafs = os.environ.get('CONFhafs', 'NO_CONFhafs')
    #conf=hafs.launcher.HAFSLauncher().read(environ_CONFhafs)
    conf = hafs.launcher.load(environ_CONFhafs)
    logger = conf.log('archive.tape')
    archive = conf.getloc('archive', 'NONE')
    if conf.has_section('archive'):
        makethedir = conf.getbool('archive', 'mkdir', False)
    else:
        makethedir = False
    if archive == 'NONE':
        logger.info('No archive location specified.  Exiting.')
        postmsg('hafs_archive disk step has nothing to do when archiving is '
                'disabled.')
        return
    with NamedDir(conf.getdir('com')):
        flist = [filename + '\n' for filename in glob.glob('*')]
        flist.sort()
        files = ''.join(flist)
        assert (len(files) > 0)

        if archive.lower() == 'none':
            postmsg('Archiving is disabled: archive=none')
            return
        elif archive[0:5] == 'disk:':
            logger.info('Disk archiving enabled.')
            logger.info('Nothing to do in the HPSS archiving step.')
            logger.info('Returning successfully after doing nothing.')
            postmsg('hafs_archive tape step does nothing when using disk '
                    'archives.')
            return
        elif archive[0:5] != 'hpss:' and archive[0:5] != 'hpsz:':
            jlogger.error('Ignoring invalid archive method %s in %s' %
                          (archive[0:4], archive))
            return

        if makethedir:
            adir = os.path.dirname(archive[5:])
            logger.info('%s: make this HPSS directory, even if it exists' %
                        (adir, ))
            mcmd = batchexe(conf.getexe('hsi'))['-P', 'mkdir', '-p', adir]
            run(mcmd, logger=logger)

        if archive[0:5] == 'hpss:':
            path = archive[5:]
            flags = '-cvp'
            cmd = batchexe(conf.getexe('htar'))[flags + 'f', path, '-L',
                                                '-'] << files
        elif archive[0:5] == 'hpsz:':

            topath = archive[5:]
            frompath = conf.strinterp('config',
                                      '{WORKhafs}/stage-archive.tar.gz')
            cmd = batchexe(conf.getexe('hsi'))['put', frompath, ':', topath]
        checkrun(cmd, logger=logger)
    postmsg('hafs_archive tape step completed')
示例#9
0
if clustername in ('tide', 'gyre'):
    WHERE_AM_I = 'wcoss'
elif clustername in ('luna', 'surge'):
    WHERE_AM_I = 'wcoss_cray'
elif clustername in ('mars', 'venus'):
    WHERE_AM_I = 'wcoss_dell_p3'
else:
    WHERE_AM_I = clustername

#   '--login', '-c', '. %s/machine-setup.sh ; which ruby ; which rocotorun ; rocotorun --verbose=5 -d %s -w %s'
#   %( shbackslash(USHhafs), shbackslash(outdb),
cmd = exe('sh') [
    '--login', '-c', '. %s/hafs_pre_job.sh.inc; which ruby ; which rocotorun ; rocotorun --verbose=5 -d %s -w %s'
    %( shbackslash(USHhafs), shbackslash(outdb),
       shbackslash(outxml) ) ] .env(QUIET_PRE_JOB='YES',
                                    HOMEhafs=HOMEhafs,
                                    WHERE_AM_I=WHERE_AM_I) \
                      < '/dev/null'
result = run(cmd, logger=logger)

if result:
    sys.exit(result)
    produtil.jlogger.critical('rocotorun failed')

produtil.log.postmsg('Successfully ran rocotorun for %s.' % (outbase, ))
bakdb = outdb + '.bak'
logger.info('Making a backup copy of .db file here: %s' % (bakdb, ))
produtil.fileop.deliver_file(outdb, bakdb)
logger.info('Success. Rejoice: hurrah!')
##@endcond