Module dependency_data
[hide private]
[frames] | no frames]

Source Code for Module dependency_data

  1  """ 
  2  Parser for the dependency layer in KAF/NAF 
  3  """ 
  4  from lxml import etree 
  5  #from lxml.objectify import dump 
  6   
  7   
8 -class Cdependency:
9 """ 10 This class encapsulates a dependency object in KAF/NAF 11 """
12 - def __init__(self,node=None):
13 """ 14 Constructor of the object 15 @type node: xml Element or None (to create and empty one) 16 @param node: this is the node of the element. If it is None it will create a new object 17 """ 18 if node is None: 19 self.node = etree.Element('dep') 20 else: 21 self.node = node
22
23 - def get_node_comment(self):
24 """ 25 Returns the lxml element for the comment 26 @rtype: lxml Element 27 @return: the lxml element for the comment 28 """ 29 return self.node_comment
30
31 - def get_node(self):
32 """ 33 Returns the node of the element 34 @rtype: xml Element 35 @return: the node of the element 36 """ 37 return self.node
38
39 - def get_from(self):
40 """ 41 Returns the from attribute of the dependency 42 @rtype: string 43 @return: the from attribute 44 """ 45 return self.node.get('from')
46
47 - def get_to(self):
48 """ 49 Returns the to attribute of the dependency 50 @rtype: string 51 @return: the to attribute 52 """ 53 return self.node.get('to')
54
55 - def get_function(self):
56 """ 57 Returns the function attribute of the dependency 58 @rtype: string 59 @return: the function attribute 60 """ 61 return self.node.get('rfunc')
62
63 - def set_from(self, f):
64 """ 65 Sets the from attribute 66 @type f: string 67 @param f: the from attribute 68 """ 69 self.node.set('from',f)
70
71 - def set_to(self,t):
72 """ 73 Sets the to attribute 74 @type t: string 75 @param t: the to attribute 76 """ 77 self.node.set('to',t)
78
79 - def set_function(self,f):
80 """ 81 Sets the function attribute 82 @type f: string 83 @param f: the function attribute 84 """ 85 self.node.set('rfunc',f)
86 87
88 - def set_comment(self,c):
89 """ 90 Sets the XML comment for the dependency 91 @type c: string 92 @param c: the string comment 93 """ 94 c = c.replace('--','- -') 95 self.node.insert(0,etree.Comment(c) )
96 97
98 - def __str__(self):
99 return dump(self.node)
100 101 102
103 -class Cdependencies:
104 """ 105 This class encapsulates the dependency layer in KAF/NAF 106 """
107 - def __init__(self,node=None):
108 """ 109 Constructor of the object 110 @type node: xml Element or None (to create and empty one) 111 @param node: this is the node of the element. If it is None it will create a new object 112 """ 113 if node is None: 114 self.node = etree.Element('deps') 115 else: 116 self.node = node
117
118 - def get_node(self):
119 """ 120 Returns the node of the element 121 @rtype: xml Element 122 @return: the node of the element 123 """ 124 return self.node
125
126 - def to_kaf(self):
127 pass
128
129 - def to_naf(self):
130 pass
131
132 - def __str__(self):
133 return dump(self.node)
134 135
136 - def __get_node_deps(self):
137 for node_dep in self.node.findall('dep'): 138 yield node_dep
139
140 - def get_dependencies(self):
141 """ 142 Iterator that returns all the dependencies in the layer 143 @rtype: L{Cdependency} 144 @return: list of dependencies (iterator) 145 """ 146 for node in self.__get_node_deps(): 147 yield Cdependency(node)
148 149
150 - def add_dependency(self,my_dep):
151 """ 152 Adds a dependency object to the layer 153 @type my_dep: L{Cdependency} 154 @param my_dep: the dependency object to be added 155 """ 156 self.node.append(my_dep.get_node())
157