audit.py :  » Game-2D-3D » PyScrabble » pyscrabble-1.6.2 » pyscrabble » Python Open Source

Home
Python Open Source
1.3.1.2 Python
2.Ajax
3.Aspect Oriented
4.Blog
5.Build
6.Business Application
7.Chart Report
8.Content Management Systems
9.Cryptographic
10.Database
11.Development
12.Editor
13.Email
14.ERP
15.Game 2D 3D
16.GIS
17.GUI
18.IDE
19.Installer
20.IRC
21.Issue Tracker
22.Language Interface
23.Log
24.Math
25.Media Sound Audio
26.Mobile
27.Network
28.Parser
29.PDF
30.Project Management
31.RSS
32.Search
33.Security
34.Template Engines
35.Test
36.UML
37.USB Serial
38.Web Frameworks
39.Web Server
40.Web Services
41.Web Unit
42.Wiki
43.Windows
44.XML
Python Open Source » Game 2D 3D » PyScrabble 
PyScrabble » pyscrabble 1.6.2 » pyscrabble » audit.py
from pyscrabble import lookup
from pyscrabble import util
import time

# Types
AUDIT_LOGON = 1
AUDIT_LOGOFF = 2
AUDIT_WIN_GAME = 3
AUDIT_LOSE_GAME = 4
AUDIT_TIE_GAME = 5

def fromType(type):
    '''
    Create and return an AuditAction based on type
    
    @param type:
    '''
    
    if type == AUDIT_LOGON: return LogonAction()
    if type == AUDIT_LOGOFF: return LogoffAction()
    if type == AUDIT_WIN_GAME: return GameWinAction()
    if type == AUDIT_LOSE_GAME: return GameLossAction()
    if type == AUDIT_TIE_GAME: return GameTieAction()

class Action(object):
    '''
    Base audit Action
    '''
    
    def __init__(self, type=None):
        '''
        Constructor
        '''
        self.date = util.Time(seconds=time.time(), dispDate=True)
        self.type = type


class LogonAction(Action):
    '''
    Logon action
    '''
    
    def __init__(self, username=None):
        '''
        Constructor
        
        @param username:
        '''
        
        Action.__init__(self, AUDIT_LOGON)
        self.username = username
    
    def __repr__(self):
        '''
        Print message
        '''
        return "%s %s" % (self.username, lookup.SERVER_MESSAGE_LOOKUP[lookup.LOGGED_IN])

class LogoffAction(Action):
    '''
    Logoff action
    '''
    
    def __init__(self, username=None):
        '''
        Constructor
        
        @param username:
        '''
        
        Action.__init__(self, AUDIT_LOGOFF)
        self.username = username
    
    def __repr__(self):
        '''
        Print message
        '''
        return "%s %s" % (self.username, lookup.SERVER_MESSAGE_LOOKUP[lookup.LOGGED_OUT])


class GameWinAction(Action):
    '''
    Game win action
    '''
    
    def __init__(self, winner=None, gameName = None, losers=None):
        '''
        Constructor
        
        @param winner:
        @param gameName:
        @param losers:
        '''
        Action.__init__(self, AUDIT_WIN_GAME)
        self.gameName = gameName
        
        if winner is not None:
            self.winner = '%s (%d)' % (winner.username, int(winner.score))
        
        if losers is not None:
            self.losers = ''
            for l in losers:
                if l != winner:
                    self.losers += '%s (%d)' % (l.username, int(l.score))
                    self.losers += ','
            self.losers = self.losers[:-1]
    
    def __repr__(self):
        '''
        Print message
        '''
        return "%s %s %s %s %s" % (self.winner, lookup.SERVER_MESSAGE_LOOKUP[lookup.DEFEATED], self.losers, lookup.SERVER_MESSAGE_LOOKUP[lookup.PLAYING_IN], self.gameName)

class GameLossAction(Action):
    '''
    Game loss action
    '''
    
    def __init__(self, winners=None, gameName = None, loser=None):
        '''
        
        @param winners:
        @param gameName:
        @param loser:
        '''
        Action.__init__(self, AUDIT_LOSE_GAME)
        self.gameName = gameName
        
        if winners is not None:
            self.winners = ''
            for w in winners:
                self.winners += '%s (%d)' % (w.username, int(w.score))
                self.winners += ','
            self.winners = self.winners[:-1]
        
        if loser is not None:
            self.loser = '%s (%d)' % (loser.username, int(loser.score))
        
    
    def __repr__(self):
        '''
        Print message
        '''
        return "%s %s %s %s %s" % (self.loser, lookup.SERVER_MESSAGE_LOOKUP[lookup.LOST_TO], self.winners, lookup.SERVER_MESSAGE_LOOKUP[lookup.PLAYING_IN], self.gameName)
        
class GameTieAction(Action):
    '''
    Game tie action
    '''
    
    def __init__(self, winner=None, gameName = None, other=None):
        '''
        
        @param winner:
        @param gameName:
        @param other:
        '''
        Action.__init__(self, AUDIT_TIE_GAME)
        self.gameName = gameName
        
        if winner is not None:
            self.winner = '%s (%d)' % (winner.username, int(winner.score))
        
        if other is not None:
            self.other = ''
            for o in other:
                self.other += '%s (%d)' % (o.username, int(o.score))
                self.other += ', '
            self.other = self.other[:-2]
    
    def __repr__(self):
        '''
        Print message
        '''
        return "%s %s %s %s %s" % (self.winner, lookup.SERVER_MESSAGE_LOOKUP[lookup.TIED_WITH], self.other, lookup.SERVER_MESSAGE_LOOKUP[lookup.PLAYING_IN], self.gameName)
        
      
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.