comparison orpg/tools/orpg_log.py @ 28:ff154cf3350c ornery-orc

Traipse 'OpenRPG' {100203-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 (Stable) New Features: New Bookmarks Feature New 'boot' command to remote admin New confirmation window for sent nodes Miniatures Layer pop up box allows users to turn off Mini labels, from FlexiRPG New Zoom Mouse plugin added New Images added to Plugin UI Switching to Element Tree New Map efficiency, from FlexiRPG New Status Bar to Update Manager New TrueDebug Class in orpg_log (See documentation for usage) New Portable Mercurial New Tip of the Day, from Core and community New Reference Syntax added for custom PC sheets New Child Reference for gametree New Parent Reference for gametree New Gametree Recursion method, mapping, context sensitivity, and effeciency.. New Features node with bonus nodes and Node Referencing help added New Dieroller structure from Core New DieRoller portability for odd Dice New 7th Sea die roller; ie [7k3] = [7d10.takeHighest(3).open(10)] New 'Mythos' System die roller added New vs. die roller method for WoD; ie [3v3] = [3d10.vs(3)]. Included for Mythos roller also New Warhammer FRPG Die Roller (Special thanks to Puu-san for the support) New EZ_Tree Reference system. Push a button, Traipse the tree, get a reference (Beta!) New Grids act more like Spreadsheets in Use mode, with Auto Calc Fixes: Fix to allow for portability to an OpenSUSE linux OS Fix to mplay_client for Fedora and OpenSUSE Fix to Text based Server Fix to Remote Admin Commands Fix to Pretty Print, from Core Fix to Splitter Nodes not being created Fix to massive amounts of images loading, from Core Fix to Map from gametree not showing to all clients Fix to gametree about menus Fix to Password Manager check on startup Fix to PC Sheets from tool nodes. They now use the tabber_panel Fix to Whiteboard ID to prevent random line or text deleting. Fixes to Server, Remote Server, and Server GUI Fix to Update Manager; cleaner clode for saved repositories Fixes made to Settings Panel and now reactive settings when Ok is pressed Fixes to Alternity roller's attack roll. Uses a simple Tuple instead of a Splice Fix to Use panel of Forms and Tabbers. Now longer enters design mode Fix made Image Fetching. New fetching image and new failed image Fix to whiteboard ID's to prevent non updated clients from ruining the fix. default_manifest.xml renamed to default_upmana.xml
author sirebral
date Wed, 03 Feb 2010 22:16:49 -0600
parents 51428d30c59e
children fc48380f0c9f
comparison
equal deleted inserted replaced
27:51428d30c59e 28:ff154cf3350c
19 # 19 #
20 # File: orpg_log.py 20 # File: orpg_log.py
21 # Author: Dj Gilcrease 21 # Author: Dj Gilcrease
22 # Maintainer: 22 # Maintainer:
23 # Version: 23 # Version:
24 # $Id: orpg_log.py,v 1.9 2007/05/06 16:43:02 digitalxero Exp $ 24 # $Id: orpg_log.py,v Traipse 'Ornery-Orc' prof.ebral Exp $
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. To be implemented later.
62 def write(self, text):
63 logger.stdout(text)
64 wx.Yield()
65 #sys.__stdout__.write(text)
66
67 class TrueDebug(object):
68 """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.
69 Adding True to locale prints the file name where the function is. Adding False to log turns the log off.
70 Adding True to parents will print out the parent functions, starting from TrueDebug.
71 This feature can be modified to trace deeper and find the bugs faster, ending the puzzle box."""
72 def __init__(self, objects=None, locale=False, log=True, parents=False):
73 if log == False: return
74 current = inspect.currentframe()
75 if parents: self.get_parents(current)
76 else: self.true_debug(current, objects, locale)
77
78 def true_debug(self, current, objects, locale):
79 debug_string = 'Function: ' + str(inspect.getouterframes(current)[1][3])
80 #if locale == 'all': print inspect.getouterframes(current)[4]; return
81 if objects != None: debug_string += ' Objects: ' + str(objects)
82 if locale: debug_string += ' File: ' + str(inspect.getouterframes(current)[1][1])
83 logger.debug(debug_string, True)
84 return
85
86 def get_parents(self, current):
87 debug_string = 'Function: ' + str(inspect.getouterframes(current)[1][3]) + ' Parents:'
88 family = list(inspect.getouterframes(current))
89 for parent in family:
90 debug_string += ' ' + str(parent[4])
91 logger.debug(debug_string, True)
92 return
93
58 class DebugConsole(wx.Frame): 94 class DebugConsole(wx.Frame):
59 def __init__(self, parent): 95 def __init__(self, parent):
60 super(DebugConsole, self).__init__(parent, -1, "Debug Console") 96 super(DebugConsole, self).__init__(parent, -1, "Debug Console")
61 icon = None
62 icon = wx.Icon(dir_struct["icon"]+'note.ico', wx.BITMAP_TYPE_ICO) 97 icon = wx.Icon(dir_struct["icon"]+'note.ico', wx.BITMAP_TYPE_ICO)
63 self.SetIcon( icon ) 98 self.parent = parent
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), span=(1,1), flag=wx.ALIGN_LEFT)
106 sizer.Add(self.report, (1,1), span=(1,1), flag=wx.ALIGN_RIGHT|wx.EXPAND)
107 sizer.AddGrowableCol(0)
108 sizer.AddGrowableRow(0)
67 self.SetSizer(sizer) 109 self.SetSizer(sizer)
110 #self.Layout()
68 self.SetAutoLayout(True) 111 self.SetAutoLayout(True)
69 self.SetSize((300, 175)) 112 self.SetSize((450, 275))
113 self.SetMinSize((450, 275))
70 self.Bind(wx.EVT_CLOSE, self.Min) 114 self.Bind(wx.EVT_CLOSE, self.Min)
115 self.Bind(wx.EVT_BUTTON, self.clear, self.bt_clear)
116 self.Bind(wx.EVT_BUTTON, self.bug_report, self.report)
71 self.Min(None) 117 self.Min(None)
118 #sys.stdout = Term2Win()
72 component.add('debugger', self.console) 119 component.add('debugger', self.console)
73 120
74 def Min(self, evt): 121 def Min(self, evt):
75 self.Hide() 122 self.Hide()
123
124 def clear(self, evt):
125 self.console.SetValue('')
126
127 def bug_report(self, evt):
128 self.parent.OnMB_HelpReportaBug()
76 129
77 class orpgLog(object): 130 class orpgLog(object):
78 _log_level = 7 131 _log_level = 7
79 _log_name = None 132 _log_name = None
80 _log_to_console = False 133 _log_to_console = False
97 'log_string': 'INFO'}, 150 'log_string': 'INFO'},
98 2: {'colorizer': {'red': True}, 151 2: {'colorizer': {'red': True},
99 'log_string': 'ERROR'}, 152 'log_string': 'ERROR'},
100 1: {'colorizer': {'bold': True, 'red': True}, 153 1: {'colorizer': {'bold': True, 'red': True},
101 'log_string': 'EXCEPTION'}} 154 'log_string': 'EXCEPTION'}}
155
102 if not self.log_name: 156 if not self.log_name:
103 self.log_name = home_dir + filename + time.strftime('%m-%d-%Y.txt', 157 self.log_name = home_dir + filename + time.strftime('%m-%d-%Y.txt',
104 time.localtime(time.time())) 158 time.localtime(time.time()))
105 159
106 def debug(self, msg, to_console=False): 160 def debug(self, msg, to_console=False):
113 self.log(msg, ORPG_INFO, to_console) 167 self.log(msg, ORPG_INFO, to_console)
114 168
115 def general(self, msg, to_console=False): 169 def general(self, msg, to_console=False):
116 self.log(msg, ORPG_GENERAL, to_console) 170 self.log(msg, ORPG_GENERAL, to_console)
117 171
172 def stdout(self, msg, to_console=True):
173 self.log(msg, ORPG_INFO, to_console)
174
118 def exception(self, msg, to_console=True): 175 def exception(self, msg, to_console=True):
119 ### Beta ### Every 'Critical' exception will draw attention to the Debug Console
120 component.get('frame').TraipseSuiteWarn('debug') 176 component.get('frame').TraipseSuiteWarn('debug')
121 self.log(msg, ORPG_CRITICAL, to_console) 177 self.log(msg, ORPG_CRITICAL, to_console)
122 178
123 def log(self, msg, log_type, to_console=False): 179 def log(self, msg, log_type, to_console=False):
124 if self.log_to_console or to_console or log_type == ORPG_CRITICAL: 180 if self.log_to_console or to_console or log_type == ORPG_CRITICAL:
125 try: self._io.line(str(msg), **self._lvl_args[log_type]['colorizer']) 181 try: self._io.line(str(msg), **self._lvl_args[log_type]['colorizer'])
126 except: pass #Fails without the Debug Console 182 except: pass #Fails without the Debug Console
127 try: component.get('debugger').AppendText(".. " + str(msg) +'\n') 183 try: component.get('debugger').AppendText(".. " + str(msg) +'\n')
128 except: pass 184 except: pass
129 185
130 if log_type & self.log_level or to_console: 186 if log_type and (self.log_level or to_console):
131 atr = {'msg': msg, 'level': self._lvl_args[log_type]['log_string']} 187 atr = {'msg': msg, 'level': self._lvl_args[log_type]['log_string']}
132 atr['time'] = time.strftime('[%x %X]', time.localtime(time.time())) 188 atr['time'] = time.strftime('[%x %X]', time.localtime(time.time()))
133 logMsg = '%(time)s (%(level)s) - %(msg)s\n' % (atr) 189 logMsg = '%(time)s (%(level)s) - %(msg)s\n' % (atr)
134 190
135 with open(self.log_name, 'a') as f: 191 with open(self.log_name, 'a') as f:
190 log_name = property(_get_log_name, _set_log_name) 246 log_name = property(_get_log_name, _set_log_name)
191 log_to_console = property(_get_log_to_console, _set_log_to_console) 247 log_to_console = property(_get_log_to_console, _set_log_to_console)
192 248
193 logger = orpgLog(dir_struct.get("user") + "runlogs/") 249 logger = orpgLog(dir_struct.get("user") + "runlogs/")
194 crash = sys.excepthook = Crash 250 crash = sys.excepthook = Crash
251 debug = TrueDebug