3 from PLC.Method import Method
4 from PLC.Auth import Auth
5 from PLC.Faults import *
9 comment_regexp = '\A\s*#.|\A\s*\Z|\Axxxxx'
11 regexps = { 'build' : '\A[bB]uild\s+(?P<key>[^:]+)\s*:\s*(?P<value>.*)\Z',
12 'tags' : '\A(?P<key>[^:]+)\s*:=\s*(?P<value>.*)\Z',
13 # spaces not part of key : ungreedy
14 'rpms' : '\A(?P<key>[^:]+?)\s*::\s*(?P<value>.*)\Z',
17 class GetPlcRelease(Method):
19 Returns various information about the current myplc installation.
22 roles = ['admin', 'pi', 'user', 'tech', 'node', 'anonymous']
28 # for now only return /etc/myplc-release verbatim
29 returns = { 'build' : 'information about the build',
30 'tags' : 'describes the codebase location and tags used for building',
31 'rpms' : 'details the rpm installed in the myplc chroot jail' }
35 comment_matcher = re.compile(comment_regexp)
39 for field in regexps.keys():
40 matchers[field] = re.compile(regexps[field])
44 release = open('/etc/myplc-release')
45 for line in release.readlines():
47 if comment_matcher.match(line):
49 for field in regexps.keys():
50 m=matchers[field].match(line)
52 (key,value)=m.groups(['key','value'])
53 result[field][key]=value
56 if not result.has_key('unexpected'):
57 result['unexpected']=""
58 result['unexpected'] += (line+"\n")
60 raise PLCNotImplemented, 'Cannot open /etc/myplc-release'