IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Oct 24, 2015, 2:20:15 PM (11 years ago)
Author:
eugene
Message:

adjust md5sum code to put options into single location; test for AP_NPIX before trying to use in diffbatch; apply static plate scale in stackbatch; add FW source X,Y, ccdID

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/ippToPsps/jython/fits.py

    r38956 r38958  
    88
    99'''
    10 FITS file class, for reading silly headers and things
     10FITS file class, for reading headers and things
    1111'''
    1212class Fits(object):
     
    3535       #shutil.copy2(self.originalPath, self.localCopyPath)
    3636
    37        # open the local copy and parse the ridiculou plain-text header
     37       # open the local copy and parse the header
    3838       #self.file = open(self.localCopyPath)
    3939       self.file = open(self.originalPath)
     
    4545       self.rewindToStart()
    4646
    47 
    4847    '''
    4948    Get md5sum for file
    5049    '''
    5150    def getMd5sum(self):
    52         ## memory inefficient all at once read but should be ok...
    53         md5 = hashlib.md5(open(self.originalPath,'rb').read())
    54         return md5.hexdigest()
     51        mode = "hashlib"
    5552
    56     def getMd5sumShell(self):
    57         md5cmd = "md5sum %s" % (self.originalPath)
    58         md5 = Popen(md5cmd, shell=True, stdout=PIPE).stdout.read()
    59         return md5[0:32]
     53        if mode == "hashlib":
     54            ## memory-inefficient all-at-once read
     55            ## XXX EAM: do we need to free the loaded file to prevent double-usage of memory
     56            md5 = hashlib.md5(open(self.originalPath,'rb').read())
     57            return md5.hexdigest()
    6058
    61     def getMd5sumFile(self):
    62         ## unclear if rb by default for file so maybe not best
    63         md5 = hashlib.md5(self.file.read())
    64         ## if used, then need to move file pointer back to the start of the file for others to use
    65         self.rewindToStart()
    66         return md5.hexdigest()
     59        if mode == "shell":
     60            ## use external shell md5sum command: error handline needs to check the exit status
     61            md5cmd = "md5sum %s" % (self.originalPath)
     62            p = Popen(md5cmd, shell=True, stdout=PIPE)
     63            p.wait()
     64            if p.returncode < 0:
     65                self.logger.errorPair("md5sum crashed: ", md5cmd)
     66                os._exit(1)
     67               
     68            if p.returncode > 0:
     69                self.logger.errorPair("md5sum error : ", md5cmd)
     70                os._exit(1)
     71
     72            md5 = p.stdout.read()
     73            return md5[0:32]
     74
     75        if mode == "file":
     76            ## it is unclear if the open mode is 'rb' by default for file; this may fail otherwise
     77            md5 = hashlib.md5(self.file.read())
     78            ## if used, then need to move file pointer back to the start of the file for others to use
     79            self.rewindToStart()
     80            return md5.hexdigest()
    6781
    6882    '''
Note: See TracChangeset for help on using the changeset viewer.