Changeset 1363 for trunk/bin


Ignore:
Timestamp:
05/02/07 09:39:11 (18 years ago)
Author:
mar637
Message:

ATNF doesn't allow http acces to ftp server anymore. Use ftp directly

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/bin/asap_update_data

    r1183 r1363  
    11#!/usr/bin/env python
    2 import urllib2
    32import os
    43import tarfile
     4import shutil
     5from ftplib import FTP
    56
    6 import shutil
     7# globals
     8md5suff = '.md5sum'
     9name = 'asap_data.tar.bz2'
     10dataurl  = "ftp.atnf.csiro.au"
     11tmpdata = '/tmp/asap_data.tar.bz2'
     12datadir = 'pub/software/asap/data'
     13tmpmd5 = tmpdata+md5suff
    714
    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 
     15ftp = FTP(dataurl)   # connect to host, default port
     16ftp.login()               # user anonymous, passwd anonymous@
     17ftp.cwd(datadir)
    1318print "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()
     19ftp.retrbinary('RETR %s' % name+md5suff, open(tmpmd5, 'wb').write)
    1920md5file = file(tmpmd5)
    2021md5new = md5file.readlines()[0].split()[0]
     
    2829    asapbase = asap.__path__[0]
    2930try:
    30     fl = os.path.join(asapbase, name+".md5sum")
     31    fl = os.path.join(asapbase, name+md5suff)
    3132    data_md5 = file(fl)
    3233    ls = data_md5.readlines()[0]
     
    3738
    3839if md5new != md5old:
    39     dreq = urllib2.Request(dataurl+name)
    40     src = urllib2.urlopen(dreq)
    4140    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)
    4542    os.chdir(asapbase)
    4643    tf = tarfile.TarFile.bz2open(tmpdata)
     
    5249    print """Data already at latest available version.
    5350If you still get errors running asap, please report this."""
     51ftp.quit()
Note: See TracChangeset for help on using the changeset viewer.