source: trunk/bin/asap_update_data@ 2291

Last change on this file since 2291 was 1363, checked in by mar637, 18 years ago

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

  • Property svn:executable set to *
File size: 1.4 KB
RevLine 
[1179]1#!/usr/bin/env python
2import os
3import tarfile
4import shutil
[1363]5from ftplib import FTP
[1179]6
[1363]7# globals
8md5suff = '.md5sum'
[1179]9name = 'asap_data.tar.bz2'
[1363]10dataurl = "ftp.atnf.csiro.au"
[1179]11tmpdata = '/tmp/asap_data.tar.bz2'
[1363]12datadir = 'pub/software/asap/data'
13tmpmd5 = tmpdata+md5suff
[1179]14
[1363]15ftp = FTP(dataurl) # connect to host, default port
16ftp.login() # user anonymous, passwd anonymous@
17ftp.cwd(datadir)
[1180]18print "Checking if an update is required."
[1363]19ftp.retrbinary('RETR %s' % name+md5suff, open(tmpmd5, 'wb').write)
[1179]20md5file = file(tmpmd5)
21md5new = md5file.readlines()[0].split()[0]
22
[1180]23# use ASAPDATA if set - allows non-root update
24if os.environ.has_key("ASAPDATA"):
25 asapbase = os.environ["ASAPDATA"]
[1183]26else:
27 import asap
28 # get asap module path
29 asapbase = asap.__path__[0]
[1179]30try:
[1363]31 fl = os.path.join(asapbase, name+md5suff)
[1179]32 data_md5 = file(fl)
33 ls = data_md5.readlines()[0]
34 data_md5.close()
35 md5old = ls.split()[0]
36except IOError:
37 md5old =''
38
39if md5new != md5old:
[1180]40 print "Update required. Downloading asap data archive...."
[1363]41 ftp.retrbinary('RETR %s' % name, open(tmpdata, 'wb').write)
[1179]42 os.chdir(asapbase)
43 tf = tarfile.TarFile.bz2open(tmpdata)
44 print "Extracting data archive in %s.." % asapbase
45 for member in tf.getmembers():
46 tf.extract(member)
47 shutil.copy(tmpmd5, asapbase)
48else:
49 print """Data already at latest available version.
50If you still get errors running asap, please report this."""
[1363]51ftp.quit()
Note: See TracBrowser for help on using the repository browser.