File: debug.html

package info (click to toggle)
sqlkit 0.9.5-1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 8,184 kB
  • sloc: python: 17,477; sql: 166; makefile: 95; xml: 23; sh: 11
file content (428 lines) | stat: -rw-r--r-- 16,669 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
      <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
      
      <title>
    debug module
 &mdash; sqlkit v0.9.5 documentation</title>
      
    <link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
    <link rel="stylesheet" href="../_static/sqlkit.css" type="text/css" />
    <link rel="stylesheet" href="../_static/print.css" type="text/css" media="print" />

    <link rel="index" title="Index" href="../genindex.html" />
    <link rel="search" title="Search" href="../search.html" />
    <link rel="top" title="sqlkit v0.9.5 documentation" href="../index.html" />
        <link rel="up" title="Debug helpers" href="contents.html" />
        <link rel="next" title="Mailing list" href="../misc/tutorials.html" />
        <link rel="prev" title="Debug helpers" href="contents.html" />
    <script type="text/javascript">
      var DOCUMENTATION_OPTIONS = {
          URL_ROOT:    '../',
          VERSION:     '0.9.5',
          COLLAPSE_MODINDEX: false,
          FILE_SUFFIX: '.html'
      };
    </script>
    <script type="text/javascript" src="../_static/jquery.js"></script>
    <script type="text/javascript" src="../_static/doctools.js"></script>


<!-- <link rel="stylesheet" href="http://www.myjqueryplugins.com/plugins/jmenu/demo/jquery/jMenu.jquery.css" type="text/css" /> -->
      <link rel="stylesheet" href="../_static/jMenu.jquery.css" type="text/css" />
      <script type="text/javascript" src="http://www.myjqueryplugins.com/plugins/jmenu/demo/jquery/jquery.js"></script>
      <script type="text/javascript" src="http://www.myjqueryplugins.com/plugins/jmenu/demo/jquery/jquery-ui.js"></script>

      <!-- <script type="text/javascript" src="http://www.myjqueryplugins.com/plugins/jmenu/demo/jquery/jMenu.jquery.js"></script> -->

      <script type="text/javascript">

	var _gaq = _gaq || [];
	_gaq.push(['_setAccount', 'UA-18221996-2']);
	_gaq.push(['_trackPageview']);

	(function() {
	  var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
	  ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
	  var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
	})();

      </script>
      <script type="text/javascript" src="../_static/jMenu.jquery.js"></script>
      <script type="text/javascript">
	      $(document).ready(function(){
		      $("#jMenu").jMenu({
			      ulWidth : '150',
			      effects : {
				      effectSpeedOpen : 300,
				      effectSpeedClose : 300,
				      effectTypeOpen : 'slide',
				      effectTypeClose : 'slide',
				      effectOpen : 'linear',
				      effectClose : 'linear'
			      },
			      TimeBeforeOpening : 100,
			      TimeBeforeClosing : 400,
			      animatedText : false,
			      paddingLeft: 1		});
	      })
      </script>
<!-- Preview -->
     <script type="text/javascript" src="../_static/imgpreview.js"></script>
     <script type="text/javascript">
       $(document).ready(function(){
           $('.preview').imgPreview();
       });
     </script>
     
     <!--[if !IE 7]>
	     <style type="text/css">
		     #wrap {display:table;height:100%}
	     </style>
     <![endif]-->
    </head>
    <body>
        




<div id="wrap">
    
<div id="header">

	<div class="logo"><a href="../misc/tour.html">
       <img src="../_static/sqlkit.png" align="left"  alt="Logo" border="0"/></a>
        </div>
	<div id="description">Acces to db made easy</div>
</div>


   <div style="clear:left;"></div>


<div >
	<ul id="jMenu">
            <li><a class="fNiv" href="../index.html" title="Home" 
                  >Home</a></li>

            <li><a li class="fNiv" href="../sqlkit/contents.html"
                  title="Sqlkit - the python package" 
                  >Sqlkit</a>

	       <ul>
		 <li ><a href="../sqlkit/contents.html"
		       title="Sqlkit - the python package" 
		       >Sqlkit</a></li>

		 <li ><a href="../sqlkit/sqlwidget.html" title="Widgets" 
		       >Widgets</a>
		       <ul> 
			 <li ><a href="../sqlkit/mask.html" title="Mask" 
			       >Mask view</a></li>
			 <li ><a href="../sqlkit/table.html" title="Table" 
			       >Table view</a></li>
		       </ul>
                 </li>
		 <li ><a href="../sqlkit/browsing.html" title="Browsing Data" 
		       >Browsing data</a>
		    <ul> 
		      <li ><a href="../sqlkit/constraints.html" title="Constraints" 
			    >Constraints</a></li>
		      <li ><a href="../sqlkit/filters.html" title="Filters" 
			    >Filters</a></li>
		      <li ><a href="../sqlkit/totals.html" title="Totals" 
			    >Totals</a></li>
		    </ul>
                 </li>
		 <li ><a href="../sqlkit/editing.html" title="Editing Data" 
		       >Editing data</a>
			 <ul> 
			   <li ><a href="../sqlkit/completion.html" title="Completion" 
				 >Completion</a></li>
			   <li ><a href="../sqlkit/validation.html" title="Validation" 
				 >Validation</a></li>
			   <li ><a href="../sqlkit/relationship.html" title="Relationships" 
				 >Relationships</a></li>
			 </ul>
		       </li>
		 <li ><a href="../sqlkit/printing.html" title="Printing" 
		       ><span>Printing</span></a></li>
		 <li ><a href="../sqlkit/advanced/contents.html" title="Advanced configuration" 
		       >Advanced configuration</a>
			 <ul> 
			   <li ><a href="../sqlkit/advanced/fields.html" title="Fields" 
				 >Fields</a></li>
			   <li ><a href="../sqlkit/advanced/views.html" title="Views" 
				 >Views</a></li>
			 </ul>
		       </li>

	       </ul>
            </li>

            <li><a class="fNiv" href="../misc/sqledit.html"
                  title="Sqledit GUI" 
                  >Sqledit GUI</a></li>

            <li><a class="fNiv" href="../misc/tutorials.html"
                  title="Support & tutorials" 
                  >Support & Tutorials</a>
	       <ul>
		 <li ><a href="../misc/sqledit.html"
		       title="Sqledit - the application" 
		       >Sqledit - the application</a></li>
		 <li ><a href="../misc/tour.html"
		       title="Sqlkit - the features'tour"
		       >Sqlkit - features' tour</a></li>
		 <li ><a href="../misc/sqledit.html"
		       title="Sqledit - the application" 
		       >Installing instructions</a></li>
		</ul> 
            </li>

            <li><a class="fNiv" href="../layout/contents.html" title="Layout"
                  >Layout</a></li>

            <li><a  class="fNiv"href="../misc/contents.html" title="Download" 
                  >Download</a>

	       <ul>
		 <li ><a href="../misc/contents.html"
		       title="Download"
		       >Download</a></li>
		 <li ><a href="http://sqlkit.argolinux.org/download/Changelog"  title="Changelog"
		       title="Changelog"
		       >Changelog</a></li>
		 <li ><a href="../misc/backward_incompatibilities.html"
		       title="Backward incompatibilities"
		       >Backward incompatibilities</a></li>
	       </ul>
            </li>



        </ul>
</div>
   <div style="clear:left;"></div>

    
    <div class="related">
      <ul>
	
<!-- <div class="prevnext"> -->
<!--    <li class="right"  style="margin-right: 10px">Indice -->
<!--      <a href="../genindex.html" title="Indice generale" -->
<!--                accesskey="I">indice</a></li> -->

        <li class="right">Prev:
        <a href="contents.html" title="previous chapter">Debug helpers</a></li>
        <li class="right">Next:
        <a href="../misc/tutorials.html" title="next chapter">Mailing list</a></li>
<!-- </div> -->


      </ul>

    </div>

    
  <div class="sphinxsidebar">
     <div class="sphinxsidebarwrapper">


	    <div class="topnav">
    <h3>Table of contents</h3>
		    <ul>
<li><a class="reference external" href="#">debug module</a></li>
<li><a class="reference external" href="#purpose">purpose</a></li>
<li><a class="reference external" href="#use">use</a><ul>
<li><a class="reference external" href="#switching-debug-on-off">switching debug on &amp; off</a></li>
<li><a class="reference external" href="#write-caller">write() - caller()</a></li>
<li><a class="reference external" href="#logging-methods">Logging methods</a></li>
<li><a class="reference external" href="#traceit">TraceIt</a></li>
</ul>
</li>
</ul>

		<div class="clearboth"></div>
	    </div>



    <h3>Questions?</h3>

    <p>Subscribe to out mailing list <a href="http://groups.google.com/group/sqlkit">
       Google group</a>:</p>

    <form action="http://groups.google.com/group/sqlkit/boxsubscribe" style="padding-left: 1em">
      <input type="text" name="email" value="your@email"/>
      <input type="submit" name="sub" value="Subscribe" />
    </form>
    <div id="searchbox" style="display: none">

    <h3>Quick search</h3>
	<form class="search" action="../search.html" method="get">
	  <input type="text" name="q" size="18" />
	  <input type="submit" value="Search" />
	  <input type="hidden" name="check_keywords" value="yes" />

	  <input type="hidden" name="area" value="default" />
	</form>
	<p class="searchtip" style="font-size: 90%">
        Enter search terms or a module, class or function name.
	</p>
    <h3>License</h3>
	<img src="../_static/gplv3.png" alt="logo GPLv3">

    </div>
    <script type="text/javascript">$('#searchbox').show(0);</script>

     </div>
  </div>

    <div class="document">
      <div class="documentwrapper">
        <div class="bodywrapper">

            <div class="body">
                
<div class="section" id="debug-module">
<h1>debug module<a class="headerlink" href="#debug-module" title="Permalink to this headline">¶</a></h1>
<div class="highlight-python"><div class="highlight"><pre><span class="kn">from</span> <span class="nn">sqlkit</span> <span class="kn">import</span> <span class="n">debug</span> <span class="k">as</span> <span class="n">dbg</span>
</pre></div>
</div>
</div>
<div class="section" id="purpose">
<h1>purpose<a class="headerlink" href="#purpose" title="Permalink to this headline">¶</a></h1>
<img align="right" alt="../_images/gtk_debug.png" class="align-right" src="../_images/gtk_debug.png" />
<p>This module provides easy way to debug with print commands. This is not in
general my preferred way of debugging (<tt class="docutils literal"><span class="pre">pdb</span></tt> within ipython being my
preferred solution). Nevertheless I found myself in need of these functions.</p>
<p>Printing of messages can be easily switched on or off.</p>
<p>Printing can diverted to a gtk widget.</p>
<p>Methods of Classes can be tracked in the way reported in the image, where
blue rows correspond to <tt class="docutils literal"><span class="pre">dbg.write</span></tt>  commands and all the rest is
tracking of methods calls.</p>
</div>
<div class="section" id="use">
<h1>use<a class="headerlink" href="#use" title="Permalink to this headline">¶</a></h1>
<div class="section" id="switching-debug-on-off">
<h2>switching debug on &amp; off<a class="headerlink" href="#switching-debug-on-off" title="Permalink to this headline">¶</a></h2>
<p>The way to use this is</p>
<blockquote>
<ol class="arabic">
<li><p class="first">in you library:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="kn">from</span> <span class="nn">sqlkit</span> <span class="kn">import</span> <span class="n">debug</span> <span class="k">as</span> <span class="n">dbg</span>
<span class="n">dbg</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s">&#39;text message&#39;</span><span class="p">,</span> <span class="s">&#39;text2&#39;</span><span class="p">)</span>
</pre></div>
</div>
</li>
<li><p class="first">in you application:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="kn">from</span> <span class="nn">sqlkit</span> <span class="kn">import</span> <span class="n">debug</span> <span class="k">as</span> <span class="n">dbg</span>
<span class="n">dbg</span><span class="o">.</span><span class="n">debug</span><span class="p">(</span><span class="bp">True</span><span class="p">)</span>
</pre></div>
</div>
</li>
</ol>
</blockquote>
</div>
<div class="section" id="write-caller">
<h2>write() - caller()<a class="headerlink" href="#write-caller" title="Permalink to this headline">¶</a></h2>
<p>from now on, each time you use dbg.write()/dbg.caller() you&#8217;ll see the text you
want to log anly if you enabled it with dbg.debug(True)</p>
<p>If you want the log to happen in a gtk.TreeView window, you can specify:;</p>
<blockquote>
import dbg
dbg.debug(True, gtk=True)</blockquote>
</div>
<div class="section" id="logging-methods">
<h2>Logging methods<a class="headerlink" href="#logging-methods" title="Permalink to this headline">¶</a></h2>
<p>Following recipe 198078 in the ASP Python CookBook (see in the code)
this module provides also a metaclass to trace the use of methods of a
particular class. It will be instantiated as:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="k">class</span> <span class="nc">A</span><span class="p">(</span><span class="nb">object</span><span class="p">):</span>
    <span class="n">__metaclass__</span> <span class="o">=</span> <span class="n">dbg</span><span class="o">.</span><span class="n">LogTheMethods</span>
</pre></div>
</div>
<p>for each method call a line will be logged (unless configured to be ignored)
with</p>
<blockquote>
function called
caller class
arguments
caller function
line of code
return code
calling class
time elapsed</blockquote>
<p>IMPORTANT: since the logging occurs with metaclasses you need to import dbg and
set debugging <em>before</em> importing the class you want to trace:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="kn">from</span> <span class="nn">sqlkit</span> <span class="kn">import</span> <span class="n">debug</span> <span class="k">as</span> <span class="n">dbg</span>
<span class="n">dbg</span><span class="o">.</span><span class="n">debug</span><span class="p">(</span><span class="bp">True</span><span class="p">,</span> <span class="n">gtk</span><span class="o">=</span><span class="bp">True</span><span class="p">)</span>
<span class="n">dbg</span><span class="o">.</span><span class="n">trace_class</span><span class="p">(</span><span class="s">&#39;SqlTable2&#39;</span><span class="p">)</span>  <span class="c"># optional</span>
<span class="n">dbg</span><span class="o">.</span><span class="n">trace_function</span><span class="p">(</span><span class="n">exclude</span><span class="o">=</span><span class="s">&#39;cell_default_cb|cell_bool_cb&#39;</span><span class="p">)</span>  <span class="c"># optional</span>
<span class="kn">import</span> <span class="nn">sqlkit</span>
</pre></div>
</div>
</div>
<div class="section" id="traceit">
<h2>TraceIt<a class="headerlink" href="#traceit" title="Permalink to this headline">¶</a></h2>
<p>in case you need to understand who is changing the value of a variable, you
can use TraceIt as:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="n">commit_allowed</span> <span class="o">=</span> <span class="n">dbg</span><span class="o">.</span><span class="n">TraceIt</span><span class="p">(</span><span class="bp">True</span><span class="p">,</span> <span class="n">name</span><span class="o">=</span><span class="s">&#39;commit_allowed&#39;</span><span class="p">,</span> <span class="n">mode</span><span class="o">=</span><span class="s">&#39;rw&#39;</span><span class="p">)</span>
</pre></div>
</div>
<p>and use it as a normal variable.  You&#8217;ll get lines in your output stating
who changed the value of that variable, in the form:</p>
<div class="highlight-python"><pre>__str__/function_name:  old_value =&gt; new_value
__get__/function_name:  value</pre>
</div>
</div>
</div>


            </div>
        </div>
     </div>
   </div>

        
</div> <!-- wrap -->

            <div class="bottomnav footer">
                <div class="doc_copyright">
                Alessandro Dentella -- Copyright 2006-2007-2008-2009-2010
		  Sqlkit release 0.9.5
<!--                 % if hasdoc('copyright'): -->
<!--                     &copy; <a href="../copyright.html">Copyright</a> 2008, Sandro Dentella. -->
<!--                 % else: -->
<!--                     &copy; Copyright 2008, Sandro Dentella. -->
<!--                 % endif -->
                    creato usando  <a href="http://sphinx.pocoo.org/">Sphinx</a> 0.6.4.
                </div>
            </div>
        












<br style="clear: left" />

    </body>
</html>