sgeenviron.py
#!/usr/bin/python
# * Copyright 2010. The Regents of the University of California.
# * All Rights Reserved.
# * @author Prakashan Korambath
# *
# * Purpose: Make use of scheduler TMPDIR variable for File I/O. The scratch space
# * defined in SGE is often has a faster I/O than NFS file system. So your codes
# * may run faster if you use TMPDIR to write scratch files which are not needed
# * at the end of a run. The scheduler used on Hoffman2 is Oracle Grid Engine.
# * In place of TMPDIR any other faster SCRATCH space can be substituted.
# *
# * This software program and documentation are copyrighted by The Regents
# * of the University of California. The software program and documentation
# * are supplied "as is", without any accompanying services from The Regents.
# * The Regents does not warrant that the operation of the program will be
# * uninterrupted or error-free. The end-user understands that the program
# * was developed for research purposes and is advised not to rely exclusively
# * on the program for any reason.
#
# * IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR
# * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING
# * LOST PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION,
# * EVEN IF THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY
# * OF SUCH DAMAGE. THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY
# * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
# * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED
# * HEREUNDER IS ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO
# * OBLIGATIONS TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR
# * MODIFICATIONS.
# *
# *
import os, string
# * Get SGE TMPDIR environment variable
try:
tmpdir=os.environ["TMPDIR"]
except KeyError:
print 'Failed to get environment variable TMPDIR'
tmpdir='/work'
print 'TMPDIR is ' + tmpdir
# * scrathc file name. Do not forget leading / character
scratch1='/scratchxxx'
filepath=tmpdir+scratch1
print 'Full filepath is ' + filepath
usefulData='FirstName' + '\n' + 'LastName' + '\n'
# * open and output file and write something
output_file = open(filepath, 'w')
output_file.write(usefulData)
output_file.close()
# * oepn the same file for reading
input_file = open(filepath, 'r')
line = input_file.readline()
while line:
print line.strip()
line = input_file.readline()
input_file.close()
try:
os.remove(filepath)
except os.error:
print filepath + ' could not be deleted'