- Timestamp:
- 05/13/09 15:37:11 (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/PBSQuery.py
r184 r188 77 77 78 78 class PBSQuery: 79 80 # a[key] = value, key and value are data type string 81 # 82 OLD_DATA_STRUCTURE = True 83 79 84 def __init__(self, server=None): 80 85 if not server: … … 82 87 else: 83 88 self.server = server 84 85 89 86 90 def _connect(self): … … 101 105 i = 0 102 106 for attrib in list: 103 self.attribs[i].name = attrib 107 # So we can user Resource 108 attrib = attrib.split('.') 109 self.attribs[i].name = attrib[0] 104 110 i = i + 1 105 111 … … 111 117 112 118 def _list_2_dict(self, l, class_func): 113 """Convert a pbsstat function list to a class dictionary""" 119 """ 120 Convert a pbsstat function list to a class dictionary, The 121 data structure depends on the function new_data_structure(). 122 123 Default data structure is: 124 class[key] = value, Where key and value are of type string 125 126 Future release, can be set by new_data_structure(): 127 - class[key] = value where value can be: 128 1. a list of values of type string 129 2. a dictionary with as list of values of type string. If 130 values contain a '=' character 131 132 eg: 133 print node['np'] 134 >> [ '2' ] 135 136 print node['status']['arch'] 137 >> [ 'x86_64' ] 138 """ 114 139 self.d = {} 115 140 for item in l: 116 141 new = class_func() 142 117 143 self.d[item.name] = new 118 144 145 new.name = item.name 146 119 147 for a in item.attribs: 120 new.name = item.name 148 121 149 if a.resource: 122 new[a.name + '.' + a.resource] = a.value150 key = '%s.%s' %(a.name, a.resource) 123 151 else: 124 new[a.name] = a.value 152 key = a.name 153 154 if self.OLD_DATA_STRUCTURE: 155 new[key] = a.value 156 else: 157 values = string.split(a.value, ',') 158 159 if len(values) == 1: 160 # simple form 161 # print 'simple %s = %s' %(key, values[0]) 162 # 163 new[key] = values 164 165 else: 166 # list check 167 list_or_dict = string.split(a.value, '=') 168 169 170 if len(list_or_dict) == 1: 171 # This is a list 172 # print 'list %s = %s' %(key, values) 173 # 174 new[key] = values 175 176 else: 177 # This is dictionary 178 # print 'dict %s = %s' %(key, values) 179 # 180 new[key] = dict() 181 for v in values: 182 a,b = v.split('=') 183 new[key][a] = [ b ] 184 125 185 self._free(l) 126 186 … … 128 188 """ 129 189 freeing up used memmory 190 130 191 """ 131 192 pbs.pbs_statfree(memory) … … 225 286 return self.server 226 287 288 def new_data_structure(self): 289 """ 290 Use new data structure, will be standard in future release 291 """ 292 self.OLD_DATA_STRUCTURE = False 293 227 294 class _PBSobject(UserDict.UserDict): 228 295 TRUE = 1 … … 238 305 else: 239 306 return None 307 308 def __repr__(self): 309 return repr(self.data) 310 311 def __str__(self): 312 return str(self.data) 313 314 def __getattr__(self, name): 315 try: 316 return self.data[name] 317 except KeyError: 318 error = 'invalid attribute %s' %(name) 319 raise PBSError(error) 240 320 241 321 def uniq(self, list): … … 295 375 296 376 297 298 299 300 377 class queue(_PBSobject): 301 378 """PBS queue class"""
Note: See TracChangeset
for help on using the changeset viewer.