source: trunk/bin/asap_update_data @ 1180

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

allowing for ASAPDATA env variable. more printing.

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