Mercurial > traipse
annotate orpg/tools/orpg_log.py @ 39:ed322725b928 ornery-orc tip
Traipse 'OpenRPG' {110114-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 (Closed)
New Features:
New to Map, can re-order Grid, Miniatures, and Whiteboard layer draw order
New to Server GUI, can now clear log
New Earthdawn Dieroller
New IronClaw roller, sheet, and image
New ShapeShifter PC Sheet
Updates:
Update to Warhammer PC Sheet. Rollers set as macros. Should work with little maintanence.
Update to Browser Server window. Display rooms with ' " & cleaner
Update to Server. Handles ' " & cleaner
Update to Dieroller. Cleaner, more effecient expression system
Update to Hidden Die plugin, allows for non standard dice rolls
Update to location.py, allows for more portable references when starting Traipse
Update to the Features node
Fixes:
Fix to InterParse that was causing an Infernal Loop with Namespace Internal
Fix to XML data, removed old Minidom and switched to Element Tree
Fix to Server that was causing eternal attempt to find a Server ID, in Register Rooms thread
Fix to Server, removing wxPython dependencies where not needed
Fix to metaservers.xml file not being created
Fix to Single and Double quotes in Whiteboard text
Fix to Background images not showing when using the Image Server
Fix to Duplicate chat names appearing
Fix to Server GUI's logging output
Fix to FNB.COLORFUL_TABS bug
Fix to Gametree for XSLT Sheets
Fix to Gametree for locating gametree files
Fix to Send to Chat from Gametree
Fix to Gametree, renaming and remapping operates correctly
Fix to aliaslib, prevents error caused when SafeHTML is sent None
author | sirebral |
---|---|
date | Fri, 14 Jan 2011 05:24:52 -0600 |
parents | fc48380f0c9f |
children |
rev | line source |
---|---|
0
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
1 # Copyright (C) 2000-2001 The OpenRPG Project |
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
2 # |
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
3 # openrpg-dev@lists.sourceforge.net |
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
4 # |
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
5 # This program is free software; you can redistribute it and/or modify |
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
6 # it under the terms of the GNU General Public License as published by |
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
7 # the Free Software Foundation; either version 2 of the License, or |
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
8 # (at your option) any later version. |
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
9 # |
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
10 # This program is distributed in the hope that it will be useful, |
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of |
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
13 # GNU General Public License for more details. |
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
14 # |
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
15 # You should have received a copy of the GNU General Public License |
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
16 # along with this program; if not, write to the Free Software |
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
17 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
18 # -- |
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
19 # |
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
20 # File: orpg_log.py |
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
21 # Author: Dj Gilcrease |
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
22 # Maintainer: |
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
23 # Version: |
28 | 24 # $Id: orpg_log.py,v Traipse 'Ornery-Orc' prof.ebral Exp $ |
0
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
25 # |
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
26 # Description: classes for orpg log messages |
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
27 # |
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
28 |
18 | 29 from __future__ import with_statement |
28 | 30 import sys, os, os.path, time, traceback, inspect, wx |
18 | 31 |
32 from orpg.orpgCore import component | |
33 from orpg.external.terminalwriter import TerminalWriter | |
34 from orpg.tools.decorators import pending_deprecation | |
35 from orpg.dirpath import dir_struct | |
0
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
36 |
18 | 37 ######################### |
38 ## Error Types | |
39 ######################### | |
28 | 40 ORPG_PRINT = 0 |
18 | 41 ORPG_CRITICAL = 1 |
42 ORPG_GENERAL = 2 | |
43 ORPG_INFO = 4 | |
44 ORPG_NOTE = 8 | |
45 ORPG_DEBUG = 16 | |
46 | |
28 | 47 |
18 | 48 def Crash(type, value, crash): |
49 crash_report = open(dir_struct["home"] + 'crash-report.txt', "w") | |
50 traceback.print_exception(type, value, crash, file=crash_report) | |
51 crash_report.close() | |
52 msg = '' | |
53 crash_report = open(dir_struct["home"] + 'crash-report.txt', "r") | |
54 for line in crash_report: msg += line | |
55 logger.exception(msg) | |
56 crash_report.close() | |
57 logger.exception("Crash Report Created!!") | |
58 logger.info("Printed out crash-report.txt in your System folder", True) | |
0
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
59 |
28 | 60 class Term2Win(object): |
61 # A stdout redirector. To be implemented later. | |
62 def write(self, text): | |
63 logger.stdout(text) | |
64 wx.Yield() | |
31 | 65 sys.__stdout__.write(text) |
28 | 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 | |
18 | 94 class DebugConsole(wx.Frame): |
95 def __init__(self, parent): | |
27 | 96 super(DebugConsole, self).__init__(parent, -1, "Debug Console") |
18 | 97 icon = wx.Icon(dir_struct["icon"]+'note.ico', wx.BITMAP_TYPE_ICO) |
28 | 98 self.parent = parent |
99 self.SetIcon(icon) | |
18 | 100 self.console = wx.TextCtrl(self, -1, style=wx.TE_MULTILINE | wx.TE_READONLY) |
28 | 101 self.bt_clear = wx.Button(self, wx.ID_CLEAR) |
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) | |
18 | 109 self.SetSizer(sizer) |
28 | 110 #self.Layout() |
18 | 111 self.SetAutoLayout(True) |
28 | 112 self.SetSize((450, 275)) |
113 self.SetMinSize((450, 275)) | |
18 | 114 self.Bind(wx.EVT_CLOSE, self.Min) |
28 | 115 self.Bind(wx.EVT_BUTTON, self.clear, self.bt_clear) |
116 self.Bind(wx.EVT_BUTTON, self.bug_report, self.report) | |
18 | 117 self.Min(None) |
28 | 118 #sys.stdout = Term2Win() |
18 | 119 component.add('debugger', self.console) |
120 | |
121 def Min(self, evt): | |
122 self.Hide() | |
0
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
123 |
28 | 124 def clear(self, evt): |
125 self.console.SetValue('') | |
126 | |
127 def bug_report(self, evt): | |
128 self.parent.OnMB_HelpReportaBug() | |
129 | |
18 | 130 class orpgLog(object): |
131 _log_level = 7 | |
132 _log_name = None | |
133 _log_to_console = False | |
134 _io = TerminalWriter(sys.stderr) | |
135 _lvl_args = None | |
136 | |
137 def __new__(cls, *args, **kwargs): | |
138 it = cls.__dict__.get("__it__") | |
139 if it is not None: | |
140 return it | |
141 cls.__it__ = it = object.__new__(cls) | |
142 return it | |
143 | |
144 def __init__(self, home_dir, filename='orpgRunLog '): | |
145 self._lvl_args = {16: {'colorizer': {'green': True}, | |
146 'log_string': 'DEBUG'}, | |
147 8: {'colorizer': {'bold': True, 'green':True}, | |
148 'log_string':'NOTE'}, | |
149 4: {'colorizer': {'blue': True}, | |
150 'log_string': 'INFO'}, | |
151 2: {'colorizer': {'red': True}, | |
152 'log_string': 'ERROR'}, | |
153 1: {'colorizer': {'bold': True, 'red': True}, | |
154 'log_string': 'EXCEPTION'}} | |
28 | 155 |
18 | 156 if not self.log_name: |
157 self.log_name = home_dir + filename + time.strftime('%m-%d-%Y.txt', | |
158 time.localtime(time.time())) | |
159 | |
160 def debug(self, msg, to_console=False): | |
161 self.log(msg, ORPG_DEBUG, to_console) | |
0
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
162 |
18 | 163 def note(self, msg, to_console=False): |
164 self.log(msg, ORPG_NOTE, to_console) | |
165 | |
166 def info(self, msg, to_console=False): | |
167 self.log(msg, ORPG_INFO, to_console) | |
168 | |
169 def general(self, msg, to_console=False): | |
170 self.log(msg, ORPG_GENERAL, to_console) | |
171 | |
28 | 172 def stdout(self, msg, to_console=True): |
173 self.log(msg, ORPG_INFO, to_console) | |
174 | |
18 | 175 def exception(self, msg, to_console=True): |
27 | 176 component.get('frame').TraipseSuiteWarn('debug') |
18 | 177 self.log(msg, ORPG_CRITICAL, to_console) |
178 | |
179 def log(self, msg, log_type, to_console=False): | |
180 if self.log_to_console or to_console or log_type == ORPG_CRITICAL: | |
181 try: self._io.line(str(msg), **self._lvl_args[log_type]['colorizer']) | |
182 except: pass #Fails without the Debug Console | |
183 try: component.get('debugger').AppendText(".. " + str(msg) +'\n') | |
184 except: pass | |
185 | |
28 | 186 if log_type and (self.log_level or to_console): |
18 | 187 atr = {'msg': msg, 'level': self._lvl_args[log_type]['log_string']} |
188 atr['time'] = time.strftime('[%x %X]', time.localtime(time.time())) | |
189 logMsg = '%(time)s (%(level)s) - %(msg)s\n' % (atr) | |
190 | |
191 with open(self.log_name, 'a') as f: | |
192 f.write(logMsg) | |
193 | |
194 @pending_deprecation("use logger.log_level = #") | |
0
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
195 def setLogLevel(self, log_level): |
18 | 196 self.log_level = log_level |
0
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
197 |
18 | 198 @pending_deprecation("use logger.log_level") |
0
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
199 def getLogLevel(self): |
18 | 200 return self.log_level |
0
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
201 |
18 | 202 @pending_deprecation("use logger.log_name = bla") |
0
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
203 def setLogName(self, log_name): |
18 | 204 self.log_name = log_name |
0
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
205 |
18 | 206 @pending_deprecation("use logger.log_name") |
0
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
207 def getLogName(self): |
18 | 208 return self.log_name |
209 | |
210 @pending_deprecation("use logger.log_to_console = True/False") | |
211 def setLogToConsol(self, true_or_false): | |
212 self.log_to_consol = true_or_false | |
213 | |
214 @pending_deprecation("use logger.log_to_console") | |
215 def getLogToConsol(self): | |
216 return self.log_to_consol | |
217 | |
218 """ | |
219 Property Methods | |
220 """ | |
221 def _get_log_level(self): | |
222 return self._log_level | |
223 def _set_log_level(self, log_level): | |
224 if not isinstance(log_level, int) or log_level < 1 or log_level > 31: | |
225 raise TypeError("The loggers level must be an int between 1 and 31") | |
226 | |
227 self._log_level = log_level | |
0
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
228 |
18 | 229 def _get_log_name(self): |
230 return self._log_name | |
231 def _set_log_name(self, name): | |
232 if not os.access(os.path.abspath(os.path.dirname(name)), os.W_OK): | |
233 raise IOError("Could not write to the specified location") | |
234 | |
235 self._log_name = name | |
0
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
236 |
18 | 237 def _get_log_to_console(self): |
238 return self._log_to_console | |
239 def _set_log_to_console(self, true_or_false): | |
240 if not isinstance(true_or_false, bool): | |
241 raise TypeError("log_to_console must be a boolean value") | |
242 | |
243 self._log_to_console = true_or_false | |
244 | |
245 log_level = property(_get_log_level, _set_log_level) | |
246 log_name = property(_get_log_name, _set_log_name) | |
247 log_to_console = property(_get_log_to_console, _set_log_to_console) | |
248 | |
249 logger = orpgLog(dir_struct.get("user") + "runlogs/") | |
250 crash = sys.excepthook = Crash | |
28 | 251 debug = TrueDebug |