source: tags/0.2/console.py @ 335

Revision 173, 3.9 KB checked in by marc, 5 years ago (diff)

Dont hide server log on stopping server. Fixed minor UI quirk when starting/stopping server. Removed redundant gtk.Hbox. Removed my email from all files. Added references to the HACKING guide on the docs.

  • Property svn:executable set to *
  • Property svn:keywords set to Id Rev
Line 
1#! /usr/bin/env python
2# -*- coding: utf8 -*-
3#
4# Itaka is free software; you can redistribute it and/or modify
5# it under the terms of the GNU General Public License as published by
6# the Free Software Foundation; either version 2 of the License, or
7# any later version.
8#
9# Itaka is distributed in the hope that it will be useful,
10# but WITHOUT ANY WARRANTY; without even the implied warranty of
11# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12# GNU General Public License for more details.
13#
14# You should have received a copy of the GNU General Public License
15# along with Itaka; if not, write to the Free Software
16# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
17#
18# Copyright 2003-2007 Marc E.
19# http://itaka.jardinpresente.com.ar
20#
21# $Id$
22
23""" Itaka console output and logging engine """
24
25class BaseMessage:
26    """
27    Base class for console output.
28    """
29
30    def __init__(self, message):
31        """
32        Constructor.
33
34        @type message: str
35        @param message: The message to print on the Console.
36        """
37
38        self.message = message
39        print '[*] %s' % (str(self.message))
40
41class BaseFailureMessage(BaseMessage):
42    """
43    Base class for failure messages.
44    """
45
46    def __init__(self, debug, caller, message, type):
47        """
48        Constructor.
49
50        @type debug: bool
51        @param debug: Whether the L{caller} arguments will be printed.
52
53        @type caller: tuple
54        @param caller: Specifies the class and method were the failure ocurred.
55
56        @type message: str
57        @param message: The message to print.
58
59        @type type: str
60        @param type: The type of failure: 'WARNING', 'ERROR', 'DEBUG'.
61        """
62
63        self.caller = '.'.join(caller)
64        self.message = message
65        self.debug = debug
66        self.type = type
67
68        if self.debug:
69            self.message = ' '.join((self.caller, self.message))
70
71        print '[*] %s: %s' % (str(self.type), str(self.message))
72               
73
74class Console:
75    """
76    Console I/O handler organized by message type. Also handle GUI logging when passed an instance.
77    """
78
79    def __init__(self, itakaglobals):
80        """ailuretype == 'ERROR':
81
82        Constructor for console output handler.
83       
84        @type itakaglobals: module
85        @param itakaglobals: Configuration module.
86        """
87
88        self.itakaglobals = itakaglobals
89        if self.itakaglobals.output['normal']:
90            BaseMessage('Itaka %s starting' % (itakaglobals.version))
91           
92    def __del__(self):
93        """
94        Destructor.
95        """
96       
97        if self.itakaglobals.output['normal']:
98            BaseMessage('Itaka shutting down')
99
100    def message(self, message):
101        """
102        Message handler.
103       
104        @type message: str
105        @param message: Message to print to the console.
106        """
107       
108        if self.itakaglobals.output['normal']:
109            BaseMessage(message)
110
111    def failure(self, caller, message, failuretype='ERROR'):
112        """
113        Failure handler abstract.
114
115        @type caller: tuple
116        @param caller: Specifies the class and method were the warning ocurred.
117
118        @type message: str
119        @param message: Message to print to the console.
120
121        @type failuretype: str
122        @param failuretype: What kind of failure it is, either 'ERROR' (default), 'WARNING' or 'DEBUG'
123        """
124
125        if failuretype == 'ERROR':
126            if not self.itakaglobals.output['quiet']:
127                BaseFailureMessage(self.itakaglobals.output['quiet'], caller, message, failuretype)
128
129        elif failuretype == 'WARNING':
130            if self.itakaglobals.output['normal']:
131                BaseFailureMessage(self.itakaglobals.output['normal'], caller, message, failuretype)
132
133        elif failuretype == 'DEBUG':
134            if self.itakaglobals.output['debug']:
135                BaseFailureMessage(self.itakaglobals.output['debug'], caller, message, failuretype)
136
Note: See TracBrowser for help on using the repository browser.