-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcheckVersion
More file actions
executable file
·81 lines (64 loc) · 2.59 KB
/
checkVersion
File metadata and controls
executable file
·81 lines (64 loc) · 2.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#!/usr/bin/env python2
# Compare the version of this DAVM to the list of those that have been released so far and alert
# the user if this instance has is now out of date.
import sys
import urllib2
import xml.dom.minidom
from PyQt4 import QtGui
from datetime import datetime
CURRENT_VERSION_FORMAT = '%y%m%d'
RELEASE_VERSION_FORMAT = '%Y%m%d' # Releases in online bucket contain century in year component
ETC_VERSION = '/etc/davm_version'
RELEASE_URL = 'https://s3-ap-southeast-2.amazonaws.com/uts.dataarena.vm/'
ALERT_TITLE = 'This DAVM release is now out of date!'
ALERT_MESSAGE = 'Please refer to the DAVM Google Group for more information about how to download and install the latest release.'
def fetch_current_release():
"""
Retrieve the release version of the DAVM within which this script has been invoked.
"""
current = datetime.now().date().strftime(CURRENT_VERSION_FORMAT)
try:
f = open(ETC_VERSION, 'r')
current = f.read().strip()
f.close()
except:
pass
return current
def fetch_available_releases():
"""
Uses the S3 REST api to retrieve an XML listing of the specified bucket contents (appropriate
public access rights need to be assigned to the bucket for this call to succeed).
"""
try:
return urllib2.urlopen(RELEASE_URL).read()
except Exception:
return None
def parse_available_releases(payload):
"""
This implementation relies on each release being uploaded to a YYYYMMDD folder underneath the
releases directory inside the uts.dataarena.vm S3 bucket.
"""
releases = []
if payload:
dom = xml.dom.minidom.parseString(payload)
for entry in dom.getElementsByTagName('Contents'):
keys = entry.getElementsByTagName('Key')
bits = keys[0].firstChild.data.split('/')
if bits[1] and bits[1] not in releases:
releases.append(bits[1])
return releases
def check_release_version():
"""
Compare current release to latest available release and alert user if they are out of date.
"""
response = fetch_available_releases()
if response:
releases = parse_available_releases(response)
if releases:
latest = datetime.strptime(releases[-1], RELEASE_VERSION_FORMAT)
current = datetime.strptime(fetch_current_release(), CURRENT_VERSION_FORMAT)
if current < latest:
app = QtGui.QApplication(sys.argv)
QtGui.QMessageBox.warning(None, ALERT_TITLE, ALERT_MESSAGE, QtGui.QMessageBox.Ok)
if __name__ == '__main__':
check_release_version()