source: branches/Release2.1/bin/asap_update_data@ 2753

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

only import asap when ASAPDATA not set

  • Property svn:executable set to *
File size: 1.4 KB
Line 
1#!/usr/bin/env python
2import urllib2
3import os
4import tarfile
5
6import shutil
7
8name = 'asap_data.tar.bz2'
9dataurl = "http://www.atnf.csiro.au/pub/software/asap/data/"
10tmpdata = '/tmp/asap_data.tar.bz2'
11tmpmd5 = tmpdata+'.md5sum'
12
13print "Checking if an update is required."
14md5req = urllib2.Request(dataurl+name+'.md5sum')
15response = urllib2.urlopen(md5req)
16md5file = file(tmpmd5,'w')
17md5file.write(response.read())
18md5file.close()
19md5file = file(tmpmd5)
20md5new = md5file.readlines()[0].split()[0]
21
22# use ASAPDATA if set - allows non-root update
23if os.environ.has_key("ASAPDATA"):
24 asapbase = os.environ["ASAPDATA"]
25else:
26 import asap
27 # get asap module path
28 asapbase = asap.__path__[0]
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.