#!/bin/env python # update the version when significant changes are made program = 'goUSNO' version = '0.13' from sys import exit, argv, stdin from time import gmtime, strftime from string import strip, split, lower, find from os import system, chdir, environ, popen from datetime import datetime # some tunable parameters email = 'ut1@nrao.edu' baseDir = '/home/vlbiobs/astronomy' templateFile = '/users/vlbaops/STDFILES/usno_template.key' #sched_base = '/usr/local/sched' #sched = '/usr/local/sched/bin/sched' # temporary hack to get around bug in released sched version sched_base = '/users/cwalker/files/sched_beta' sched = '/users/cwalker/files/sched_beta/bin/LINUX64SPICE/sched' queueVex = 'queueVex' # add to environment environ['PYTHONPATH'] = '/home/swc/DiFX-trunk-64/lib64/python2.4/site-packages' environ['LD_LIBRARY_PATH'] = '%s:%s' % (environ['LD_LIBRARY_PATH'], '/home/swc/DiFX-trunk-64/lib') environ['LD_LIBRARY_PATH'] = '%s:%s' % (environ['LD_LIBRARY_PATH'], '/home/oracle/LinuxClient_x86_64/product/10.2.0.1/lib') environ['PATH'] = '%s:%s' % (environ['PATH'], '/home/swc/DiFX-trunk-64/bin') environ['ORACLE_BASE'] = '/home/oracle' environ['ORACLE_VERSION'] = '10.2.0.1' environ['ORACLE_HOME'] = '/home/oracle/LinuxClient_x86_64/product/10.2.0.1' environ['VLBA_DB'] = 'vlba/chandra1999@vlba10' environ['SCHED'] = sched_base # NOTHING SHOULD NEED CHANGING BY OPERATIONS BELOW HERE dateFormat = '%Y %b %d [doy %j] %H:%M:%S' verbose = 1 def genDir(start, projectCode): monthnames = ['jan', 'feb', 'mar', 'apr', 'may', 'jun', 'jul', 'aug', 'sep', 'oct', 'nov', 'dec'] return '%s/%s%02d/%s/MARK5C' % (baseDir, monthnames[start[1]-1], start[0]%100, projectCode) def doy(year, mo, day): return datetime(year, mo, day, 0, 0).timetuple().tm_yday def args2time(args, now): mon = int(args[0]) day = int(args[1]) yr = now[0] if mon < now[1]: yr += 1 t = split(args[2]+':0:0', ':') h = int(t[0]) m = int(t[1]) s = int(t[2]) return (yr, mon, day, h, m, s, -1, doy(yr, mon, day), -1) def execute(cmd): if verbose > 1: print 'Executing: %s' % cmd system(cmd) # FIXME: clean up by using datetime now = gmtime() # format: (2011, 9, 12, 15, 47, 47, 0, 255, 0) force = False testmode = False edit = False if strip(popen('uname -s').readline()) != 'Linux': print 'Must be run on a Linux machine' exit(0) args = [] for a in argv[1:]: if a in ['-f', '--force']: force = True elif a in ['-v', '--verbose']: verbose += 1 elif a in ['-q', '--quiet']: verbose -= 1 elif a in ['-t', '--test']: testmode = True elif a in ['-e', '--edit']: edit = True else: args.append(a) if len(args) != 4: print '\n%s version %s\n' % (program, version) print 'Usage: %s [options] \n' % argv[0] print 'options can include:' print ' -f or --force : proceed even if this project has already been queued' print ' -v or --verbose : print more output' print ' -q or --quiet : print less output' print ' -t or --test : schedule project as test' print ' -e or --edit : allow .py files to be edited\n' exit(0) start = args2time(args[1:], now) defaultProjectCode = 'n%d%d' % (start[0]%10, start[7]) projectCode = lower(args[0]) if projectCode == 'auto': projectCode = defaultProjectCode outDir = genDir(start, projectCode) if verbose > 0: print '' print 'Now it is: %s UTC' % strftime(dateFormat, now) print 'Start time scheduled for: %s UTC' % strftime(dateFormat, start) print 'Output directory is: %s' % outDir print 'Project code is: %s' % projectCode print '\nThis program will:' print '1. generate a schedule (.key) file' print '2. run sched to generate .vex and crd files' print '3. run db2vex to add predicted EOPs and clocks to a .vex.preobs file' print '4. run vex2script to generate executor control files' print '5. copy executor Mark5C control files to VLBA stations' print '6. update the Mark5C observ.tx file on the new systems at VLBA stations' print '7. email %s with a confirmation' % email if find(projectCode, defaultProjectCode) < 0: print '\nWARNING: project expected to contain %s but does not!' % defaultProjectCode # Verify the user wants to go ahead # FIXME: should --force skip this? while 1: print '\nDo you wish to continue? [y/n]' a = stdin.readline() if a[0] in ['n', 'N']: print 'Operation cancelled' exit(0) elif a[0] in ['y', 'Y']: break; newFile = '%s.key' % projectCode execute('mkdir -p %s' % outDir) chdir(outDir) execute('mkdir -p %s/sniffer' % outDir) execute('chmod a+w %s/sniffer' % outDir) execute("sed -e 's/%%year%%/%d/' -e 's/%%month%%/%d/' -e 's/%%day%%/%d/' -e 's/%%utc%%/%d:%02d:%02d/' -e 's/%%expcode%%/%s/' <%s >%s" % (start[0], start[1], start[2], start[3], start[4], start[5], projectCode, templateFile, newFile) ) execute("%s < %s" % (sched, newFile) ) execute('db2vex --preobs --force %s.vex' % projectCode) options = "--usno" if edit: options += " --edit" execute("%s %s %s.vex" % (queueVex, options, projectCode) ) if email != None: cmd = "mail -s '%s scheduled' %s" % (projectCode, email) out = popen(cmd, "w") out.write('Start time = %s UTC\n' % strftime(dateFormat, start)) out.write('Project directory = %s\n' % outDir) if testmode: out.write('\n*** This is a test observation and may not provide real data ***\n\n') out.write('\nemail sent by %s version %s\n' % (program, version)) out.close() print '\nFinished.\n' print "*** Don't forget to: ***" print "1. copy crd files to legacy systems" print "2. update observ.tx on legacy systems" print "3. update OMS as necessary" print "************************" print '\nArchive files are in: %s\n' % outDir