source: branches/hpc33/bin/asap_update_data@ 2479

Last change on this file since 2479 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
Line 
1#!/usr/bin/env python
2import os
3import tarfile
4import shutil
5from ftplib import FTP
6
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
14
15ftp = FTP(dataurl) # connect to host, default port
16ftp.login() # user anonymous, passwd anonymous@
17ftp.cwd(datadir)
18print "Checking if an update is required."
19ftp.retrbinary('RETR %s' % name+md5suff, open(tmpmd5, 'wb').write)
20md5file = file(tmpmd5)
21md5new = md5file.readlines()[0].split()[0]
22
23# use ASAPDATA if set - allows non-root update
24if os.environ.has_key("ASAPDATA"):
25 asapbase = os.environ["ASAPDATA"]
26else:
27 import asap
28 # get asap module path
29 asapbase = asap.__path__[0]
30try:
31 fl = os.path.join(asapbase, name+md5suff)
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:
40 print "Update required. Downloading asap data archive...."
41 ftp.retrbinary('RETR %s' % name, open(tmpdata, 'wb').write)
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."""
51ftp.quit()
Note: See TracBrowser for help on using the repository browser.