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 # spaces not part of key : ungreedy
12 'rpms' : '\A(?P<key>[^:]+?)\s*::\s*(?P<value>.*)\Z',
15 class GetPlcRelease(Method):
17 Returns various information about the current myplc installation.
20 roles = ['admin', 'pi', 'user', 'tech', 'node', 'anonymous']
26 # for now only return /etc/myplc-release verbatim
27 returns = { 'build' : 'information about the build',
28 'tags' : 'describes the codebase location and tags used for building',
29 'rpms' : 'details the rpm installed in the myplc chroot jail' }
33 comment_matcher = re.compile(comment_regexp)
37 for field in list(regexps.keys()):
38 matchers[field] = re.compile(regexps[field])
42 release = open('/etc/myplc-release')
43 for line in release.readlines():
45 if comment_matcher.match(line):
47 for field in list(regexps.keys()):
48 m=matchers[field].match(line)
50 (key,value)=m.groups(['key','value'])
51 result[field][key]=value
54 if 'unexpected' not in result:
55 result['unexpected']=""
56 result['unexpected'] += (line+"\n")
58 raise PLCNotImplemented('Cannot open /etc/myplc-release')