/[pdpsoft]/trunk/nl.nikhef.pdp.lrmsutils/lrms-pbs/pbsServer.py
ViewVC logotype

Diff of /trunk/nl.nikhef.pdp.lrmsutils/lrms-pbs/pbsServer.py

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1885 by templon, Thu Aug 19 08:37:24 2010 UTC revision 1886 by templon, Thu Aug 19 13:04:30 2010 UTC
# Line 110  class LiveServer(Server): Line 110  class LiveServer(Server):
110    
111  import copy  import copy
112            
113  ## following is helper for class Event.  ## following is helper for class Event.  superseded by newer keyvallist2dict function.
114  ## takes as arg a string of key=val pairs, returns a dict with the same  ## takes as arg a string of key=val pairs, returns a dict with the same
115  ## structure.  example input string:  ## structure.  example input string:
116  ## user=tdykstra group=niktheorie jobname=Q11_241828.gjob  ## user=tdykstra group=niktheorie jobname=Q11_241828.gjob
# Line 119  def keyval2dict(astring): Line 119  def keyval2dict(astring):
119      flds = string.split(astring)      flds = string.split(astring)
120      d = {}      d = {}
121      for f in flds:      for f in flds:
122          kv=string.split(f,"=")          kv=f.split("=",1)
123          if len(kv) == 2:          if len(kv) == 2:
124              d[kv[0]] = kv[1]              d[kv[0]] = kv[1]
125          else:          else:
126                print f
127              print kv              print kv
128              raise CantHappenException              raise CantHappenException
129      return d      return d
130    
131    ## following is helper for class Event.
132    ## takes as arg a list of key=val pairs, returns a dict with the same
133    ## structure.  example input string:
134    ## ['user=tdykstra', 'group=niktheorie', 'jobname=Q11_241828.gjob']
135    
136    def keyvallist2dict(kvlist):
137        d = {}
138        for f in kvlist:
139            kv=f.split("=",1)
140            if len(kv) == 2:
141                d[kv[0]] = kv[1]
142            else:
143                print "tried to split:", f, ", result was:", kv
144                raise CantHappenException
145        return d
146    
147  class Event:  class Event:
148    
149      # simple class to represent events like job queued, job started, etc.      # simple class to represent events like job queued, job started, etc.
150    
151      def __init__(self,evstring,debug=0):      def __init__(self,evstring,debug=0):
152    
153            self.__time__   = None          # default values
154            self.__type__   = None
155            self.__jobid__  = None
156            self.__info__   = { }
157    
158          # search pattern for parsing string using "re" module          # search pattern for parsing string using "re" module
159          # for successful search, fields are:          # for successful search, fields are:
160          # 1) timestamp          # 1) timestamp
161          # 2) event type (Q,S,E,D, etc)          # 2) event type (Q,S,E,D, etc)
162          # 3) local PBS jobID          # 3) local PBS jobID
163          # 4) rest of line (key=value) to be parsed otherwise          # 4) rest of line (key=value) to be parsed otherwise
164                    # this structure is matched by evpatt
         self.__time__   = None          # default values  
         self.__type__   = None  
         self.__jobid__  = None  
         self.__info__   = { }  
   
         # search patt breaks on "account" attribute due to embedded whitespace and equals  
         # solution is to replace whitespace in this substring by character '^'  
         # and equals characters by '#'  
           
         accpatt  = "account=."  
         attrpatt = r' [a-zA-Z_.]+='  
         attrprog = re.compile(attrpatt)  
           
         macc = re.search(accpatt,evstring)  
         if macc:  
             accstart=macc.start() + len(accpatt) # need to get past the = character  
             mnextattr=attrprog.search(evstring,macc.start())  
             if mnextattr:  
                 accend = mnextattr.start()  
                 accstr = evstring[accstart:accend]  
                 tmpev           = accstr.replace(' ','^')  
                 escaped_version =  tmpev.replace('=','#')  
                 news = evstring.replace(accstr,escaped_version)  
                 evstring=news  
165                    
166          evpatt = "^(.+);([A-Z]);(.+);(.*)"          evpatt = "^(.+);([A-Z]);(.+);(.*)"
167          m = re.search(evpatt,evstring)          m = re.search(evpatt,evstring)
# Line 177  class Event: Line 175  class Event:
175              print "jobid", m.group(3)              print "jobid", m.group(3)
176              print "attrs", m.group(4)              print "attrs", m.group(4)
177    
178            # tpatt matches strings of form key=val
179            # lookahead assertion is necessary to work around presence of ' ' and '=' in some
180            # 'val' strings (like account, or neednodes with multiple processors)
181            
182            tpatt  = r'[a-z._A-Z]+=[a-z0-9A-Z=/: -@_]+?(?=$| [a-z._A-Z]+=)'
183            tprog  = re.compile(tpatt)
184            tmatch = tprog.findall(m.group(4))
185            if debug:
186                print "result of key=val match pattern:", tmatch
187    
188          # parse timestamp          # parse timestamp
189    
190          ttup=time.strptime(m.group(1),"%m/%d/%Y %H:%M:%S")          ttup=time.strptime(m.group(1),"%m/%d/%Y %H:%M:%S")
# Line 190  class Event: Line 198  class Event:
198          self.__time__   = int(time.mktime(atup))          self.__time__   = int(time.mktime(atup))
199          self.__type__   = m.group(2)          self.__type__   = m.group(2)
200          self.__jobid__  = m.group(3)          self.__jobid__  = m.group(3)
201          self.__info__   = keyval2dict(m.group(4))          self.__info__   = keyvallist2dict(tmatch)
202    
203      def time(self):      def time(self):
204          return self.__time__          return self.__time__
# Line 330  class History: Line 338  class History:
338                      if ev.info('Resource_List.walltime') and not \                      if ev.info('Resource_List.walltime') and not \
339                         job.get('maxwalltime'):                         job.get('maxwalltime'):
340                          hms = ev.info('Resource_List.walltime')                          hms = ev.info('Resource_List.walltime')
341                          hmsflds = string.split(hms,":")                          (h,m,s) = hms.split(":")
342                          maxwallsecs = int(hmsflds[0]) * 3600 + \                          maxwallsecs = int(h) * 3600 + int(m) * 60 + int(s)
                                       int(hmsflds[1]) *   60 + \  
                                       int(hmsflds[2])  
343                          job.set('maxwalltime',maxwallsecs)                          job.set('maxwalltime',maxwallsecs)
344                      if ev.info('end') and not job.get('end'):                      if ev.info('end') and not job.get('end'):
345                          job.set('end',int(ev.info('end')))                          job.set('end',int(ev.info('end')))

Legend:
Removed from v.1885  
changed lines
  Added in v.1886

grid.support@nikhef.nl
ViewVC Help
Powered by ViewVC 1.1.28