# YASARA BioTools # Visit www.yasara.org for more... # Copyright by Elmar Krieger # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA import os,string,shutil,fnmatch,zipfile # ====================================================================== # D I S C F U N C T I O N G R O U P (D S C) # ====================================================================== # CALCULATE FILE CHECKSUM # ======================= def checksum(filename): checksum=0 file=open(filename,"rb") pos=1 a=0 b=0 while (1): data=file.read(1000000) datalen=len(data) i=0 while (i0 and filename[i] not in string.digits): i=i-1 while (i>=0): num=ord(filename[i]) if (num<48 or num>57): break num=num+1 if (num==58): num=48 filename=filename[:i]+chr(num)+filename[i+1:] if (num!=48): break i=i-1 return(filename) # MAKE DIRECTORY CHAIN # ==================== def makedirs(path,permissions=0x1ed): if (not os.path.exists(path)): os.makedirs(path,permissions) # THE PERMISSIONS ARE NOT ALWAYS SET CORRECTLY, DO IT AGAIN chmod(path,permissions) # GET MD5SUM # ========== def md5sum(filename): content=open(filename,"rb").read() md5sum=hashlib.md5(content) return(md5sum.hexdigest()) # GET THE MODIFICATION TIME OF A FILE # =================================== def modtime(filename): if (not os.path.exists(filename)): return(0) else: return(os.path.getmtime(filename)) # GET ALL MODIFICATION TIMES FOR A LIST OF FILES # ============================================== def modtimelist(filenamelist): timelist=[] for filename in filenamelist: timelist.append(modtime(filename)) return(timelist) # CHECK IF TWO FILES ARE THE SAME # =============================== def havesamecontent(filename1,filename2): size1=filesize(filename1) size2=filesize(filename2) if (size1==0 or size1!=size2): return(0) return(open(filename1,"rb").read()==open(filename2,"rb").read()) # BUILD TEMPORARY FILE NAME # ========================= def tmpfilename(filename): dotpos=filename.rfind(".") slashpos=filename.rfind(os.sep) if (dotpos==-1 or dotpos