Changeset 38958 for trunk/ippToPsps/jython/fits.py
- Timestamp:
- Oct 24, 2015, 2:20:15 PM (11 years ago)
- File:
-
- 1 edited
-
trunk/ippToPsps/jython/fits.py (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/ippToPsps/jython/fits.py
r38956 r38958 8 8 9 9 ''' 10 FITS file class, for reading sillyheaders and things10 FITS file class, for reading headers and things 11 11 ''' 12 12 class Fits(object): … … 35 35 #shutil.copy2(self.originalPath, self.localCopyPath) 36 36 37 # open the local copy and parse the ridiculou plain-textheader37 # open the local copy and parse the header 38 38 #self.file = open(self.localCopyPath) 39 39 self.file = open(self.originalPath) … … 45 45 self.rewindToStart() 46 46 47 48 47 ''' 49 48 Get md5sum for file 50 49 ''' 51 50 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" 55 52 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() 60 58 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() 67 81 68 82 '''
Note:
See TracChangeset
for help on using the changeset viewer.
