"""Run dbd2asc on latest glider binary data ({?}bd) files. Usage: python sbd2asc.py glidername filetype Inputs: glidername [ramses | pelagia] filetype [sbd | tbd | dbd | ...] input path /home/localuser/realtime/{glider}/{filetype}/*.{filetype} output path /home/localuser/realtime/{glider}/{filetype}asc/*.{filetype}asc Example usage: python dbd2asc.py ramses sbd /home/localuser/realtime/ramses/sbd/*.sbd all new *.sbd will be processed to /home/localuser/realtime/ramses/sbdasc/*.sbdasc """ import sys import os import glob import errno import datetime if __name__ == "__main__": try: debug = 0 glider = sys.argv[1] filetype = sys.argv[2] local_dir = "/home/localuser/realtime" # localuser realtime {glider} (sbd) bd_dir = os.path.join(local_dir, glider, filetype) bd_files = glob.glob1(bd_dir, "*." + filetype) for idx,f in enumerate(bd_files): bd_files[idx] = os.path.splitext(f)[0] # localuser realtime {glider} (sbdasc) asc_dir = os.path.join(local_dir, glider, filetype + "asc") asc_files = glob.glob1(asc_dir, "*." + filetype + "asc") for idx,f in enumerate(asc_files): asc_files[idx] = os.path.splitext(f)[0] s = set(bd_files) - set(asc_files) files = list(s) files.sort() if files: for f in files: infile = os.path.join(bd_dir, f + '.' + filetype) dt = datetime.datetime.fromtimestamp(os.stat(infile).st_ctime) dt_str = dt.strftime("_%Y_%m_%d_%H%M") # datetime string added to outfile name for raw2proc # outfile = os.path.join(asc_dir, f + dt_str + '.' + filetype + 'asc') outfile = os.path.join(asc_dir, f + '.' + filetype + 'asc') cache_dir = os.path.join(asc_dir, "cache") if debug: print infile print outfile try: command = "/home/localuser/bin/dbd2asc -c " + cache_dir + " " + infile + " > " + outfile rc = os.system(command) print " ... Processed", outfile except OSError: print "dbd2asc return code: " + str(rc) else: print "Nothing to convert" except: print __doc__