Ignore:
Timestamp:
Aug 2, 2009 6:25:17 PM (15 years ago)
Author:
Ted Faber <faber@…>
Branches:
axis_example, compt_changes, info-ops, master, version-2.00, version-3.01, version-3.02
Children:
81a7f3f
Parents:
cdb62d9
Message:

create images from topdl descriptions, a good sign they're coming out right.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • fedd/federation/topdl.py

    rcdb62d9 rdf783c1  
    55    def init_class(c, arg):
    66        if isinstance(arg, dict):
    7             return c(**arg)
     7            try:
     8                return c(**arg)
     9            except:
     10                print "%s" % arg
     11                raise
    812        elif isinstance(arg, c):
    913            return arg
     
    1620        elif getattr(a, '__iter__', None): return a
    1721        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
    1832
    1933
     
    93107
    94108class OperatingSystem(base):
    95     def __init__(self, name, version=None, distribution=None,
     109    def __init__(self, name=None, version=None, distribution=None,
    96110            distributionversion=None, attribute=[]):
    97111        self.name = name
     
    103117
    104118    def to_dict(self):
    105         rv = { 'name': self.name }
     119        rv = { }
     120        if self.name: rv['name'] = self.name
    106121        if self.version: rv['version'] = self.version
    107122        if self.distribution: rv['version'] = self.distribution
     
    249264        return rv
    250265
    251 def topology_from_xml(file=None, top="topology"):
     266def topology_from_xml(string=None, file=None, top="topology"):
    252267    import xml.parsers.expat
    253268
     
    303318    xp.CharacterDataHandler = p.char_data
    304319
    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
    308329
    309330    return Topology(**p.current[top])
Note: See TracChangeset for help on using the changeset viewer.