jayven  committed 3e5cd8d

Add hotlog feature

  • Participants
  • Parent commits ae3e056
  • Branches add_hotlog

Comments (0)

Files changed (2)

 import linecache
 from itertools import izip, islice
 from bgconsole import BGConsole
+from datetime import datetime
 from osv import osv, fields
 help_text = """
+    This page contains an interactive console
     Enter python src in Cmd then press 'Save' (or Ctrl+S) to send
     it to the console. Both single line and multi-lines are supported.
     openerp client from striping the indent spaces before 'pass' and the
     newline after 'pass'
-Python environ:
     The console is a code.InteractiveConsole instance.
         uid: the uid that open the console
         cr: the cursor
         pool: the object pool
+Last exception:
+    This page contains the last expection and traceback throwed by the console
+Hot log:
+    This page contains a log, one can use
+        hotlog('log information')
+    in source code instead of print out elsewhere.
+    Just this page.
 def norm_select(select):
     return ns_cache[id(ns)]
+hotlog_data = ''
+def hotlog(s):
+    global hotlog_data
+    hotlog_data += '\n[%s] %s' % ("%F %X"), s)
+# affect everywhere
+import __builtin__
+__builtin__.__dict__['hotlog'] = hotlog
 class DebugConsole(osv.osv_memory):
     def _get_console(self, cr, uid, id, context):
         return True
+    def _hotlog_get(self, cr, uid, ids, field_name, arg, context=None):
+        return dict(((id, hotlog_data) for id in norm_select(ids)))
+    def clear_hotlog(self, cr, uid, ids, context=None):
+        global hotlog_data
+        hotlog_data = ''
+        return True
     def restart_console(self, cr, uid, ids, context=None):
         if context is None:
             context = {}
         'last_traceback': fields.one2many('hotdebug.tb',
             'Last exception traceback'),
+        'hotlog': fields.function(_hotlog_get, type='text', method=True,
+            string='Log',
+            readonly=True),
         'help': fields.text('Help', readonly=True),
     _defaults = {

File debugger.xml

                             <field name="last_value" nolabel="1" colspan="4" />
                             <field name="last_traceback"  string="tracebacks" widget="one2many_list" nolabel="1" readonly="1" colspan="4" />
+                        <page string="Hot Log">
+                            <field nolabel="1" colspan="4" name="hotlog" />
+                            <button colspan="4" name="clear_hotlog" string="Clear Log" type="object" icon="gtk-go-forward" />
+                        </page>
                         <page string="Help">
                             <field name="help" nolabel="1" colspan="4"/>