Changeset 190 for trunk


Ignore:
Timestamp:
05/14/09 13:11:08 (15 years ago)
Author:
bas
Message:

src/PBSQuery.py:

  • fixed an error in parsing for new data structure, value can contain a '=' char
  • added the iter method

examples/new_interface.py:

  • make use of new data structure and iter object
Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/examples/new_interface.py

    r74 r190  
    1616
    1717  p = PBSQuery()
    18 
    19   nodes = p.getnodes()
    20   for name, node in nodes.items():
    21         print node
    22         if node.is_free():
    23                 print "%s : Found an free node" %name
     18  p.new_data_structure()
    2419
    2520  jobs = p.getjobs()
    26   for name, job in jobs.items():
    27      for key in job.keys():
    28         print '%s = %s' %(key, job[key])
    29  
     21  for id in jobs:
     22     print id + ':'
     23     for attr in jobs[id]:
     24        print '\t' + attr, jobs[id][attr]
     25     
    3026  l = ['state', 'np' ]
    3127  nodes = p.getnodes(l)
    32   for node in nodes.values():
    33      print node
     28  for id in nodes:
     29     print id + ': ', nodes[id].state, nodes[id].np
     30
     31     for attrib in nodes[id]:
     32        print attrib, nodes[id][attrib]
    3433
    3534main()
  • trunk/src/PBSQuery.py

    r188 r190  
    180180                                                        new[key] = dict()
    181181                                                        for v in values:
    182                                                                 a,b = v.split('=')
    183                                                                 new[key][a] = [ b ]
     182                                                                # First argument is the key and the rest is the value
     183                                                                # - value can contain a '='
     184                                                                #
     185                                                                tmp = v.split('=')
     186                                                                new[key][ tmp[0] ] = [ tmp[1:] ]
    184187                                               
    185188                self._free(l)
     
    318321                        error = 'invalid attribute %s' %(name)
    319322                        raise PBSError(error)
     323
     324        def __iter__(self):
     325                return iter(self.data.keys())
    320326
    321327        def uniq(self, list):
Note: See TracChangeset for help on using the changeset viewer.