2 from PLC.Method import Method
3 from PLC.Auth import Auth
4 from PLC.Faults import *
8 comment_regexp = '\A\s*#.|\A\s*\Z|\Axxxxx'
10 regexps = { 'build' : '\A[bB]uild\s+(?P<key>[^:]+)\s*:\s*(?P<value>.*)\Z',
11 'tags' : '\A(?P<key>[^:]+)\s*:=\s*(?P<value>.*)\Z',
12 # spaces not part of key : ungreedy
13 'rpms' : '\A(?P<key>[^:]+?)\s*::\s*(?P<value>.*)\Z',
16 class GetPlcRelease(Method):
18 Returns various information about the current myplc installation.
21 roles = ['admin', 'pi', 'user', 'tech', 'node', 'anonymous']
27 # for now only return /etc/myplc-release verbatim
28 returns = { 'build' : 'information about the build',
29 'tags' : 'describes the codebase location and tags used for building',
30 'rpms' : 'details the rpm installed in the myplc chroot jail' }
34 comment_matcher = re.compile(comment_regexp)
38 for field in regexps.keys():
39 matchers[field] = re.compile(regexps[field])
43 release = open('/etc/myplc-release')
44 for line in release.readlines():
46 if comment_matcher.match(line):
48 for field in regexps.keys():
49 m=matchers[field].match(line)
51 (key,value)=m.groups(['key','value'])
52 result[field][key]=value
55 if not result.has_key('unexpected'):
56 result['unexpected']=""
57 result['unexpected'] += (line+"\n")
59 raise PLCNotImplemented, 'Cannot open /etc/myplc-release'