#!/usr/bin/env python3 import pwd, sys, os, re, shutil, time, subprocess, datetime from pet_misc import * # temp_dir = "/tmp" nusolve_exe = "nuSolve -t /opt64/share/nusolve/scripts/export2vda.js" # def main(): if ( len(sys.argv) < 3 ): print ( "Usage: vdb_to_vda.py VDB-file VDA-file" ) exit ( 1 ) else: vdb_file = sys.argv[1] vda_file = sys.argv[2] ib = vdb_file.rfind("/") ie = vdb_file.rfind(".tgz") vdb_tar_dir = temp_dir + "/" + vdb_file[ib+1:ie] vdb_dir = vdb_tar_dir + "/" + vdb_file[ib+1:ie] vda_output_file = vdb_dir + "/" + vdb_file[ib+1:ie] + ".vda" if ( os.path.isdir ( vdb_tar_dir ) ): print ( "Directory %s already exists" % vdb_dir ) exit ( 1 ) (ret,out) = exe ( "mkdir " + vdb_tar_dir ) if ( ret != 0 ): print ( "Cannot create directory " + vdb_tar_dir + " " ) print ( out ) exit ( 1 ) com = "tar -C " + vdb_tar_dir + " -zxf " + vdb_file (ret,out) = exe ( com ) if ( ret != 0 ): print ( "Cannot create directory " + vdb_dir ) print ( out ) exit ( 1 ) wrp_file_list = [] for path, dirs, files in os.walk(vdb_dir): for file in files: if ( "ngs" in file ): continue if ( ".wrp" in file ): wrp_file_list.append ( path + "/" + file ) if ( len(wrp_file_list) == 0 ): print ( "No wrp files in %s were found" % vdb_dir ) exit ( 1 ) wrp_file_list.sort() wrp_file = wrp_file_list[len(wrp_file_list)-1] iv = wrp_file.rfind("_V") if ( len(wrp_file_list) == 0 ): print ( "Cannot find version in the wrp " % wrp_file ) exit ( 1 ) ## print ( "wrp_file = ", wrp_file ) # %%%%%%%%%%%%%% vers_short_str = wrp_file[iv+2:iv+5] vers_long_str = wrp_file[iv:iv+6] for line in wrp_file_list: if ( vers_long_str in line ): if ( "GSFC_kall" in line ): wrp_file = line com = nusolve_exe + " " + \ wrp_file + " " + \ "VDB" + " " + \ vdb_dir (ret,out) = exe ( com ) if ( ret != 0 ): print ( "Failure in conversion from VGOSDB to VGOSDA" ) print ( out ) exit ( 1 ) if ( not os.path.isfile ( vda_output_file ) ): print ( "Somehow command %s did not generate output file %s\n" % \ ( com, vda_output_file ) ) print ( out ) exit ( 1 ) com = "mv " + vda_output_file + " " + vda_file (ret,out) = exe ( com ) if ( ret != 0 ): print ( "Failure in command " % com ) print ( out ) exit ( 1 ) com = "rm -fR " + vdb_tar_dir (ret,out) = exe ( com ) if ( ret != 0 ): print ( "Failure in command " % com ) print ( out ) exit ( 1 ) print ( "Written output file " + vda_file ) if __name__ == "__main__": global pima_child_pid try: if ( sys.version[:3] < "3.0" ): print ( "This script cannot run under Python-2" ); exit ( 1 ) if ( sys.version[:3] < "3.2" ): print ( "This script cannot run under Python older than 3.2. Please upgrade" ); exit ( 1 ) main() except KeyboardInterrupt: print ( "pf.py: Interrupted" ) exit ( 1 )