Changeset df783c1 for fedd/federation
- Timestamp:
- Aug 2, 2009 6:25:17 PM (15 years ago)
- Branches:
- axis_example, compt_changes, info-ops, master, version-2.00, version-3.01, version-3.02
- Children:
- 81a7f3f
- Parents:
- cdb62d9
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
fedd/federation/topdl.py
rcdb62d9 rdf783c1 5 5 def init_class(c, arg): 6 6 if isinstance(arg, dict): 7 return c(**arg) 7 try: 8 return c(**arg) 9 except: 10 print "%s" % arg 11 raise 8 12 elif isinstance(arg, c): 9 13 return arg … … 16 20 elif getattr(a, '__iter__', None): return a 17 21 else: return [ a ] 22 23 def get_attribute(self, key): 24 rv = None 25 attrs = getattr(self, 'attributes', None) 26 if attrs: 27 for a in attrs: 28 if a.attribute == key: 29 rv = a.value 30 break 31 return rv 18 32 19 33 … … 93 107 94 108 class OperatingSystem(base): 95 def __init__(self, name , version=None, distribution=None,109 def __init__(self, name=None, version=None, distribution=None, 96 110 distributionversion=None, attribute=[]): 97 111 self.name = name … … 103 117 104 118 def to_dict(self): 105 rv = { 'name': self.name } 119 rv = { } 120 if self.name: rv['name'] = self.name 106 121 if self.version: rv['version'] = self.version 107 122 if self.distribution: rv['version'] = self.distribution … … 249 264 return rv 250 265 251 def topology_from_xml( file=None, top="topology"):266 def topology_from_xml(string=None, file=None, top="topology"): 252 267 import xml.parsers.expat 253 268 … … 303 318 xp.CharacterDataHandler = p.char_data 304 319 305 f = open(file, "r") 306 307 xp.ParseFile(f) 320 if file and string: 321 raise RuntimeError("Only one of file and string") 322 elif file: 323 f = open(file, "r") 324 xp.ParseFile(f) 325 elif string: 326 xp.Parse(string, isfinal=True) 327 else: 328 return None 308 329 309 330 return Topology(**p.current[top])
Note: See TracChangeset
for help on using the changeset viewer.