jayven avatar jayven committed 3e5cd8d

Add hotlog feature

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 = """
-Usage:
+Console:
+    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.
     locals:
         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.
+
+Help:
+    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' % (datetime.now().strftime("%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',
             'console',
             'Last exception traceback'),
+        'hotlog': fields.function(_hotlog_get, type='text', method=True,
+            string='Log',
+            readonly=True),
         'help': fields.text('Help', readonly=True),
     }
     _defaults = {
                             <field name="last_value" nolabel="1" colspan="4" />
                             <field name="last_traceback"  string="tracebacks" widget="one2many_list" nolabel="1" readonly="1" colspan="4" />
                         </page>
+                        <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"/>
                         </page>
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.