comparison farolluz/producttree.py @ 47:652f59fbea3a

Docstring update + use a set where due
author Benoît Allard <benoit.allard@greenbone.net>
date Tue, 30 Dec 2014 12:29:07 +0100
parents 1b7f3f4f1238
children
comparison
equal deleted inserted replaced
46:1b7f3f4f1238 47:652f59fbea3a
79 self.getProductForID(parent._relatestoproductreference), 79 self.getProductForID(parent._relatestoproductreference),
80 self.getProductForID(parent._productreference) 80 self.getProductForID(parent._productreference)
81 ) 81 )
82 82
83 def getBranch(self, path): 83 def getBranch(self, path):
84 """ path is a tuple of indexes """
84 if len(path) == 0: 85 if len(path) == 0:
85 return self 86 return self
86 branches = self._branches 87 branches = self._branches
87 node = None 88 node = None
88 for idx in path: 89 for idx in path:
118 def getNotTerminalBranches(self, b2=None): 119 def getNotTerminalBranches(self, b2=None):
119 """\ 120 """\
120 The branches that could accept `b2` as new sub-branches 121 The branches that could accept `b2` as new sub-branches
121 Note that b2 and all its sub-branches cannot be listed 122 Note that b2 and all its sub-branches cannot be listed
122 """ 123 """
123 black_list = [] 124 black_list = set()
124 if b2 is not None: 125 if b2 is not None:
125 black_list = [b2] + list(b2.getBranches()) 126 black_list.add(b2)
127 black_list.update(b2.getBranches())
126 for branch in self.getBranches(): 128 for branch in self.getBranches():
127 if branch in black_list: 129 if branch in black_list:
128 continue 130 continue
129 if branch._product is None: 131 if branch._product is None:
130 yield branch 132 yield branch
198 200
199 def getParent(self): 201 def getParent(self):
200 return self._parentbranch 202 return self._parentbranch
201 203
202 def getPath(self, string=False): 204 def getPath(self, string=False):
203 """ return the path to that branch element as a tuple """ 205 """ return the path to that branch element as a tuple or as '/'
206 separated string """
204 if self.isRoot(): 207 if self.isRoot():
205 for i, b in enumerate(self._parentbranch._branches): 208 for i, b in enumerate(self._parentbranch._branches):
206 if b is self: 209 if b is self:
207 if string: 210 if string:
208 return '%d' % i 211 return '%d' % i
250 else: 253 else:
251 self.getParent()._childs.remove(self) 254 self.getParent()._childs.remove(self)
252 self._parentbranch = None 255 self._parentbranch = None
253 256
254 def link(self, parent): 257 def link(self, parent):
255 """ Actually, only set the parent """ 258 """ Set the parent, and add ourself to our parent's childs """
256 self._parentbranch = parent 259 self._parentbranch = parent
257 if self.isRoot(): 260 if self.isRoot():
258 parent._branches.append(self) 261 parent._branches.append(self)
259 else: 262 else:
260 parent._childs.append(self) 263 parent._childs.append(self)
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)