1 from PLC.Method import Method
2 from PLC.Auth import Auth
3 from PLC.Faults import *
7 comment_regexp = '\A\s*#.|\A\s*\Z|\Axxxxx'
9 regexps = { 'build' : '\A[bB]uild\s+(?P<key>[^:]+)\s*:\s*(?P<value>.*)\Z',
10 'tags' : '\A(?P<key>[^:]+)\s*:=\s*(?P<value>.*)\Z',
11 'rpms' : '\A(?P<key>[^:]+)\s*::\s*(?P<value>.*)\Z',
14 class GetPlcRelease(Method):
16 Returns various information about the current myplc installation.
19 roles = ['admin', 'pi', 'user', 'tech', 'node', 'anonymous']
25 # for now only return /etc/myplc-release verbatim
26 returns = { 'build' : 'information about the build',
27 'tags' : 'describes the codebase location and tags used for building',
28 'rpms' : 'details the rpm installed in the myplc chroot jail' }
32 comment_matcher = re.compile(comment_regexp)
36 for field in regexps.keys():
37 matchers[field] = re.compile(regexps[field])
41 release = open('/etc/myplc-release')
42 for line in release.readlines():
44 if comment_matcher.match(line):
46 for field in regexps.keys():
47 m=matchers[field].match(line)
49 (key,value)=m.groups(['key','value'])
50 result[field][key]=value
53 if not result.has_key('unexpected'):
54 result['unexpected']=""
55 result['unexpected'] += (line+"\n")
57 raise PLCNotImplemented, 'Cannot open /etc/myplc-release'