#!/usr/bin/python # File: update.py import os import commands import string from stat import * from ftplib import FTP from threading import Thread from Tkinter import * # # FTP thread # class FTPthread(Thread): def __init__( self, master, host, path, file ): self.master = master self.host = host self.path = path self.file = file Thread.__init__( self ) def run( self ): self.master.message( "Contacting "+self.host ) self.opfile = open( self.file, 'w') ftp = FTP( self.host ) ftp.login() ftp.cwd( self.path ) ftp.retrbinary( "RETR "+self.file, self.write_and_count_line ) ftp.quit() self.opfile.close() self.master.status() def write_and_count_line( self, block ): self.opfile.write( block ) self.master.update() # # Install thread # class Installthread(Thread): def __init__( self, master ): self.master = master Thread.__init__( self ) def run( self ): self.master.message( "Installing: please wait" ) homedir = os.getcwd() os.chdir( self.master.dir.get() ) print commands.getoutput("tar xvfz " + homedir + "/" + ftpsrcfile) os.chdir( version ) print commands.getoutput("tar xvfz " + homedir + "/" + ftpbinfile) self.makesetup( "include/ccp4.setup-dist", "include/ccp4.setup" ) self.makesetup( "include/ccp4.setup-bash", "include/ccp4.setup.sh" ) f = open( "ccp4get.sh", "w" ) f.write( "date > $HOME/.agree2ccp4\n" ) f.write( "source include/ccp4.setup.sh\n" ) f.write( "source BINARY.setup\n" ) f.close() print commands.getoutput("/bin/bash ccp4get.sh") print "\nInstalled\n" self.master.message( "Installed" ) def makesetup( self, ifile, ofile ): setup = [] f = open( ifile, "r" ) setup = f.readlines() f.close() for i in range(0,len(setup)): setup[i] = string.replace( setup[i], "/xtal", self.master.dir.get() ) setup[i] = string.replace( setup[i], "/usr/local/bin", "/usr/bin" ) setup[i] = string.replace( setup[i], "/tmp/$USER", self.master.tmp.get() ) setup[i] = string.replace( setup[i], "lp -s -denscript", self.master.prt.get() ) setup[i] = string.replace( setup[i], "lp -s -dmicrolaser", self.master.plt.get() ) f = open( ofile, "w" ) f.writelines( setup ) f.close() # # Warrenty disclaimer # class Disclaim: def __init__( self, master ): # make a window frame1 = Frame( master ) frame1.pack(side=TOP) frame2 = Frame( master ) frame2.pack(side=BOTTOM) Label(frame1, text="Warning: Use of this installer is conditional on the following terms:").pack(side=TOP) scrollbar = Scrollbar(frame1) scrollbar.pack(side=RIGHT, fill=Y) text = Text(frame1,yscrollcommand=scrollbar.set) text.insert(END, " CCP4 Software Licence\n\nPREAMBLE\n\nThe purpose of this document is to state the terms and conditions under which \nthe CCP4 Program Suite software and documentation as defined at Annex 1 ('the \nCCP4 suite') may be used.\n\n\nNOTICE TO USER:\n\nBY USING THE SOFTWARE YOU ACCEPT THE FOLLOWING TERMS AND CONDITIONS WHICH APPLY \nTO ITS USE.\n\n1. The CCP4 Suite is compiled at Daresbury Laboratory with support from \nthe Biotechnology and Biological Sciences Research Council (BBSRC) of the UK \nas part of the Collaborative Computational Project Number 4 (CCP4), on Protein \nCrystallography, first set up in October 1979.\n\n2. Any opinion, findings, conclusions or recommendations expressed in the \nCCP4 program suite are those of the authors/contributors and do not necessarily \nreflect the views of the BBSRC.\n\n3. The CCP4 suite is in part the property of the Council for the Central \nLaboratory of the Research Councils ('CCLRC'). Additionally extra modules may \nbe supplied which are not specifically owned by the Council. These may be the \ncopyright of a third party and are distributed under terms, which as far as \nthe Council is aware, permit them to be included within the terms of this \nLicence. If this is so this notification or declaration that the information is\nin the public domain will be included in the files. The Council shall, in all \ngood faith, distribute these modules in compliance with the terms and \nconditions as set down by the third party. The Council shall not be liable and \nshall take no responsibility for any module that is not the property of the \nCouncil.\n\n4. The CCP4 suite is made available free of charge for use by non-profit \neducational, academic and research institutions. However, as the distribution \nof the CCP4 suite can prove to be an expensive commitment, non-profit \ninstitutions requiring versions to be distributed on magnetic tape or disk may \nbe asked to pay for the time and media involved. No recipient of the CCP4 suite\nand or material shall offer magnetic tapes, microfiche, listings or any further\nCCP4 item for sale as a commercial item. \n\n5. For items of the CCP4 suite considered as being of Part (i) (Annex 1), \n(and for items considered as Part (ii) (Annex 1) of the CCP4 distribution that \ndo not have an explicit statement of warranty then the following warranty \nstatement also applies) these are supplied under the following conditions:- \n\n i) The CCP4 suite is provided to the user 'as is' and neither CCLRC\n nor the original authors/contributors make any warranty as to its use,\n performance or results which the user may obtain by using the CCP4\n suite. CCLRC makes no warranties, express or implied, as to\n non-infringement of third party rights, merchantability, or fitness\n for any particular purpose. In no event will CCLRC or original\n authors/contributors be liable to the user for any consequential,\n incidental or special damages, including any lost profits or lost\n savings, even if a CCLRC representative or original\n authors/contributors has been advised of such damages, or for any\n claim by any third party.\n\n\n6. For items of the CCP4 suite considered as being Part (ii) and \nPart (iii) (Annex 1), if the authors have given a statement of copyright and \nwarranties then those notices apply to those items of the CCP4 suite.\n\n7. As part of CCP4's two goals of preserving the free status of all of \nour free software (and derivatives), and of promoting the sharing and reuse \nof software generally, then for items of software considered as being of \npart (i) (Annex 1), the CCP4 library routines, you are permitted and encouraged\nto use, copy, modify and distribute this software and its documentation for \nany purpose and without fee. A notice to 'CCP4/Daresbury Laboratory' must \nappear in all copies, and the User must do the following:\n\n(a) cause the modified files to carry prominent notices stating that you \nchanged the files and the date of any change, and to provide those changes \nback to the community;\n\n(b) for the whole of any work that you distribute or publish, that in whole\nor in part contains the Part (i) (Annex 1) routines or any part thereof, \neither with or without modifications, then any subsequent licence that you \ncharge to all third parties must exclude the CCP4 Part (i) (Annex 1) software \nand such Part (i) (Annex 1) software can only be included under the terms of \nthis Conditions of Distribution (except that you may choose to grant warranty \nprotection to some or all third parties, at your option).\n\n8. For a single site that requires more than one implementation of the \nCCP4 distribution the User may copy verbatim copies of the CCP4 distribution \nas they receive it, in any medium at that site, provided that the User \nconspicuously and appropriately publishes on each copy an appropriate copyright\nnotice and disclaimer of warranty.\n\n9. The User may not copy, modify, sublicence, distribute or transfer the \nCCP4 suite except as expressly provided under either this agreement or as in \nthe case of the CCP4 suite considered as either Part (ii) or Part (iii) \n(Annex 1) by the Copyright notices of the original authors. Any attempt \notherwise to copy, modify, sublicence, distribute or transfer the CCP4 suite \nis void, and will automatically terminate your rights to use the CCP4 suite \nunder this Agreement.\n\n10. Neither the CCLRC nor the original authors are under any obligation to \nmaintain the CCP4 suite nor to respond to requests for information from the \nUser. \n\n11. The provision of any version of the CCP4 suite under the terms and \nconditions specified herein does not imply that future versions will also be \nmade available under the same terms and conditions.\n\n12. For any publication arising from use of the CCP4 program suite, a \nreference to (Collaborative Computational Project, Number 4, 1994) should be \ngiven as:\n\nCOLLABORATIVE COMPUTATIONAL PROJECT, NUMBER 4, 1994.\n'The CCP4 Suite: Programs for Protein Crystallography'. Acta Cryst. \n D50, 760-763.\n\nalong with any additional references, required by the original authors, \npertaining to individual programs where the use of the programs contributed \nto an investigation.\n\n13. The CCP4 suite (with respect to this license agreement) will be used \nsolely at the following address:\n\nName ___________________________________\n\nAddress ___________________________________\n\n ___________________________________\n\n ___________________________________\n\n\nTelephone ___________________________________ \n\nFax __________________________________________\n\nE-mail ___________________________________\n\n\nI have read the CCP4 Software Licence (including Annex 1) and I agree to \nuphold the terms and conditions of this licence:\n\n\nName ____________________ Signed ____________________\n\nPosition ____________________ Date ____________________\n\n\n\n\nUnder the terms of the UK's DATA PROTECTION ACT 1984, we are obliged to notify \nyou that you are on a CCP4 mailing list and that your name and address are held\non computer. The Act requires your consent to your name and address being so \nheld. Our receipt of this completed form will indicate your acceptance.\n\n\n\n\n\n\n ANNEX 1\n\nThe CCP4 Program Suite consists of three parts:\n\ni) The set of Library routines for the handling of MAP files, MTZ files \nand PDB files and the general routines for DISKIO, CCPLIB, (parts of) MODLIB, \nFFTLIB, PLOT84LIB, SYMLIB, CCIFLIB, HARVLIB, LIBHTML, should be regarded as \n'Free-Software', with Copyright still remaining with the original authors \nand/or their place of employment where that software was written as employees \nin the course of their employment, and is freely available from CCP4 and the \nBBSRC.\n This software is held in the subdirectories src and ccif in:\n CCP4_MASTER: [CCP4.LIB] (for the VMS distribution),\n %CCP4_MASTER%\ccp4\lib (for DOS based systems),\n and $CCP4_MASTER/ccp4/lib (for the Unix distribution).\n\nii) Contributed programs which use the part (i) library routines. For this \nset of software all copyrights remain with the original authors of the code. If\na Part (ii) program does not contain a Copyright notice then this Copyright \nnotice applies.\n Examples of this software are held in directories:\n VMS: CCP4_MASTER: [CCP4.SRC];\n DOS: %CCP4_MASTER%\ccp4\src;\n Unix: $CCP4_MASTER/ccp4/src\n\niii) Other independent works which have been merely aggregated to the CCP4 \ndistribution media, where the Advisory Notices and/or Copyright Notices for \nthis other work allow for the free distribution of that code. This set of \nsoftware (or their derivatives) that are held on the CCP4 volume of storage \nor distribution medium are not brought under the scope of the terms of the \nCCP4 distribution conditions.\n Examples of this software are held in the directories:\n VMS Unix\n $CCP4_MASTER:[XTAL.WULFF] $CCP4_MASTER/wulff\n $CCP4_MASTER:[XTAL.LAUE] $CCP4_MASTER/laue\n\n\nThe distribution tape and ftp area contains copies of all programs in the CCP4 \nsuite (source code) plus documentation and shell files for running the programs\ninteractively.\n") text.pack(side=LEFT, fill=BOTH) scrollbar.config(command=text.yview) Button(frame2, text="I accept", command=frame2.quit).pack(side=LEFT) Button(frame2, text="I decline", command=self.quit).pack(side=RIGHT) def quit( self ): raise SystemExit # # Main application # class App: def __init__( self, master ): self.host = IntVar() self.dir = StringVar() self.tmp = StringVar() self.prt = StringVar() self.plt = StringVar() self.stat = StringVar() self.host.set(1) self.dir.set( os.getcwd() ) self.tmp.set( "/tmp/$USER" ) self.prt.set( "lpr" ) self.plt.set( "lpr" ) self.message( "Idle" ) # chose ftp host Label(master,text="FTP host: ").grid(row=0,column=0) Radiobutton(master, text="UK", variable=self.host, value=1).grid(row=0,column=1) Radiobutton(master, text="US", variable=self.host, value=2).grid(row=0,column=2) Radiobutton(master, text="JP", variable=self.host, value=3).grid(row=0,column=3) # text fields Label(master, text="Target directory:" ).grid(row=1,column=0) Entry(master, textvariable=self.dir, width=40).grid(row=1,column=1,columnspan=3) Label(master, text="Temporary directory:" ).grid(row=2,column=0) Entry(master, textvariable=self.tmp, width=40).grid(row=2,column=1,columnspan=3) Label(master, text="Print command:" ).grid(row=3,column=0) Entry(master, textvariable=self.prt, width=40).grid(row=3,column=1,columnspan=3) Label(master, text="Plot command:" ).grid(row=4,column=0) Entry(master, textvariable=self.plt, width=40).grid(row=4,column=1,columnspan=3) # status frame Label(master, text="Status:" ).grid(row=5,column=0) Label(master, textvariable=self.stat, width=40, relief=GROOVE ).grid(row=5,column=1,columnspan=3) # buttons self.button_dl = Button(master, text="Download", width=8, command=self.download) self.button_dl.grid(row=6,column=1) self.button_in = Button(master, text="Install", width=8, command=self.install) self.button_in.grid(row=6,column=2) Button(master, text="Quit", width=8, command=self.quit).grid(row=6,column=3) self.button_dl.configure(state = ACTIVE) self.button_in.configure(state = DISABLED) self.message( "Ready to download" ) # set button states self.status() def download( self ): self.button_dl.configure(state = DISABLED) self.button_in.configure(state = DISABLED) ftpthread = FTPthread( self, ftphost[self.host.get()], ftppath[self.host.get()]+"packed/", ftpsrcfile ) ftpthread.start() ftpthread = FTPthread( self, ftphost[self.host.get()], ftppath[self.host.get()]+"binaries/", ftpbinfile ) ftpthread.start() def install( self ): self.button_dl.configure(state = DISABLED) self.button_in.configure(state = DISABLED) installthread = Installthread( self ) installthread.start() def message( self, msg ): self.stat.set( msg ) def update( self ): count = 0; if ( os.access( ftpsrcfile, os.F_OK) ): count = count + os.stat( ftpsrcfile )[ST_SIZE] if ( os.access( ftpbinfile, os.F_OK) ): count = count + os.stat( ftpbinfile )[ST_SIZE] count = count / ( (ftpsrcsize+ftpbinsize)/100 ) self.message( "Downloading: " + str( count ) + "%" ) def status( self ): if ( os.access( ftpsrcfile, os.F_OK ) & os.access( ftpbinfile, os.F_OK ) ): if ( ( os.stat( ftpsrcfile )[ST_SIZE] == ftpsrcsize ) & ( os.stat( ftpbinfile )[ST_SIZE] == ftpbinsize ) ): self.button_dl.configure(state = DISABLED) self.button_in.configure(state = ACTIVE) self.message( "Ready to install" ) def quit( self ): raise SystemExit # # The main program # global ftphost, ftppath, ftpfile, ftpsize, version ftphost = "ftp.ysbl.york.ac.uk", "ftp.ccp4.ac.uk", "ftp.sdsc.edu", "ftp.protein.osaka-u.ac.jp" ftppath = "pub/ccp4fl/", "pub/ccp4/4.2.1/", "pub/sdsc/xtal/CCP4/4.2.1/", "mirror/ccp4/ccp4/4.2.1/" ftpsrcfile = "ccp4-4.2.1.tar.gz" ftpbinfile = "ccp4-4.2.1_Linux.tar.gz" ftpsrcsize = 37054357 ftpbinsize = 23883508 version = "ccp4-4.2.1" win1 = Tk() win1.title( "CCP4 version 4.2.1 for Linux binary installer" ) Disclaim( win1 ) win1.mainloop() win1.withdraw() win2 = Toplevel() win2.title( "CCP4 version 4.2.1 for Linux binary installer" ) App( win2 ) win2.mainloop()