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'}
12 class GetPlcRelease(Method):
14 Returns various information about the current myplc installation.
17 roles = ['admin', 'pi', 'user', 'tech', 'node', 'anonymous']
23 # for now only return /etc/myplc-release verbatim
24 returns = { 'build' : 'information about the build',
25 'tags' : 'describes the codebase location and tags used for building',
26 'rpms' : 'details the rpm installed in the myplc chroot jail' }
30 comment_matcher = re.compile(comment_regexp)
34 for field in regexps.keys():
35 matchers[field] = re.compile(regexps[field])
37 result['rpms']="Not implemented yet"
40 release = open('/etc/myplc-release')
41 for line in release.readlines():
43 if comment_matcher.match(line):
45 for field in regexps.keys():
46 m=matchers[field].match(line)
48 (key,value)=m.groups(['key','value'])
49 result[field][key]=value
52 if not result.has_key('unexpected'):
53 result['unexpected']=""
54 result['unexpected'] += (line+"\n")
56 raise PLCNotImplemented, 'Cannot open /etc/myplc-release'