#!/usr/bin/env python # # This is install_drs.py, an install script for all the OSIRIS software # by Marshall Perrin, mperrin@ucla.edu # # To update this script for new releases of the pipeline, search for # the string "UPDATE ME" below. import sys, os, urllib, shutil def file_update_define(filename, keystring, valstring): # print "filename: "+filename if not os.path.exists(filename): print "Trying to update file "+filename print "That file doesn't exist!" exit(1) f = open(filename) textfile = [line for line in f] # read in whole file f.close() f = open(filename,'w') for line in textfile: if line.startswith(keystring): line = keystring+valstring+"\n" f.write(line) f.close() def xml_file_update_define(filename, keystring, valstring): # NOTE: This routine is INCREDIBLY basic and very very fragile. # Probably you could easily make something better than this # by parsing the XML or something like that. print "Updating %s, set %s = %s " % (filename, keystring, valstring) if not os.path.exists(filename): print "That file doesn't exist!" exit(1) f = open(filename) textfile = [line for line in f] # read in whole file f.close() f = open(filename,'w') for line in textfile: if line.startswith(' \n" % (keystring, valstring, comment) f = open(filename,'w') for line in textfile: f.write(line) f.close() def check_files(files): base_url='http://www.astro.ucla.edu/~irlab/osiris/downloads/' for f in files: if not os.path.exists(f): print "Downloading %s from UCLA" % f print " "+base_url+f urllib.urlretrieve(base_url+f, f) def install_drs(): # FILE NAMES TO INSTALL HERE # UPDATE ME FOR NEW RELEASES! default_dir = "/usr/local/osiris" default_data_dir = "~/osiris/" pipeline_tgz = "osiris_pipeline_v2.2.tar.gz" odrfgui_tgz = "odrfgui_v2.2.tar.gz" oopgui_tgz = "oopgui_v1.5.tar.gz" qlook2_tgz = "qlook2_v2.2.tar.gz" osiris_manual = "OSIRIS_Manual_v2.2.pdf" qlook_manual = "qlook2_manual_v2.2.pdf" file_list = [pipeline_tgz,odrfgui_tgz,oopgui_tgz,qlook2_tgz,osiris_manual, qlook_manual] print "" print "" print "******* OSIRIS DRS installation script ******" print "" print " WARNING: This script has ONLY been tested on an Intel Mac" print " and will probably not work anywhere else yet. " print " No guarantees of any sort implied!" print " " print " Questions, comments, and bug reports to " print " Marshall Perrin, mperrin@ucla.edu " print " " print "************************************************" print " " print " READ THIS FIRST: " print " To install the OSIRIS DRS, you need the following things " print " 1) a working copy of IDL, with 'idl' located somewhere in your $PATH " print " 2) the CFITSIO library. On a Mac, you can install this either " print " from source via Fink, or get a binary as part of the " print " SciSoft distribution of astronomy software. " print " 3) about 25 MB for the pipeline itself, plus 160 MB for each " print " extraction matrix, one per filter/pixel scale combination. " print " " print "This script will now ask you a few locations about where these things are " print "located, after which it will download and install the software." print " " print "Into which directory should the DRS be installed?" print "Press enter for default: \"%s\"" % default_dir install_dir = raw_input("Directory? > ").rstrip() if install_dir == "": install_dir=default_dir cwd = os.getcwd() # TODO validate the install dir so that users don't break the script by # including characters that need to be escaped. #TODO check that last character is a '/' if not install_dir.endswith('/'): install_dir = install_dir+"/" if not cwd.endswith('/'): cwd = cwd+"/" print "" print " ====> Will install into %s" % (install_dir) print "" default_matrix_dir = install_dir + "drs/calib" print "In what directory do you want to store the extraction matrices?" print " (The default is almost certainly fine here, unless you " print " already have some other directory full of extraction matrices.) " print "Press enter for default: \"%s\"" % default_matrix_dir matrix_dir = raw_input("Directory? > ").rstrip() if matrix_dir == "": matrix_dir=default_matrix_dir cwd = os.getcwd() # TODO validate the matrix dir so that users don't break the script by # including characters that need to be escaped. #TODO check that last character is a '/' if not matrix_dir.endswith('/'): matrix_dir = matrix_dir+"/" if not cwd.endswith('/'): cwd = cwd+"/" print "" print " ====> Will look for matrices in %s" % (matrix_dir) print "" print "In what directory do you like to keep your OSIRIS data?" print " (This doesn't really matter much; it just sets the default path" print " that the GUI's File | Open dialog boxes look in first, but " print " you can always pick another directory then.)" print "Press enter for default: \"%s\"" % default_data_dir data_dir = raw_input("Directory? > ").rstrip() if data_dir == "": data_dir=default_data_dir print "" print " ====> Default data dir is %s" % (install_dir) print "" ############# Figure out where IDL is installed print "To compile the datacube extraction routine, I need to know where your" print "IDL header file is installed." #print "In what directory is IDL's idl_export.h file?" handle = os.popen('which idl') idlpath = handle.readline().rstrip() handle.close() if idlpath == "" : print "I can't find IDL in your path, so the default guess is probably wrong!" idlexternpath = "/usr/local/rsi/idl/external/include" else: print " IDL found at "+idlpath if not os.path.exists(idlpath): print "That path doesn't exist!!" return 1 if os.path.islink(idlpath): idlpath = os.readlink(idlpath) print " That path is a symlink , pointing to "+idlpath idx = idlpath.find('bin/idl') if idx > -1: idlexternpath = idlpath idlexternpath = idlexternpath.replace('bin/idl', 'external/include') if os.path.exists(idlexternpath+"/idl_export.h"): print "I believe I have located idl_export.h in the following directory:" print idlexternpath print " " print "In which directory is IDL's idl_export.h?" print "Press enter for default: \"%s\"" % idlexternpath idlextern_dir = raw_input("Directory? > ").rstrip() if idlextern_dir == "": idlextern_dir=idlexternpath if not os.path.exists(idlextern_dir+"/idl_export.h"): print "ERROR: There is no idl_export.h in that directory!" print "" print " ====> Using IDL idl_export.h from %s" % (idlextern_dir) print "" ############# Where is cfitsio? print " " print "In which directory is the CFITSIO library?" # ostype = os.popen('uname -s') # if ostype =="Darwin": # ver = os.popen('uname -r | cut -f 1 -d "."') # if ver == '8' then arch = os.popen('uname -am') else arch=('uname -sm') cfitsiopath = "" # default is we don't know. handle = os.popen('uname -sp') arch = handle.readline().rstrip() handle.close() if arch == "Darwin i386": cfitsiopath = "/scisoft/i386/lib/" if arch == "Darwin ppc" or arch=="Darwin powerpc": cfitsiopath = "/scisoft/cfitsio/lib" print "Press enter for default: \"%s\"" % cfitsiopath cfitsio_dir = raw_input("Directory? > ").rstrip() if cfitsio_dir == "": cfitsio_dir=cfitsiopath print "" print " ====> Using cfitsio from %s" % (cfitsio_dir) print "" print "After installing, delete temporary files (the downloaded .tar.gzs of the code)?" delete_when_done = raw_input("[y/N] > ").upper() == "Y" ############# Get the files - either from current directory or the internet check_files(file_list) ############ Do the actual install - untarring files, etc. if not os.path.exists( install_dir ): print " That directory does not exist; creating it now..." os.mkdir( install_dir ) os.system("tar -C %s -xvzf %s " % (install_dir, pipeline_tgz)) if not os.path.exists( install_dir+"odrfgui"): os.mkdir (install_dir+"odrfgui") os.system("tar -C %s -xvzf %s " % (install_dir+"odrfgui", odrfgui_tgz)) if not os.path.exists( install_dir+"oopgui"): os.mkdir (install_dir+"oopgui") os.system("tar -C %s -xvzf %s " % (install_dir+"oopgui", oopgui_tgz)) #qlook2 is already in the 'ql2' directory in the TGZ file os.system("tar -C %s -xvzf %s " % (install_dir, qlook2_tgz)) if not os.path.exists( matrix_dir ): print " The directory %s does not exist; creating it now..." % matrix_dir os.mkdir( matrix_dir ) #### First, update the shell setenvs files. file_update_define(install_dir+"drs/modules/source/local_Makefile","IDL_INCLUDE = ", idlextern_dir) file_update_define(install_dir+"drs/modules/source/local_Makefile","CFITSIOLIBDIR = ", cfitsio_dir) file_update_define(install_dir+"drs/scripts/setup_osirisDRPSetupEnv","setenv OSIRIS_ROOT ", install_dir+"drs") #file_update_define(install_dir+"oopgui/oopgui","OOPGUI_DIR=", install_dir+"oopgui \n cd $OOPGUI_DIR") # OK, this is an ugly hack here, since I'm essentially rewriting OOPGUI entirely to allow starting from arbitrary directories newoopcmd = "OOPGUI_DIR=%soopgui\ncd $OOPGUI_DIR\njava -Djava.security.policy=java.policy.oopgui -jar $OOPGUI_DIR/oopgui.jar cfg=$OOPGUI_DIR/oopgui_cfg.xml" % install_dir #file_update_define(install_dir+"oopgui/oopgui.bat","java", newoopcmd ) f = open(install_dir+"oopgui/oopgui.bat", "w") f.write(newoopcmd) f.close # OK, this is an ugly hack here, since I'm essentially rewriting ODRFGUI entirely... newodrfcmd = "ODRFGUI_DIR=%sodrfgui\ncd $ODRFGUI_DIR\njava -Djava.security.policy=java.policy.odrfgui -jar $ODRFGUI_DIR/odrfgui.jar cfg=$ODRFGUI_DIR/odrfgui_cfg.xml" % install_dir #file_update_define(install_dir+"odrfgui/odrfgui.bat","java", newodrfcmd ) f = open(install_dir+"odrfgui/odrfgui.bat", "w") f.write(newodrfcmd) f.close #### Now, update the shell scripts to start the programs. scriptdir = install_dir+"drs/scripts/" # add links in the script directory for the other files # first, check for old versions if os.path.exists(scriptdir+"oopgui"): os.remove(scriptdir+"oopgui") os.symlink(install_dir+"oopgui/oopgui.bat", scriptdir+"oopgui") if os.path.exists(scriptdir+"odrfgui"): os.remove(scriptdir+"odrfgui") os.symlink(install_dir+"odrfgui/odrfgui.bat", scriptdir+"odrfgui") if os.path.exists(scriptdir+"run_ql2"): os.remove(scriptdir+"run_ql2") os.symlink(install_dir+"ql2/run_ql2", scriptdir+"run_ql2") if os.path.exists(scriptdir+"run_iql2"): os.remove(scriptdir+"run_iql2") os.symlink(install_dir+"ql2/run_iql2", scriptdir+"run_iql2") if os.path.exists(scriptdir+"run_sql2"): os.remove(scriptdir+"run_sql2") os.symlink(install_dir+"ql2/run_sql2", scriptdir+"run_sql2") if os.path.exists(scriptdir+"run_oql2"): os.remove(scriptdir+"run_oql2") os.symlink(install_dir+"ql2/run_oql2", scriptdir+"run_oql2") if cwd != install_dir: #print "Need to move PDFs to install dir" shutil.copy(cwd+osiris_manual, install_dir+osiris_manual) shutil.copy(cwd+qlook_manual, install_dir+qlook_manual) #### Compile the module os.chdir(install_dir+"drs/modules/source/") os.system("make -f local_Makefile") if not os.path.exists(install_dir+"drs/modules/source/libosiris_drp_ext_null.so.0.0"): print "ERROR: Compilation of libosiris library failed!" print " Investigate the problem with local_Makefile in " print " %sdrs/modules/source/" % install_dir return 2 else: print "\nlibosiris compiled successfully!\n" os.chdir(cwd) # return to original directory #### Now, update the configuration file for ODRFGUI xml_file_update_define(install_dir+'odrfgui/odrfgui_cfg.xml','DEFAULT_INPUT_DIR',data_dir) xml_file_update_define(install_dir+'odrfgui/odrfgui_cfg.xml','DEFAULT_OUTPUT_DIR',data_dir) xml_file_update_define(install_dir+'odrfgui/odrfgui_cfg.xml','DEFAULT_LOG_DIR',data_dir) xml_file_update_define(install_dir+'odrfgui/odrfgui_cfg.xml','DRF_QUEUE_DIR',install_dir+"drs/drf_queue/") xml_file_update_define(install_dir+'odrfgui/odrfgui_cfg.xml','DRF_READ_PATH',data_dir) xml_file_update_define(install_dir+'odrfgui/odrfgui_cfg.xml','DRF_WRITE_PATH',data_dir) xml_file_update_define(install_dir+'odrfgui/odrfgui_cfg.xml','OSIRIS_DRP_BACKBONE_CONFIG_FILE',install_dir+"drs/backbone/SupportFiles/RPBconfig.xml") xml_file_add_define(install_dir+'odrfgui/odrfgui_cfg.xml', 'OSIRIS_CALIB_ARCHIVE_DIR', matrix_dir,"OSIRIS Calibration Data Archive") ############# And now we're done!! print " ***************************************************** " print " " print "OSIRIS Software Installed Successfully!" print " * Data Reduction System (drs)" print " * OSIRIS Observation Planning GUI (oopgui)" print " * OSIRIS Data Reduction File GUI (odrfgui)" print " * Quicklook 2 (ql2)" print "" print "" print " You should now add the following lines to your shell config files:" print "" print " source %s" % scriptdir+"setup_osirisDRPSetupEnv" print " setenv PATH ${PATH}:${OSIRIS_ROOT}/scripts" print " setenv IDL_PATH ${IDL_PATH}:+${OSIRIS_ROOT}/ql2" print "" print "You can then type 'run_odrp', 'run_ql', 'oopgui', 'odrfgui' at your shell" print "or start IDL and run 'ql' directly. " print "" print "Note that you will need to download the desired rectification matrices" print "from http://tkserver.keck.hawaii.edu/osiris/" print "(These are huge, 150 MB each, so they are not automatically downloaded.)" print "You should then install these files into the following directory: " print " "+matrix_dir print " " print "See the OSIRIS manual in %s for more info." % install_dir print " " print "You can further customize your directory path settings for ODRFGUI by editing " print "the ODRFGUI config file, %s" % (install_dir+"odrfgui/odrfgui/odrfgui_cfg.xml") print "See %s for more info. " % (install_dir+"odrfgui/README") print " " print " Good luck!" print "" print "" if delete_when_done: for f in file_list: if f.endswith('.tar.gz'): os.remove(f) else: # don't remove the PDFs if we're already in the install dir if cwd != install_dir: os.remove(f) return 0 if __name__ == "__main__": sys.exit(install_drs()) if __name__ == "Test": # This just tests the XML updating routines... shutil.copy('/usr/local/osiris/odrfgui/odrfgui_cfg.xml.bak','/usr/local/osiris/odrfgui/odrfgui_cfg.xml') install_dir = "/usr/local/osiris/" matrix_dir = install_dir+"drs/calib/" data_dir = "~/data/osiris/" xml_file_update_define(install_dir+'odrfgui/odrfgui_cfg.xml','DEFAULT_INPUT_DIR',data_dir) xml_file_update_define(install_dir+'odrfgui/odrfgui_cfg.xml','DEFAULT_OUTPUT_DIR',data_dir) xml_file_update_define(install_dir+'odrfgui/odrfgui_cfg.xml','DEFAULT_LOG_DIR',data_dir) xml_file_update_define(install_dir+'odrfgui/odrfgui_cfg.xml','DRF_QUEUE_DIR',install_dir+"drs/drf_queue/") xml_file_update_define(install_dir+'odrfgui/odrfgui_cfg.xml','DRF_READ_PATH',data_dir) xml_file_update_define(install_dir+'odrfgui/odrfgui_cfg.xml','DRF_WRITE_PATH',data_dir) xml_file_update_define(install_dir+'odrfgui/odrfgui_cfg.xml','OSIRIS_DRP_BACKBONE_CONFIG_FILE',install_dir+"drs/backbone/SupportFiles/RPBconfig.xml") xml_file_add_define(install_dir+'odrfgui/odrfgui_cfg.xml', 'OSIRIS_CALIB_ARCHIVE_DIR', matrix_dir,"OSIRIS Calibration Data Archive")