-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathsysinfo.py
More file actions
56 lines (48 loc) · 1.74 KB
/
sysinfo.py
File metadata and controls
56 lines (48 loc) · 1.74 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
__author__ = 'depew'
RHWEB_VERSION = '1.2.0'
from handler import JsonHandler
def _identify_remote_location_version(v):
'''
:param v: tuple representing version major, minor, patch
:return: boolean
>>> _identify_remote_location_version((1, 10, 2))
False
>>> _identify_remote_location_version((1, 10, 3))
True
>>> _identify_remote_location_version((1, 11, 1))
True
>>> _identify_remote_location_version((2, 1, 1))
True
>>> _identify_remote_location_version((1, 9, 3))
False
'''
return (v[0] > 1) or \
(v[0] == 1 and
(v[1] == 10 and v[2] > 2) or
(v[1] > 10))
def _parse_dist_version(distver, element=None):
'''
:param distver: distribution version from pkg_resources
:return: a three element tuple of only the integers
>>> _parse_dist_version(('00000001', '00000010', '00000002', '*final'))
(1, 10, 2)
>>> _parse_dist_version(('00000002', '00000012', '00000002', '*final'))
(2, 12, 2)
>>> _parse_dist_version(('00000002', '00000012', '0000002b', '*final'))
(2, 12, 2)
>>> _parse_dist_version(('00000002', '00000012', '000000b', '*final'))
(2, 12, 0)
>>> _parse_dist_version(('00000002', '00000012', 'b', '*final'))
(2, 12, 0)
'''
if element is None:
return (_parse_dist_version(distver, 0),
_parse_dist_version(distver, 1),
_parse_dist_version(distver, 2))
try:
return int(re.findall('\d+', distver[element])[0])
except (ValueError, IndexError):
return 0
class SysInfoHandler(JsonHandler):
def get(self):
self._render_json(self.redhawk.get_redhawk_info())