comparison orpg/tools/orpg_log.py @ 135:dcf4fbe09b70 beta

Traipse Beta 'OpenRPG' {091010-00} Traipse is a distribution of OpenRPG that is designed to be easy to setup and go. Traipse also makes it easy for developers to work on code without fear of sacrifice. 'Ornery-Orc' continues the trend of 'Grumpy' and adds fixes to the code. 'Ornery-Orc's main goal is to offer more advanced features and enhance the productivity of the user. Update Summary (Beta) Added Bookmarks Fix to Remote Admin Commands Minor fix to text based Server Fix to Pretty Print, from Core Fix to Splitter Nodes not being created Fix to massive amounts of images loading, from Core Added 'boot' command to remote admin Added confirmation window for sent nodes Minor changes to allow for portability to an OpenSUSE linux OS Miniatures Layer pop up box allows users to turn off Mini labels, from FlexiRPG Zoom Mouse plugin added Images added to Plugin UI Switching to Element Tree Map efficiency, from FlexiRPG Added Status Bar to Update Manager default_manifest.xml renamed to default_upmana.xml Cleaner clode for saved repositories New TrueDebug Class in orpg_log (See documentation for usage) Mercurial's hgweb folder is ported to upmana **Pretty important update that can help remove thousands of dead children from your gametree. **Children, <forms />, <group_atts />, <horizontal />, <cols />, <rows />, <height />, etc... are all tags now. Check your gametree and look for dead children!! **New Gamtree Recusion method, mapping, and context sensitivity. !!Alpha - Watch out for infinite loops!!
author sirebral
date Tue, 10 Nov 2009 14:11:28 -0600
parents 118fbe111922
children 2345c12d93a7
comparison
equal deleted inserted replaced
101:394ebb3b6a0f 135:dcf4fbe09b70
25 # 25 #
26 # Description: classes for orpg log messages 26 # Description: classes for orpg log messages
27 # 27 #
28 28
29 from __future__ import with_statement 29 from __future__ import with_statement
30 import sys, os, os.path, wx, time, traceback 30 import sys, os, os.path, time, traceback, inspect, wx
31 31
32 from orpg.orpgCore import component 32 from orpg.orpgCore import component
33 from orpg.external.terminalwriter import TerminalWriter 33 from orpg.external.terminalwriter import TerminalWriter
34 from orpg.tools.decorators import pending_deprecation 34 from orpg.tools.decorators import pending_deprecation
35 from orpg.dirpath import dir_struct 35 from orpg.dirpath import dir_struct
36 36
37 ######################### 37 #########################
38 ## Error Types 38 ## Error Types
39 ######################### 39 #########################
40 ORPG_PRINT = 0
40 ORPG_CRITICAL = 1 41 ORPG_CRITICAL = 1
41 ORPG_GENERAL = 2 42 ORPG_GENERAL = 2
42 ORPG_INFO = 4 43 ORPG_INFO = 4
43 ORPG_NOTE = 8 44 ORPG_NOTE = 8
44 ORPG_DEBUG = 16 45 ORPG_DEBUG = 16
46
45 47
46 def Crash(type, value, crash): 48 def Crash(type, value, crash):
47 crash_report = open(dir_struct["home"] + 'crash-report.txt', "w") 49 crash_report = open(dir_struct["home"] + 'crash-report.txt', "w")
48 traceback.print_exception(type, value, crash, file=crash_report) 50 traceback.print_exception(type, value, crash, file=crash_report)
49 crash_report.close() 51 crash_report.close()
53 logger.exception(msg) 55 logger.exception(msg)
54 crash_report.close() 56 crash_report.close()
55 logger.exception("Crash Report Created!!") 57 logger.exception("Crash Report Created!!")
56 logger.info("Printed out crash-report.txt in your System folder", True) 58 logger.info("Printed out crash-report.txt in your System folder", True)
57 59
60 class Term2Win(object):
61 # A stdout redirector. Allows the messages from Mercurial to be seen in the Install Window
62 def write(self, text):
63 #logger.stdout(text)
64 wx.Yield()
65 sys.__stdout__.write(text)
66
67 class TrueDebug(object):
68 ### Alpha ###
69 """A simple debugger. Add debug() to a function and it prints the function name and any objects included. Add an object or a group of objects in ()'s.
70 Adding True to locale prints the file name where the function is. Adding False to log turns the log off.
71 Adding True to parents will print out the parent functions, starting from TrueDebug.
72 This feature can be modified to trace deeper and find the bugs faster, ending the puzzle box."""
73 def __init__(self, objects=None, locale=False, log=True, parents=False):
74 if log == False: return
75 current = inspect.currentframe()
76 if parents: self.get_parents(current)
77 else: self.true_debug(current, objects, locale)
78
79 def true_debug(self, current, objects, locale):
80 debug_string = 'Function: ' + str(inspect.getouterframes(current)[1][3])
81 #if locale == 'all': print inspect.getouterframes(current)[4]; return
82 if objects != None: debug_string += ' Objects: ' + str(objects)
83 if locale: debug_string += ' File: ' + str(inspect.getouterframes(current)[1][1])
84 logger.debug(debug_string, True)
85 return
86
87 def get_parents(self, current):
88 debug_string = 'Function: ' + str(inspect.getouterframes(current)[1][3]) + ' Parents:'
89 family = list(inspect.getouterframes(current))
90 for parent in family:
91 debug_string += ' ' + str(parent[4])
92 logger.debug(debug_string, True)
93 return
94
58 class DebugConsole(wx.Frame): 95 class DebugConsole(wx.Frame):
59 def __init__(self, parent): 96 def __init__(self, parent):
60 super(DebugConsole, self).__init__(parent, -1, "Debug Console") 97 super(DebugConsole, self).__init__(parent, -1, "Debug Console")
61 icon = None
62 icon = wx.Icon(dir_struct["icon"]+'note.ico', wx.BITMAP_TYPE_ICO) 98 icon = wx.Icon(dir_struct["icon"]+'note.ico', wx.BITMAP_TYPE_ICO)
63 self.SetIcon( icon ) 99 self.SetIcon(icon)
64 self.console = wx.TextCtrl(self, -1, style=wx.TE_MULTILINE | wx.TE_READONLY) 100 self.console = wx.TextCtrl(self, -1, style=wx.TE_MULTILINE | wx.TE_READONLY)
65 sizer = wx.BoxSizer(wx.VERTICAL) 101 self.bt_clear = wx.Button(self, wx.ID_CLEAR)
66 sizer.Add(self.console, 1, wx.EXPAND) 102 self.report = wx.Button(self, wx.ID_ANY, 'Bug Report')
103 sizer = wx.GridBagSizer(hgap=1, vgap=1)
104 sizer.Add(self.console, (0,0), span=(1,2), flag=wx.EXPAND)
105 sizer.Add(self.bt_clear, (1,0), flag=wx.ALIGN_LEFT)
106 sizer.Add(self.report, (1,1), flag=wx.ALIGN_LEFT)
107 sizer.AddGrowableCol(0)
108 sizer.AddGrowableRow(0)
67 self.SetSizer(sizer) 109 self.SetSizer(sizer)
68 self.SetAutoLayout(True) 110 self.SetAutoLayout(True)
69 self.SetSize((300, 175)) 111 self.SetSize((450, 175))
70 self.Bind(wx.EVT_CLOSE, self.Min) 112 self.Bind(wx.EVT_CLOSE, self.Min)
113 self.Bind(wx.EVT_BUTTON, self.clear, self.bt_clear)
114 self.Bind(wx.EVT_BUTTON, self.bug_report, self.report)
71 self.Min(None) 115 self.Min(None)
116 #sys.stdout = Term2Win()
72 component.add('debugger', self.console) 117 component.add('debugger', self.console)
73 118
74 def Min(self, evt): 119 def Min(self, evt):
75 self.Hide() 120 self.Hide()
121
122 def clear(self, evt):
123 self.console.SetValue('')
124
125 def bug_report(self, evt):
126 pass
76 127
77 class orpgLog(object): 128 class orpgLog(object):
78 _log_level = 7 129 _log_level = 7
79 _log_name = None 130 _log_name = None
80 _log_to_console = False 131 _log_to_console = False
125 try: self._io.line(str(msg), **self._lvl_args[log_type]['colorizer']) 176 try: self._io.line(str(msg), **self._lvl_args[log_type]['colorizer'])
126 except: pass #Fails without the Debug Console 177 except: pass #Fails without the Debug Console
127 try: component.get('debugger').AppendText(".. " + str(msg) +'\n') 178 try: component.get('debugger').AppendText(".. " + str(msg) +'\n')
128 except: pass 179 except: pass
129 180
130 if log_type & self.log_level or to_console: 181 if log_type and (self.log_level or to_console):
131 atr = {'msg': msg, 'level': self._lvl_args[log_type]['log_string']} 182 atr = {'msg': msg, 'level': self._lvl_args[log_type]['log_string']}
132 atr['time'] = time.strftime('[%x %X]', time.localtime(time.time())) 183 atr['time'] = time.strftime('[%x %X]', time.localtime(time.time()))
133 logMsg = '%(time)s (%(level)s) - %(msg)s\n' % (atr) 184 logMsg = '%(time)s (%(level)s) - %(msg)s\n' % (atr)
134 185
135 with open(self.log_name, 'a') as f: 186 with open(self.log_name, 'a') as f:
190 log_name = property(_get_log_name, _set_log_name) 241 log_name = property(_get_log_name, _set_log_name)
191 log_to_console = property(_get_log_to_console, _set_log_to_console) 242 log_to_console = property(_get_log_to_console, _set_log_to_console)
192 243
193 logger = orpgLog(dir_struct.get("user") + "runlogs/") 244 logger = orpgLog(dir_struct.get("user") + "runlogs/")
194 crash = sys.excepthook = Crash 245 crash = sys.excepthook = Crash
246 debug = TrueDebug