X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=PLC%2FMethods%2FGetPlcRelease.py;h=796ae7ea0ff71ad0b7b36e6ba3df22a40cf5ec8d;hb=bd0cbf4f7f2e4cf7ceda500bfa6f98c0a700018b;hp=7df66aaee6b55292ea7932fd51b21be4f9780347;hpb=e46d8adbd39540555d5c611d6dc025f522e3d421;p=plcapi.git diff --git a/PLC/Methods/GetPlcRelease.py b/PLC/Methods/GetPlcRelease.py index 7df66aa..796ae7e 100644 --- a/PLC/Methods/GetPlcRelease.py +++ b/PLC/Methods/GetPlcRelease.py @@ -4,10 +4,13 @@ from PLC.Faults import * import re -comment_regexp = '\A\s*#.|\A\s*\Z|\Axxxxx' +comment_regexp = '\A\s*#.|\A\s*\Z|\Axxxxx' regexps = { 'build' : '\A[bB]uild\s+(?P[^:]+)\s*:\s*(?P.*)\Z', - 'tags' : '\A(?P[^:]+)\s*:=\s*(?P.*)\Z'} + 'tags' : '\A(?P[^:]+)\s*:=\s*(?P.*)\Z', +# spaces not part of key : ungreedy + 'rpms' : '\A(?P[^:]+?)\s*::\s*(?P.*)\Z', +} class GetPlcRelease(Method): """ @@ -22,36 +25,35 @@ class GetPlcRelease(Method): # for now only return /etc/myplc-release verbatim returns = { 'build' : 'information about the build', - 'tags' : 'describes the codebase location and tags used for building', - 'rpms' : 'details the rpm installed in the myplc chroot jail' } + 'tags' : 'describes the codebase location and tags used for building', + 'rpms' : 'details the rpm installed in the myplc chroot jail' } def call(self, auth): - comment_matcher = re.compile(comment_regexp) - - matchers = {} - result = {} - for field in regexps.keys(): - matchers[field] = re.compile(regexps[field]) - result[field]={} - result['rpms']="Not implemented yet" - - try: - release = open('/etc/myplc-release') - for line in release.readlines(): - line=line.strip() - if comment_matcher.match(line): - continue - for field in regexps.keys(): - m=matchers[field].match(line) - if m: - (key,value)=m.groups(['key','value']) - result[field][key]=value - break - else: - if not result.has_key('unexpected'): - result['unexpected']="" - result['unexpected'] += (line+"\n") - except: - raise PLCNotImplemented, 'Cannot open /etc/myplc-release' - return result + comment_matcher = re.compile(comment_regexp) + + matchers = {} + result = {} + for field in regexps.keys(): + matchers[field] = re.compile(regexps[field]) + result[field]={} + + try: + release = open('/etc/myplc-release') + for line in release.readlines(): + line=line.strip() + if comment_matcher.match(line): + continue + for field in regexps.keys(): + m=matchers[field].match(line) + if m: + (key,value)=m.groups(['key','value']) + result[field][key]=value + break + else: + if not result.has_key('unexpected'): + result['unexpected']="" + result['unexpected'] += (line+"\n") + except: + raise PLCNotImplemented, 'Cannot open /etc/myplc-release' + return result