Home | Trees | Indices | Help |
|
---|
|
1 # -*- coding: utf-8 -*- 2 """ 3 4 @author: Fabio Erculiani <[email protected]> 5 @contact: [email protected] 6 @copyright: Fabio Erculiani 7 @license: GPL-2 8 9 B{Entropy Package Manager Debug classes}. 10 11 """ 12 import os 13 14 from entropy.const import const_debug_write, const_setup_file, \ 15 const_mkstemp, etpConst 1618 19 """ 20 This class implements a list() object with debug prints using 21 entropy.const.const_debug_write 22 """ 23 26179 18028 const_debug_write(__name__, "%s __add__ called: %s" % (self, other,)) 29 return list.__add__(self, other)3032 const_debug_write(__name__, "%s __contains__ called: %s" % ( 33 self, item,)) 34 return list.__contains__(self, item)3537 const_debug_write(__name__, "%s __delattr__ called: %s" % ( 38 self, name,)) 39 return list.__delattr__(self, name)4042 const_debug_write(__name__, "%s __delitem__ called: %s" % ( 43 self, key,)) 44 return list.__delitem__(self, key)4547 const_debug_write(__name__, "%s __delslice__ called: %s|%s" % ( 48 self, i, j,)) 49 return list.__delslice__(self, i, j)5052 const_debug_write(__name__, "%s __eq__ called: %s" % ( 53 self, other,)) 54 return list.__eq__(self, other)5557 const_debug_write(__name__, "%s __ge__ called: %s" % ( 58 self, other,)) 59 return list.__ge__(self, other)6062 const_debug_write(__name__, "%s __getattribute__ called: %s" % ( 63 self, name,)) 64 return list.__getattribute__(self, name)6567 const_debug_write(__name__, "%s __getitem__ called: %s" % ( 68 self, key,)) 69 return list.__getitem__(self, key)7072 const_debug_write(__name__, "%s __gt__ called: %s" % ( 73 self, other,)) 74 return list.__gt__(self, other)75 8082 const_debug_write(__name__, "%s __iadd__ called: %s" % ( 83 self, other,)) 84 return list.__iadd__(self, other)8587 const_debug_write(__name__, "%s __imul__ called: %s" % ( 88 self, other,)) 89 return list.__imul__(self, other)90 9597 const_debug_write(__name__, "%s __le__ called: %s" % ( 98 self, other,)) 99 return list.__le__(self, other)100 104106 const_debug_write(__name__, "%s __lt__ called: %s" % ( 107 self, other,)) 108 return list.__lt__(self, other)109111 const_debug_write(__name__, "%s __mul__ called: %s" % ( 112 self, other,)) 113 return list.__mul__(self, other)114116 const_debug_write(__name__, "%s __ne__ called: %s" % ( 117 self, other,)) 118 return list.__ne__(self, other)119121 const_debug_write(__name__, "%s __reversed__ called" % ( 122 self,)) 123 return list.__reversed__(self)124126 const_debug_write(__name__, "%s __setattr__ called: %s => %s" % ( 127 self, name, value,)) 128 return list.__setattr__(self, name, value)129131 const_debug_write(__name__, "%s __setitem__ called: %s => %s" % ( 132 self, key, value,)) 133 return list.__setitem__(self, key, value)134136 const_debug_write(__name__, 137 "%s __setslice__ called: i:%s,j:%s,seq:%s" % ( 138 self, i, j, sequence,)) 139 return list.__setslice__(self, i, j, sequence)140142 const_debug_write(__name__, "%s append called: %s" % (self, item,)) 143 return list.append(self, item)144146 const_debug_write(__name__, "%s count called: %s" % (self, item,)) 147 return list.count(self, item)148150 const_debug_write(__name__, "%s extend called: %s" % (self, other,)) 151 return list.extend(self, other)152154 const_debug_write(__name__, "%s index called: %s" % (self, item,)) 155 return list.index(self, item)156158 const_debug_write(__name__, 159 "%s insert called: pos:%s => %s" % (self, pos, item,)) 160 return list.insert(self, pos, item)161163 const_debug_write(__name__, 164 "%s pop called: %s, %s" % (self, args, kwargs,)) 165 return list.pop(self, *args, **kwargs)166168 const_debug_write(__name__, "%s remove called: %s" % (self, elem,)) 169 return list.remove(self, elem)170 174176 const_debug_write(__name__, "%s sort called: %s, %s" % ( 177 self, args, kwargs)) 178 return list.sort(self, *args, **kwargs)182 183 """ 184 GraphDrawer is a draw generator for entropy.graph.Graph objects using 185 pydot library, which uses Graphviz. 186 It requires pydot installed. 187 NOTE for packagers: this is debug code included in the entropy core library. 188 It doesn't mean you're allowed to include pydot as entropy dependency. 189 If you do so, the same class will be wiped out and you'll be fucked ;-) 190 191 """ 192243194 """ 195 GraphDrawer Constructor. 196 197 @param entropy_client: Entropy Client interfaces 198 @type entropy_client: entropy.client.interfaces.client.Client 199 @param graph: a finalized entropy.graph.Graph object ready to be drawed 200 @type graph: entropy.graph.Graph 201 """ 202 self._entropy = entropy_client 203 self._entropy_graph = graph 204 import pydot 205 self._pydot = pydot206208 209 def _get_name(pkg_match): 210 pkg_id, repo_id = pkg_match 211 repo = self._entropy.open_repository(repo_id) 212 name = "%s::%s,%d" % (repo.retrieveAtom(pkg_id), 213 repo_id, pkg_id) 214 return name215 216 graph = self._pydot.Dot(graph_name="Packages", 217 graph_type="digraph", suppress_disconnected=True) 218 219 # thanks 220 # key = package match 221 # value = entropy.graph.GraphNode object 222 raw_graph = self._entropy_graph._graph_debug() 223 # first add all the nodes 224 name_map = {} 225 for pkg_match in raw_graph.keys(): 226 name = _get_name(pkg_match) 227 name_map[pkg_match] = name 228 node = self._pydot.Node(name) 229 graph.add_node(node) 230 # now add edges 231 for pkg_match, graph_node in raw_graph.items(): 232 # list of GraphArchSet 233 outgoing_arches = [x for x in graph_node.arches() if \ 234 graph_node.is_arch_outgoing(x)] 235 for arch in outgoing_arches: 236 arch_pkg_matches = [x.item() for x in arch.endpoints()] 237 for arch_pkg_match in arch_pkg_matches: 238 edge = self._pydot.Edge(name_map[pkg_match], 239 name_map[arch_pkg_match]) 240 graph.add_edge(edge) 241 242 return graph245 """ 246 Generate a PNG from current Graph content. 247 """ 248 graph = self._generate_pydot() 249 tmp_fd, tmp_path = const_mkstemp(prefix="entropy.graph", 250 suffix=".png") 251 os.close(tmp_fd) 252 graph.write_png(tmp_path) 253 const_setup_file(tmp_path, etpConst['entropygid'], 0o644) 254 return tmp_path255257 """ 258 Generate RAW dot file that can be used to feed graphviz 259 """ 260 graph = self._generate_pydot() 261 tmp_fd, tmp_path = const_mkstemp(prefix="entropy.graph", 262 suffix=".dot") 263 os.close(tmp_fd) 264 graph.write_raw(tmp_path) 265 const_setup_file(tmp_path, etpConst['entropygid'], 0o644) 266 return tmp_path267
Home | Trees | Indices | Help |
|
---|
Generated by Epydoc 3.0.1 on Sun Apr 22 00:00:27 2018 | http://epydoc.sourceforge.net |