deed.py :  » Development » Lyntin » lyntin-4.2 » lyntin » modules » 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 » Development » Lyntin 
Lyntin » lyntin 4.2 » lyntin » modules » deed.py
#########################################################################
# This file is part of Lyntin.
#
# Lyntin is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# Lyntin is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
# 
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
#
# copyright (c) Free Software Foundation 2002-2007
#
# $Id: deed.py,v 1.3 2007/07/24 00:39:03 willhelm Exp $
#########################################################################
"""
This module defines the DeedManager which handles deeds (user events).

Deeds can be used to keep track of when things happened.  I tend to
create deeds whenever someone does something nice for me via an action.
This allows me to have a log of who did what to me and when they did it
(if you use the $TIMESTAMP variable) even if I'm away from the computer
or in the midst of copious battle spam.
"""

# deed code originally written by Sebastian John.

import string
from lyntin import manager,utils,exported
from lyntin.modules import modutils

class DeedData:
  def __init__(self):
    self._deeds = []
  
  def addDeed(self, deed):
    """
    Adds a deed to the list.
    
    @param deed: the actual deed text
    @type deed: string
    """
    self._deeds.append(deed)
  
  def clear(self):
    """
    Removes all the deeds.
    """
    self._deeds = []
  
  def getInfo(self, num=""):
    """
    Returns information about the deeds in here.
    
    This is used only by #deed to show all the deeds stored.
    
    @param num: if a number, then returns the last num deeds.  otherwise
        returns deeds that match what this expands to.
    @type num: string or int

    @returns: one big string with all the deeds in it
    @rtype: string
    """
    if not self._deeds:
      return ""
    
    if num.isdigit():
      count = int(num)
      listing = self._deeds[-count:]
    else:
      listing = self._deeds
    
    return string.join(listing, "\n")
  
  def getStatus(self):
    """
    Returns the number of deeds actually stored.

    @returns: the total number of deeds in this DeedData object.
    @rtype: int
    """
    return "%d deed(s)." % len(self._deeds)

class DeedManager(manager.Manager):
  def __init__(self):
    self._deeds = {}

  def getDeedData(self, ses):
    if not self._deeds.has_key(ses):
      self._deeds[ses] = DeedData()
    return self._deeds[ses]

  def clear(self, ses):
    if self._deeds.has_key(ses):
      self._deeds[ses].clear()

  def getInfo(self, ses, num=""):
    return self.getDeedData(ses).getInfo(num)

  def getStatus(self, ses):
    return self.getDeedData(ses).getStatus()


commands_dict = {}

def deed_cmd(ses, args, input):
  """
  Deeds serve as a kind of notebook - whatever you don't want
  to forget, store it in a deed.

  examples::
    #deed                             -- prints all the deeds for 
                                         that session
    #deed {$TIMESTAMP Joe healed me}  -- adds a new deed to the list
    #deed 10                          -- prints the last 10 deeds

  Before a deed is stored, variables are expanded--this allows you
  to use system, global, and session variables in your deeds like
  $TIMESTAMP which will mark when the deed was created.
  
  category: commands
  """
  # original deed_cmd code contributied by Sebastian John

  if (ses.getName() == "common"):
    exported.write_error("deed cannot be applied to common session.", ses)
    return

  deedtext = args["text"]
  quiet = args["quiet"]

  if not deedtext:
    data = exported.get_manager("deed").getInfo(ses)
    if data == "":
      data = "deed: no deeds defined."
    
    exported.write_message(data, ses)
    return
  
  if deedtext.isdigit():
    data = exported.get_manager("deed").getInfo(ses, deedtext)
    if data == "":
      data = "deed: no deeds defined."
    
    exported.write_message(data, ses)
    return

  exported.get_manager("deed").getDeedData(ses).addDeed(deedtext)
  if not quiet:
    exported.write_message("deed: {%s} added." % deedtext, ses)

commands_dict["deed"] = (deed_cmd, "text= quiet:boolean=false")


dm = None

def load():
  """ Initializes the module by binding all the commands."""
  global dm
  modutils.load_commands(commands_dict)
  dm = DeedManager()
  exported.add_manager("deed", dm)


def unload():
  """ Unloads the module by calling any unload/unbind functions."""
  global dm
  modutils.unload_commands(commands_dict.keys())
  exported.remove_manager("deed")

# Local variables:
# mode:python
# py-indent-offset:2
# tab-width:2
# End:
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.