#!/usr/bin/env python import os,sys if (sys.hexversion<0x3000000): # PYTHON 2.X FUNCTIONS def binary(text): return(text) def text(binary): return(binary) def byte(value): return(chr(value)) else: # PYTHON 3.X FUNCTIONS def binary(text): return(text.encode("latin-1")) def text(binary): return(binary.decode("latin-1")) def byte(value): return(value) if (len(sys.argv)!=2): print("You must provide the path to the YASARA executable as first argument") else: yasara=open(sys.argv[1],"rb").read() oldurl=binary("cftp.rcsb.org") idx=yasara.find(oldurl) # DOWNLOAD SERVER IS PRESENT AS A SECOND STRING http://"PDB_DOWNLOADSERVER"/view FOR ALIGNMENTS */ if (idx!=-1 and yasara[idx-7:idx]==binary("http://")): idx=yasara.find(oldurl,idx+1) if (idx==-1): if (yasara.find(binary("files.rcsb.org"))!=-1): print("This YASARA executable has already been patched") else: print("The file %s is not a YASARA executable"%sys.argv[1]) else: for i in range(40): if (yasara[idx+14+i]==byte(0)): break print("Replacing RCSB URL, damaging the string '%s'"%text(yasara[idx+14:idx+14+i])) yasara=yasara[:idx]+binary("files.rcsb.org\0")+yasara[idx+15:] open(sys.argv[1],"wb").write(yasara) print("Patch completed")