Package entropy :: Module debug

Source Code for Module entropy.debug

  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 
 16   
17 -class DebugList(list):
18 19 """ 20 This class implements a list() object with debug prints using 21 entropy.const.const_debug_write 22 """ 23
24 - def __init__(self):
25 list.__init__(self)
26
27 - def __add__(self, other):
28 const_debug_write(__name__, "%s __add__ called: %s" % (self, other,)) 29 return list.__add__(self, other)
30
31 - def __contains__(self, item):
32 const_debug_write(__name__, "%s __contains__ called: %s" % ( 33 self, item,)) 34 return list.__contains__(self, item)
35
36 - def __delattr__(self, name):
37 const_debug_write(__name__, "%s __delattr__ called: %s" % ( 38 self, name,)) 39 return list.__delattr__(self, name)
40
41 - def __delitem__(self, key):
42 const_debug_write(__name__, "%s __delitem__ called: %s" % ( 43 self, key,)) 44 return list.__delitem__(self, key)
45
46 - def __delslice__(self, i, j):
47 const_debug_write(__name__, "%s __delslice__ called: %s|%s" % ( 48 self, i, j,)) 49 return list.__delslice__(self, i, j)
50
51 - def __eq__(self, other):
52 const_debug_write(__name__, "%s __eq__ called: %s" % ( 53 self, other,)) 54 return list.__eq__(self, other)
55
56 - def __ge__(self, other):
57 const_debug_write(__name__, "%s __ge__ called: %s" % ( 58 self, other,)) 59 return list.__ge__(self, other)
60
61 - def __getattribute__(self, name):
62 const_debug_write(__name__, "%s __getattribute__ called: %s" % ( 63 self, name,)) 64 return list.__getattribute__(self, name)
65
66 - def __getitem__(self, key):
67 const_debug_write(__name__, "%s __getitem__ called: %s" % ( 68 self, key,)) 69 return list.__getitem__(self, key)
70
71 - def __gt__(self, other):
72 const_debug_write(__name__, "%s __gt__ called: %s" % ( 73 self, other,)) 74 return list.__gt__(self, other)
75
76 - def __hash__(self):
77 const_debug_write(__name__, "%s __hash__ called" % ( 78 self,)) 79 return list.__hash__(self)
80
81 - def __iadd__(self, other):
82 const_debug_write(__name__, "%s __iadd__ called: %s" % ( 83 self, other,)) 84 return list.__iadd__(self, other)
85
86 - def __imul__(self, other):
87 const_debug_write(__name__, "%s __imul__ called: %s" % ( 88 self, other,)) 89 return list.__imul__(self, other)
90
91 - def __iter__(self):
92 const_debug_write(__name__, "%s __iter__ called" % ( 93 self,)) 94 return list.__iter__(self)
95
96 - def __le__(self, other):
97 const_debug_write(__name__, "%s __le__ called: %s" % ( 98 self, other,)) 99 return list.__le__(self, other)
100
101 - def __len__(self):
102 const_debug_write(__name__, "%s len called" % (self,)) 103 return list.__len__(self)
104
105 - def __lt__(self, other):
106 const_debug_write(__name__, "%s __lt__ called: %s" % ( 107 self, other,)) 108 return list.__lt__(self, other)
109
110 - def __mul__(self, other):
111 const_debug_write(__name__, "%s __mul__ called: %s" % ( 112 self, other,)) 113 return list.__mul__(self, other)
114
115 - def __ne__(self, other):
116 const_debug_write(__name__, "%s __ne__ called: %s" % ( 117 self, other,)) 118 return list.__ne__(self, other)
119
120 - def __reversed__(self):
121 const_debug_write(__name__, "%s __reversed__ called" % ( 122 self,)) 123 return list.__reversed__(self)
124
125 - def __setattr__(self, name, value):
126 const_debug_write(__name__, "%s __setattr__ called: %s => %s" % ( 127 self, name, value,)) 128 return list.__setattr__(self, name, value)
129
130 - def __setitem__(self, key, value):
131 const_debug_write(__name__, "%s __setitem__ called: %s => %s" % ( 132 self, key, value,)) 133 return list.__setitem__(self, key, value)
134
135 - def __setslice__(self, i, j, sequence):
136 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)
140
141 - def append(self, item):
142 const_debug_write(__name__, "%s append called: %s" % (self, item,)) 143 return list.append(self, item)
144
145 - def count(self, item):
146 const_debug_write(__name__, "%s count called: %s" % (self, item,)) 147 return list.count(self, item)
148
149 - def extend(self, other):
150 const_debug_write(__name__, "%s extend called: %s" % (self, other,)) 151 return list.extend(self, other)
152
153 - def index(self, item):
154 const_debug_write(__name__, "%s index called: %s" % (self, item,)) 155 return list.index(self, item)
156
157 - def insert(self, pos, item):
158 const_debug_write(__name__, 159 "%s insert called: pos:%s => %s" % (self, pos, item,)) 160 return list.insert(self, pos, item)
161
162 - def pop(self, *args, **kwargs):
163 const_debug_write(__name__, 164 "%s pop called: %s, %s" % (self, args, kwargs,)) 165 return list.pop(self, *args, **kwargs)
166
167 - def remove(self, elem):
168 const_debug_write(__name__, "%s remove called: %s" % (self, elem,)) 169 return list.remove(self, elem)
170
171 - def reverse(self):
172 const_debug_write(__name__, "%s reverse called" % (self,)) 173 return list.reverse(self)
174
175 - def sort(self, *args, **kwargs):
176 const_debug_write(__name__, "%s sort called: %s, %s" % ( 177 self, args, kwargs)) 178 return list.sort(self, *args, **kwargs)
179 180
181 -class GraphDrawer(object):
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 """ 192
193 - def __init__(self, entropy_client, graph):
194 """ 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 = pydot
206
207 - def _generate_pydot(self):
208 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 name
215 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 graph
243
244 - def generate_png(self):
245 """ 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_path
255
256 - def generate_dot(self):
257 """ 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_path
267