annotate 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
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
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
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
97265586402b Traipse 'OpenRPG' {090827-00}
sirebral
parents: 10
diff changeset
29 from __future__ import with_statement
28
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
30 import sys, os, os.path, time, traceback, inspect, wx
18
97265586402b Traipse 'OpenRPG' {090827-00}
sirebral
parents: 10
diff changeset
31
97265586402b Traipse 'OpenRPG' {090827-00}
sirebral
parents: 10
diff changeset
32 from orpg.orpgCore import component
97265586402b Traipse 'OpenRPG' {090827-00}
sirebral
parents: 10
diff changeset
33 from orpg.external.terminalwriter import TerminalWriter
97265586402b Traipse 'OpenRPG' {090827-00}
sirebral
parents: 10
diff changeset
34 from orpg.tools.decorators import pending_deprecation
97265586402b Traipse 'OpenRPG' {090827-00}
sirebral
parents: 10
diff changeset
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
97265586402b Traipse 'OpenRPG' {090827-00}
sirebral
parents: 10
diff changeset
37 #########################
97265586402b Traipse 'OpenRPG' {090827-00}
sirebral
parents: 10
diff changeset
38 ## Error Types
97265586402b Traipse 'OpenRPG' {090827-00}
sirebral
parents: 10
diff changeset
39 #########################
28
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
40 ORPG_PRINT = 0
18
97265586402b Traipse 'OpenRPG' {090827-00}
sirebral
parents: 10
diff changeset
41 ORPG_CRITICAL = 1
97265586402b Traipse 'OpenRPG' {090827-00}
sirebral
parents: 10
diff changeset
42 ORPG_GENERAL = 2
97265586402b Traipse 'OpenRPG' {090827-00}
sirebral
parents: 10
diff changeset
43 ORPG_INFO = 4
97265586402b Traipse 'OpenRPG' {090827-00}
sirebral
parents: 10
diff changeset
44 ORPG_NOTE = 8
97265586402b Traipse 'OpenRPG' {090827-00}
sirebral
parents: 10
diff changeset
45 ORPG_DEBUG = 16
97265586402b Traipse 'OpenRPG' {090827-00}
sirebral
parents: 10
diff changeset
46
28
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
47
18
97265586402b Traipse 'OpenRPG' {090827-00}
sirebral
parents: 10
diff changeset
48 def Crash(type, value, crash):
97265586402b Traipse 'OpenRPG' {090827-00}
sirebral
parents: 10
diff changeset
49 crash_report = open(dir_struct["home"] + 'crash-report.txt', "w")
97265586402b Traipse 'OpenRPG' {090827-00}
sirebral
parents: 10
diff changeset
50 traceback.print_exception(type, value, crash, file=crash_report)
97265586402b Traipse 'OpenRPG' {090827-00}
sirebral
parents: 10
diff changeset
51 crash_report.close()
97265586402b Traipse 'OpenRPG' {090827-00}
sirebral
parents: 10
diff changeset
52 msg = ''
97265586402b Traipse 'OpenRPG' {090827-00}
sirebral
parents: 10
diff changeset
53 crash_report = open(dir_struct["home"] + 'crash-report.txt', "r")
97265586402b Traipse 'OpenRPG' {090827-00}
sirebral
parents: 10
diff changeset
54 for line in crash_report: msg += line
97265586402b Traipse 'OpenRPG' {090827-00}
sirebral
parents: 10
diff changeset
55 logger.exception(msg)
97265586402b Traipse 'OpenRPG' {090827-00}
sirebral
parents: 10
diff changeset
56 crash_report.close()
97265586402b Traipse 'OpenRPG' {090827-00}
sirebral
parents: 10
diff changeset
57 logger.exception("Crash Report Created!!")
97265586402b Traipse 'OpenRPG' {090827-00}
sirebral
parents: 10
diff changeset
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
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
60 class Term2Win(object):
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
61 # A stdout redirector. To be implemented later.
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
62 def write(self, text):
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
63 logger.stdout(text)
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
64 wx.Yield()
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
65 #sys.__stdout__.write(text)
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
66
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
67 class TrueDebug(object):
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
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.
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
69 Adding True to locale prints the file name where the function is. Adding False to log turns the log off.
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
70 Adding True to parents will print out the parent functions, starting from TrueDebug.
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
71 This feature can be modified to trace deeper and find the bugs faster, ending the puzzle box."""
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
72 def __init__(self, objects=None, locale=False, log=True, parents=False):
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
73 if log == False: return
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
74 current = inspect.currentframe()
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
75 if parents: self.get_parents(current)
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
76 else: self.true_debug(current, objects, locale)
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
77
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
78 def true_debug(self, current, objects, locale):
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
79 debug_string = 'Function: ' + str(inspect.getouterframes(current)[1][3])
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
80 #if locale == 'all': print inspect.getouterframes(current)[4]; return
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
81 if objects != None: debug_string += ' Objects: ' + str(objects)
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
82 if locale: debug_string += ' File: ' + str(inspect.getouterframes(current)[1][1])
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
83 logger.debug(debug_string, True)
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
84 return
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
85
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
86 def get_parents(self, current):
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
87 debug_string = 'Function: ' + str(inspect.getouterframes(current)[1][3]) + ' Parents:'
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
88 family = list(inspect.getouterframes(current))
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
89 for parent in family:
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
90 debug_string += ' ' + str(parent[4])
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
91 logger.debug(debug_string, True)
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
92 return
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
93
18
97265586402b Traipse 'OpenRPG' {090827-00}
sirebral
parents: 10
diff changeset
94 class DebugConsole(wx.Frame):
97265586402b Traipse 'OpenRPG' {090827-00}
sirebral
parents: 10
diff changeset
95 def __init__(self, parent):
27
51428d30c59e Traipse 'OpenRPG' {091003-00}
sirebral
parents: 18
diff changeset
96 super(DebugConsole, self).__init__(parent, -1, "Debug Console")
18
97265586402b Traipse 'OpenRPG' {090827-00}
sirebral
parents: 10
diff changeset
97 icon = wx.Icon(dir_struct["icon"]+'note.ico', wx.BITMAP_TYPE_ICO)
28
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
98 self.parent = parent
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
99 self.SetIcon(icon)
18
97265586402b Traipse 'OpenRPG' {090827-00}
sirebral
parents: 10
diff changeset
100 self.console = wx.TextCtrl(self, -1, style=wx.TE_MULTILINE | wx.TE_READONLY)
28
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
101 self.bt_clear = wx.Button(self, wx.ID_CLEAR)
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
102 self.report = wx.Button(self, wx.ID_ANY, 'Bug Report')
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
103 sizer = wx.GridBagSizer(hgap=1, vgap=1)
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
104 sizer.Add(self.console, (0,0), span=(1,2), flag=wx.EXPAND)
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
105 sizer.Add(self.bt_clear, (1,0), span=(1,1), flag=wx.ALIGN_LEFT)
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
106 sizer.Add(self.report, (1,1), span=(1,1), flag=wx.ALIGN_RIGHT|wx.EXPAND)
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
107 sizer.AddGrowableCol(0)
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
108 sizer.AddGrowableRow(0)
18
97265586402b Traipse 'OpenRPG' {090827-00}
sirebral
parents: 10
diff changeset
109 self.SetSizer(sizer)
28
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
110 #self.Layout()
18
97265586402b Traipse 'OpenRPG' {090827-00}
sirebral
parents: 10
diff changeset
111 self.SetAutoLayout(True)
28
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
112 self.SetSize((450, 275))
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
113 self.SetMinSize((450, 275))
18
97265586402b Traipse 'OpenRPG' {090827-00}
sirebral
parents: 10
diff changeset
114 self.Bind(wx.EVT_CLOSE, self.Min)
28
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
115 self.Bind(wx.EVT_BUTTON, self.clear, self.bt_clear)
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
116 self.Bind(wx.EVT_BUTTON, self.bug_report, self.report)
18
97265586402b Traipse 'OpenRPG' {090827-00}
sirebral
parents: 10
diff changeset
117 self.Min(None)
28
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
118 #sys.stdout = Term2Win()
18
97265586402b Traipse 'OpenRPG' {090827-00}
sirebral
parents: 10
diff changeset
119 component.add('debugger', self.console)
97265586402b Traipse 'OpenRPG' {090827-00}
sirebral
parents: 10
diff changeset
120
97265586402b Traipse 'OpenRPG' {090827-00}
sirebral
parents: 10
diff changeset
121 def Min(self, evt):
97265586402b Traipse 'OpenRPG' {090827-00}
sirebral
parents: 10
diff changeset
122 self.Hide()
0
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
123
28
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
124 def clear(self, evt):
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
125 self.console.SetValue('')
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
126
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
127 def bug_report(self, evt):
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
128 self.parent.OnMB_HelpReportaBug()
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
129
18
97265586402b Traipse 'OpenRPG' {090827-00}
sirebral
parents: 10
diff changeset
130 class orpgLog(object):
97265586402b Traipse 'OpenRPG' {090827-00}
sirebral
parents: 10
diff changeset
131 _log_level = 7
97265586402b Traipse 'OpenRPG' {090827-00}
sirebral
parents: 10
diff changeset
132 _log_name = None
97265586402b Traipse 'OpenRPG' {090827-00}
sirebral
parents: 10
diff changeset
133 _log_to_console = False
97265586402b Traipse 'OpenRPG' {090827-00}
sirebral
parents: 10
diff changeset
134 _io = TerminalWriter(sys.stderr)
97265586402b Traipse 'OpenRPG' {090827-00}
sirebral
parents: 10
diff changeset
135 _lvl_args = None
97265586402b Traipse 'OpenRPG' {090827-00}
sirebral
parents: 10
diff changeset
136
97265586402b Traipse 'OpenRPG' {090827-00}
sirebral
parents: 10
diff changeset
137 def __new__(cls, *args, **kwargs):
97265586402b Traipse 'OpenRPG' {090827-00}
sirebral
parents: 10
diff changeset
138 it = cls.__dict__.get("__it__")
97265586402b Traipse 'OpenRPG' {090827-00}
sirebral
parents: 10
diff changeset
139 if it is not None:
97265586402b Traipse 'OpenRPG' {090827-00}
sirebral
parents: 10
diff changeset
140 return it
97265586402b Traipse 'OpenRPG' {090827-00}
sirebral
parents: 10
diff changeset
141 cls.__it__ = it = object.__new__(cls)
97265586402b Traipse 'OpenRPG' {090827-00}
sirebral
parents: 10
diff changeset
142 return it
97265586402b Traipse 'OpenRPG' {090827-00}
sirebral
parents: 10
diff changeset
143
97265586402b Traipse 'OpenRPG' {090827-00}
sirebral
parents: 10
diff changeset
144 def __init__(self, home_dir, filename='orpgRunLog '):
97265586402b Traipse 'OpenRPG' {090827-00}
sirebral
parents: 10
diff changeset
145 self._lvl_args = {16: {'colorizer': {'green': True},
97265586402b Traipse 'OpenRPG' {090827-00}
sirebral
parents: 10
diff changeset
146 'log_string': 'DEBUG'},
97265586402b Traipse 'OpenRPG' {090827-00}
sirebral
parents: 10
diff changeset
147 8: {'colorizer': {'bold': True, 'green':True},
97265586402b Traipse 'OpenRPG' {090827-00}
sirebral
parents: 10
diff changeset
148 'log_string':'NOTE'},
97265586402b Traipse 'OpenRPG' {090827-00}
sirebral
parents: 10
diff changeset
149 4: {'colorizer': {'blue': True},
97265586402b Traipse 'OpenRPG' {090827-00}
sirebral
parents: 10
diff changeset
150 'log_string': 'INFO'},
97265586402b Traipse 'OpenRPG' {090827-00}
sirebral
parents: 10
diff changeset
151 2: {'colorizer': {'red': True},
97265586402b Traipse 'OpenRPG' {090827-00}
sirebral
parents: 10
diff changeset
152 'log_string': 'ERROR'},
97265586402b Traipse 'OpenRPG' {090827-00}
sirebral
parents: 10
diff changeset
153 1: {'colorizer': {'bold': True, 'red': True},
97265586402b Traipse 'OpenRPG' {090827-00}
sirebral
parents: 10
diff changeset
154 'log_string': 'EXCEPTION'}}
28
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
155
18
97265586402b Traipse 'OpenRPG' {090827-00}
sirebral
parents: 10
diff changeset
156 if not self.log_name:
97265586402b Traipse 'OpenRPG' {090827-00}
sirebral
parents: 10
diff changeset
157 self.log_name = home_dir + filename + time.strftime('%m-%d-%Y.txt',
97265586402b Traipse 'OpenRPG' {090827-00}
sirebral
parents: 10
diff changeset
158 time.localtime(time.time()))
97265586402b Traipse 'OpenRPG' {090827-00}
sirebral
parents: 10
diff changeset
159
97265586402b Traipse 'OpenRPG' {090827-00}
sirebral
parents: 10
diff changeset
160 def debug(self, msg, to_console=False):
97265586402b Traipse 'OpenRPG' {090827-00}
sirebral
parents: 10
diff changeset
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
97265586402b Traipse 'OpenRPG' {090827-00}
sirebral
parents: 10
diff changeset
163 def note(self, msg, to_console=False):
97265586402b Traipse 'OpenRPG' {090827-00}
sirebral
parents: 10
diff changeset
164 self.log(msg, ORPG_NOTE, to_console)
97265586402b Traipse 'OpenRPG' {090827-00}
sirebral
parents: 10
diff changeset
165
97265586402b Traipse 'OpenRPG' {090827-00}
sirebral
parents: 10
diff changeset
166 def info(self, msg, to_console=False):
97265586402b Traipse 'OpenRPG' {090827-00}
sirebral
parents: 10
diff changeset
167 self.log(msg, ORPG_INFO, to_console)
97265586402b Traipse 'OpenRPG' {090827-00}
sirebral
parents: 10
diff changeset
168
97265586402b Traipse 'OpenRPG' {090827-00}
sirebral
parents: 10
diff changeset
169 def general(self, msg, to_console=False):
97265586402b Traipse 'OpenRPG' {090827-00}
sirebral
parents: 10
diff changeset
170 self.log(msg, ORPG_GENERAL, to_console)
97265586402b Traipse 'OpenRPG' {090827-00}
sirebral
parents: 10
diff changeset
171
28
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
172 def stdout(self, msg, to_console=True):
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
173 self.log(msg, ORPG_INFO, to_console)
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
174
18
97265586402b Traipse 'OpenRPG' {090827-00}
sirebral
parents: 10
diff changeset
175 def exception(self, msg, to_console=True):
27
51428d30c59e Traipse 'OpenRPG' {091003-00}
sirebral
parents: 18
diff changeset
176 component.get('frame').TraipseSuiteWarn('debug')
18
97265586402b Traipse 'OpenRPG' {090827-00}
sirebral
parents: 10
diff changeset
177 self.log(msg, ORPG_CRITICAL, to_console)
97265586402b Traipse 'OpenRPG' {090827-00}
sirebral
parents: 10
diff changeset
178
97265586402b Traipse 'OpenRPG' {090827-00}
sirebral
parents: 10
diff changeset
179 def log(self, msg, log_type, to_console=False):
97265586402b Traipse 'OpenRPG' {090827-00}
sirebral
parents: 10
diff changeset
180 if self.log_to_console or to_console or log_type == ORPG_CRITICAL:
97265586402b Traipse 'OpenRPG' {090827-00}
sirebral
parents: 10
diff changeset
181 try: self._io.line(str(msg), **self._lvl_args[log_type]['colorizer'])
97265586402b Traipse 'OpenRPG' {090827-00}
sirebral
parents: 10
diff changeset
182 except: pass #Fails without the Debug Console
97265586402b Traipse 'OpenRPG' {090827-00}
sirebral
parents: 10
diff changeset
183 try: component.get('debugger').AppendText(".. " + str(msg) +'\n')
97265586402b Traipse 'OpenRPG' {090827-00}
sirebral
parents: 10
diff changeset
184 except: pass
97265586402b Traipse 'OpenRPG' {090827-00}
sirebral
parents: 10
diff changeset
185
28
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
186 if log_type and (self.log_level or to_console):
18
97265586402b Traipse 'OpenRPG' {090827-00}
sirebral
parents: 10
diff changeset
187 atr = {'msg': msg, 'level': self._lvl_args[log_type]['log_string']}
97265586402b Traipse 'OpenRPG' {090827-00}
sirebral
parents: 10
diff changeset
188 atr['time'] = time.strftime('[%x %X]', time.localtime(time.time()))
97265586402b Traipse 'OpenRPG' {090827-00}
sirebral
parents: 10
diff changeset
189 logMsg = '%(time)s (%(level)s) - %(msg)s\n' % (atr)
97265586402b Traipse 'OpenRPG' {090827-00}
sirebral
parents: 10
diff changeset
190
97265586402b Traipse 'OpenRPG' {090827-00}
sirebral
parents: 10
diff changeset
191 with open(self.log_name, 'a') as f:
97265586402b Traipse 'OpenRPG' {090827-00}
sirebral
parents: 10
diff changeset
192 f.write(logMsg)
97265586402b Traipse 'OpenRPG' {090827-00}
sirebral
parents: 10
diff changeset
193
97265586402b Traipse 'OpenRPG' {090827-00}
sirebral
parents: 10
diff changeset
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
97265586402b Traipse 'OpenRPG' {090827-00}
sirebral
parents: 10
diff changeset
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
97265586402b Traipse 'OpenRPG' {090827-00}
sirebral
parents: 10
diff changeset
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
97265586402b Traipse 'OpenRPG' {090827-00}
sirebral
parents: 10
diff changeset
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
97265586402b Traipse 'OpenRPG' {090827-00}
sirebral
parents: 10
diff changeset
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
97265586402b Traipse 'OpenRPG' {090827-00}
sirebral
parents: 10
diff changeset
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
97265586402b Traipse 'OpenRPG' {090827-00}
sirebral
parents: 10
diff changeset
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
97265586402b Traipse 'OpenRPG' {090827-00}
sirebral
parents: 10
diff changeset
208 return self.log_name
97265586402b Traipse 'OpenRPG' {090827-00}
sirebral
parents: 10
diff changeset
209
97265586402b Traipse 'OpenRPG' {090827-00}
sirebral
parents: 10
diff changeset
210 @pending_deprecation("use logger.log_to_console = True/False")
97265586402b Traipse 'OpenRPG' {090827-00}
sirebral
parents: 10
diff changeset
211 def setLogToConsol(self, true_or_false):
97265586402b Traipse 'OpenRPG' {090827-00}
sirebral
parents: 10
diff changeset
212 self.log_to_consol = true_or_false
97265586402b Traipse 'OpenRPG' {090827-00}
sirebral
parents: 10
diff changeset
213
97265586402b Traipse 'OpenRPG' {090827-00}
sirebral
parents: 10
diff changeset
214 @pending_deprecation("use logger.log_to_console")
97265586402b Traipse 'OpenRPG' {090827-00}
sirebral
parents: 10
diff changeset
215 def getLogToConsol(self):
97265586402b Traipse 'OpenRPG' {090827-00}
sirebral
parents: 10
diff changeset
216 return self.log_to_consol
97265586402b Traipse 'OpenRPG' {090827-00}
sirebral
parents: 10
diff changeset
217
97265586402b Traipse 'OpenRPG' {090827-00}
sirebral
parents: 10
diff changeset
218 """
97265586402b Traipse 'OpenRPG' {090827-00}
sirebral
parents: 10
diff changeset
219 Property Methods
97265586402b Traipse 'OpenRPG' {090827-00}
sirebral
parents: 10
diff changeset
220 """
97265586402b Traipse 'OpenRPG' {090827-00}
sirebral
parents: 10
diff changeset
221 def _get_log_level(self):
97265586402b Traipse 'OpenRPG' {090827-00}
sirebral
parents: 10
diff changeset
222 return self._log_level
97265586402b Traipse 'OpenRPG' {090827-00}
sirebral
parents: 10
diff changeset
223 def _set_log_level(self, log_level):
97265586402b Traipse 'OpenRPG' {090827-00}
sirebral
parents: 10
diff changeset
224 if not isinstance(log_level, int) or log_level < 1 or log_level > 31:
97265586402b Traipse 'OpenRPG' {090827-00}
sirebral
parents: 10
diff changeset
225 raise TypeError("The loggers level must be an int between 1 and 31")
97265586402b Traipse 'OpenRPG' {090827-00}
sirebral
parents: 10
diff changeset
226
97265586402b Traipse 'OpenRPG' {090827-00}
sirebral
parents: 10
diff changeset
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
97265586402b Traipse 'OpenRPG' {090827-00}
sirebral
parents: 10
diff changeset
229 def _get_log_name(self):
97265586402b Traipse 'OpenRPG' {090827-00}
sirebral
parents: 10
diff changeset
230 return self._log_name
97265586402b Traipse 'OpenRPG' {090827-00}
sirebral
parents: 10
diff changeset
231 def _set_log_name(self, name):
97265586402b Traipse 'OpenRPG' {090827-00}
sirebral
parents: 10
diff changeset
232 if not os.access(os.path.abspath(os.path.dirname(name)), os.W_OK):
97265586402b Traipse 'OpenRPG' {090827-00}
sirebral
parents: 10
diff changeset
233 raise IOError("Could not write to the specified location")
97265586402b Traipse 'OpenRPG' {090827-00}
sirebral
parents: 10
diff changeset
234
97265586402b Traipse 'OpenRPG' {090827-00}
sirebral
parents: 10
diff changeset
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
97265586402b Traipse 'OpenRPG' {090827-00}
sirebral
parents: 10
diff changeset
237 def _get_log_to_console(self):
97265586402b Traipse 'OpenRPG' {090827-00}
sirebral
parents: 10
diff changeset
238 return self._log_to_console
97265586402b Traipse 'OpenRPG' {090827-00}
sirebral
parents: 10
diff changeset
239 def _set_log_to_console(self, true_or_false):
97265586402b Traipse 'OpenRPG' {090827-00}
sirebral
parents: 10
diff changeset
240 if not isinstance(true_or_false, bool):
97265586402b Traipse 'OpenRPG' {090827-00}
sirebral
parents: 10
diff changeset
241 raise TypeError("log_to_console must be a boolean value")
97265586402b Traipse 'OpenRPG' {090827-00}
sirebral
parents: 10
diff changeset
242
97265586402b Traipse 'OpenRPG' {090827-00}
sirebral
parents: 10
diff changeset
243 self._log_to_console = true_or_false
97265586402b Traipse 'OpenRPG' {090827-00}
sirebral
parents: 10
diff changeset
244
97265586402b Traipse 'OpenRPG' {090827-00}
sirebral
parents: 10
diff changeset
245 log_level = property(_get_log_level, _set_log_level)
97265586402b Traipse 'OpenRPG' {090827-00}
sirebral
parents: 10
diff changeset
246 log_name = property(_get_log_name, _set_log_name)
97265586402b Traipse 'OpenRPG' {090827-00}
sirebral
parents: 10
diff changeset
247 log_to_console = property(_get_log_to_console, _set_log_to_console)
97265586402b Traipse 'OpenRPG' {090827-00}
sirebral
parents: 10
diff changeset
248
97265586402b Traipse 'OpenRPG' {090827-00}
sirebral
parents: 10
diff changeset
249 logger = orpgLog(dir_struct.get("user") + "runlogs/")
97265586402b Traipse 'OpenRPG' {090827-00}
sirebral
parents: 10
diff changeset
250 crash = sys.excepthook = Crash
28
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 27
diff changeset
251 debug = TrueDebug