- Timestamp:
- 05/02/07 09:39:11 (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/bin/asap_update_data
r1183 r1363 1 1 #!/usr/bin/env python 2 import urllib23 2 import os 4 3 import tarfile 4 import shutil 5 from ftplib import FTP 5 6 6 import shutil 7 # globals 8 md5suff = '.md5sum' 9 name = 'asap_data.tar.bz2' 10 dataurl = "ftp.atnf.csiro.au" 11 tmpdata = '/tmp/asap_data.tar.bz2' 12 datadir = 'pub/software/asap/data' 13 tmpmd5 = tmpdata+md5suff 7 14 8 name = 'asap_data.tar.bz2' 9 dataurl = "http://www.atnf.csiro.au/pub/software/asap/data/" 10 tmpdata = '/tmp/asap_data.tar.bz2' 11 tmpmd5 = tmpdata+'.md5sum' 12 15 ftp = FTP(dataurl) # connect to host, default port 16 ftp.login() # user anonymous, passwd anonymous@ 17 ftp.cwd(datadir) 13 18 print "Checking if an update is required." 14 md5req = urllib2.Request(dataurl+name+'.md5sum') 15 response = urllib2.urlopen(md5req) 16 md5file = file(tmpmd5,'w') 17 md5file.write(response.read()) 18 md5file.close() 19 ftp.retrbinary('RETR %s' % name+md5suff, open(tmpmd5, 'wb').write) 19 20 md5file = file(tmpmd5) 20 21 md5new = md5file.readlines()[0].split()[0] … … 28 29 asapbase = asap.__path__[0] 29 30 try: 30 fl = os.path.join(asapbase, name+ ".md5sum")31 fl = os.path.join(asapbase, name+md5suff) 31 32 data_md5 = file(fl) 32 33 ls = data_md5.readlines()[0] … … 37 38 38 39 if md5new != md5old: 39 dreq = urllib2.Request(dataurl+name)40 src = urllib2.urlopen(dreq)41 40 print "Update required. Downloading asap data archive...." 42 dst = open(tmpdata, 'w') 43 dst.write(src.read()) 44 dst.close() 41 ftp.retrbinary('RETR %s' % name, open(tmpdata, 'wb').write) 45 42 os.chdir(asapbase) 46 43 tf = tarfile.TarFile.bz2open(tmpdata) … … 52 49 print """Data already at latest available version. 53 50 If you still get errors running asap, please report this.""" 51 ftp.quit()
Note:
See TracChangeset
for help on using the changeset viewer.