Last change
on this file since 2978 was 2792, checked in by Malte Marquarding, 12 years ago |
Clen up after myself
|
-
Property svn:executable
set to
*
|
File size:
1.5 KB
|
Rev | Line | |
---|
[1179] | 1 | #!/usr/bin/env python
|
---|
| 2 | import os
|
---|
| 3 | import tarfile
|
---|
| 4 | import shutil
|
---|
[1363] | 5 | from ftplib import FTP
|
---|
[1179] | 6 |
|
---|
[1363] | 7 | # globals
|
---|
| 8 | md5suff = '.md5sum'
|
---|
[1179] | 9 | name = 'asap_data.tar.bz2'
|
---|
[1363] | 10 | dataurl = "ftp.atnf.csiro.au"
|
---|
[1179] | 11 | tmpdata = '/tmp/asap_data.tar.bz2'
|
---|
[1363] | 12 | datadir = 'pub/software/asap/data'
|
---|
| 13 | tmpmd5 = tmpdata+md5suff
|
---|
[1179] | 14 |
|
---|
[1363] | 15 | ftp = FTP(dataurl) # connect to host, default port
|
---|
| 16 | ftp.login() # user anonymous, passwd anonymous@
|
---|
| 17 | ftp.cwd(datadir)
|
---|
[1180] | 18 | print "Checking if an update is required."
|
---|
[1363] | 19 | ftp.retrbinary('RETR %s' % name+md5suff, open(tmpmd5, 'wb').write)
|
---|
[1179] | 20 | md5file = file(tmpmd5)
|
---|
| 21 | md5new = md5file.readlines()[0].split()[0]
|
---|
| 22 |
|
---|
[1180] | 23 | # use ASAPDATA if set - allows non-root update
|
---|
| 24 | if os.environ.has_key("ASAPDATA"):
|
---|
| 25 | asapbase = os.environ["ASAPDATA"]
|
---|
[1183] | 26 | else:
|
---|
| 27 | import asap
|
---|
| 28 | # get asap module path
|
---|
| 29 | asapbase = asap.__path__[0]
|
---|
[1179] | 30 | try:
|
---|
[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]
|
---|
| 36 | except IOError:
|
---|
| 37 | md5old =''
|
---|
| 38 |
|
---|
| 39 | if 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)
|
---|
[2792] | 48 | os.remove(tmpdata)
|
---|
| 49 | os.remove(tmpmd5)
|
---|
[1179] | 50 | else:
|
---|
| 51 | print """Data already at latest available version.
|
---|
| 52 | If you still get errors running asap, please report this."""
|
---|
[1363] | 53 | ftp.quit()
|
---|
Note:
See
TracBrowser
for help on using the repository browser.