Package imaker :: Module iqrf
[hide private]
[frames] | no frames]

Source Code for Module imaker.iqrf

  1  #============================================================================  
  2  #Name        : iqrf.py  
  3  #Part of     : Helium  
  4   
  5  #Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). 
  6  #All rights reserved. 
  7  #This component and the accompanying materials are made available 
  8  #under the terms of the License "Eclipse Public License v1.0" 
  9  #which accompanies this distribution, and is available 
 10  #at the URL "http://www.eclipse.org/legal/epl-v10.html". 
 11  # 
 12  #Initial Contributors: 
 13  #Nokia Corporation - initial contribution. 
 14  # 
 15  #Contributors: 
 16  # 
 17  #Description: 
 18  #=============================================================================== 
 19   
 20  """ 
 21      Implements iQRF model. 
 22       
 23      How to use it: 
 24      import imaker.iqrf 
 25      root = imaker.iqrf.load(filename) 
 26      root.result 
 27  """ 
 28  import amara 
 29  import logging 
 30  from  imaker.ecore import ContainerBase, Reference        
 31   
 32  logging.basicConfig() 
 33  logger = logging.getLogger("iqrf.model") 
 34  #logger.setLevel(logging.DEBUG) 
 35   
 36           
37 -class IMaker(ContainerBase):
38 """ IMaker container. """
39 - def __init__(self, parent=None):
40 ContainerBase.__init__(self, parent) 41 self.result = None
42
43 - def load(self, node):
44 """ Load data from XML node. """ 45 if hasattr(node, 'result'): 46 logger.debug("IMaker has result attribute.") 47 self.result = Result(self) 48 self.result.load(node.result)
49 50
51 -class Result(ContainerBase):
52 """ Result container. """
53 - def __init__(self, parent=None):
54 ContainerBase.__init__(self, parent) 55 self.interfaces = [] 56 self.configurations = [] 57 self.targets = []
58
59 - def load(self, node):
60 """ Load data from XML node. """ 61 logger.debug("Loading Result") 62 for elem in node.interfaces: 63 interface = Interface(self) 64 interface.load(elem) 65 self.interfaces.append(interface) 66 for elem in node.configurations: 67 configuration = Configuration(self) 68 configuration.load(elem) 69 self.configurations.append(configuration) 70 for elem in node.targets: 71 target = Target(self) 72 target.load(elem) 73 self.targets.append(target)
74
75 -class Configuration(ContainerBase):
76 """ Configuration container. """ 77
78 - def __init__(self, parent=None):
79 ContainerBase.__init__(self, parent) 80 self.name = None 81 self.settings = [] 82 self.filePath = None 83 self.targetrefs = []
84
85 - def load(self, node):
86 """ Load data from XML node. """ 87 logger.debug("Loading Configuration") 88 self.name = node.name 89 self.filePath = node.filePath 90 for elem in node.xml_xpath('./settings'): 91 setting = Setting(self) 92 setting.load(elem) 93 self.settings.append(setting) 94 95 for ref in node.targetrefs.split(" "): 96 self.targetrefs.append(Reference(self, ref))
97
98 -class Setting(ContainerBase):
99
100 - def __init__(self, parent=None):
101 ContainerBase.__init__(self, parent) 102 self.name = None 103 self.value = None 104 self.ref = None
105
106 - def load(self, node):
107 logger.debug("Loading Setting") 108 self.name = node.name 109 self.value = node.value 110 self.ref = Reference(node.ref)
111 112
113 -class Interface(ContainerBase):
114 """ Interface container. """
115 - def __init__(self, parent=None):
116 ContainerBase.__init__(self, parent) 117 self.name = None 118 self.configurationElements = []
119
120 - def load(self, node):
121 """ Load data from XML node. """ 122 logger.debug("Loading Interface") 123 self.name = node.name 124 for cel in node.configurationElements: 125 conf = ConfigurationElement(self) 126 conf.load(cel) 127 self.configurationElements.append(conf)
128
129 -class ConfigurationElement(ContainerBase):
130 """ ConfigurationElement container. """
131 - def __init__(self, parent=None):
132 ContainerBase.__init__(self, parent) 133 self.name = None 134 self.description = None 135 self.values = None
136
137 - def load(self, node):
138 """ Load data from XML node. """ 139 logger.debug("Loading ConfigurationElement") 140 self.name = node.name 141 self.description = node.description 142 self.values = node.values
143
144 -class Target(ContainerBase):
145 """ Target container. """ 146
147 - def __init__(self, parent=None):
148 ContainerBase.__init__(self, parent) 149 self.name = None 150 self.description = None
151
152 - def load(self, node):
153 """ Load data from XML node. """ 154 logger.debug("Loading Target") 155 self.name = node.name 156 self.description = node.description
157 158 159 160
161 -def load(filename):
162 """ Load IMaker serialized ecore configuration. """ 163 doc = amara.parse(open(filename, 'r')) 164 imaker = IMaker() 165 imaker.load(doc.IMaker) 166 return imaker
167