X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=PLC%2FMethods%2FGetPlcRelease.py;h=77f2fb00fb12b4c9545469e8d4951d88cca1f177;hb=e795c7325c38c212ed525e567fe028e8ed0c8e90;hp=b7d238f598c5f27f9328ab36503471304bc62566;hpb=ef89f685cfea902b3dda838188cb1c05cdbfc3a1;p=plcapi.git diff --git a/PLC/Methods/GetPlcRelease.py b/PLC/Methods/GetPlcRelease.py index b7d238f..77f2fb0 100644 --- a/PLC/Methods/GetPlcRelease.py +++ b/PLC/Methods/GetPlcRelease.py @@ -1,13 +1,15 @@ +# $Id$ +# $URL$ from PLC.Method import Method from PLC.Auth import Auth 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', } @@ -25,35 +27,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]={} - - 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