~ubuntu-branches/ubuntu/utopic/gozerbot/utopic

« back to all changes in this revision

Viewing changes to debian/gozerbot/usr/lib/python2.5/site-packages/gozerbot/aliases.py

  • Committer: Bazaar Package Importer
  • Author(s): Jeremy Malcolm
  • Date: 2009-09-14 09:00:29 UTC
  • mfrom: (1.1.4 upstream) (3.1.5 sid)
  • Revision ID: james.westby@ubuntu.com-20090914090029-uval0ekt72kmklxw
Tags: 0.9.1.3-3
Changed dependency on python-setuptools to python-pkg-resources
(Closes: #546435) 

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# gozerbot/aliases.py
2
 
#
3
 
#
4
 
 
5
 
""" command aliases """
6
 
 
7
 
__copyright__ = 'this file is in the public domain'
8
 
 
9
 
from gozerbot.datadir import datadir
10
 
from gozerbot.persist import Persist
11
 
from gozerbot.generic import lockdec
12
 
import os, thread
13
 
 
14
 
aliases = Persist(datadir + os.sep + 'aliases') # aliases
15
 
if not aliases.data:
16
 
    aliases.data = {}
17
 
 
18
 
aliaslock = thread.allocate_lock()
19
 
locked = lockdec(aliaslock)
20
 
 
21
 
def aliasreverse(what):
22
 
    """ get the reverse of an alias """
23
 
    for i, j in aliases.data.iteritems():
24
 
        if what == j:
25
 
            return i
26
 
 
27
 
def aliascheck(ievent):
28
 
    """ check if alias is available """
29
 
    try:
30
 
        cmnd = ievent.txt.split()[0]
31
 
        alias = aliases.data[cmnd]
32
 
        ievent.txt = ievent.txt.replace(cmnd, alias, 1)
33
 
        ievent.alias = alias
34
 
        ievent.aliased = cmnd
35
 
    except (IndexError, KeyError):
36
 
        pass
37
 
 
38
 
@locked
39
 
def aliassave():
40
 
    """ save the aliases data """
41
 
    aliases.save()
42
 
 
43
 
@locked
44
 
def aliasset(fromm, to):
45
 
    """ set an alias """
46
 
    aliases.data[fromm] = to
47
 
 
48
 
@locked
49
 
def aliasdel(fromm):
50
 
    """ delete an alias """
51
 
    try:
52
 
        del aliases.data[fromm]
53
 
        aliases.save()
54
 
        return 1
55
 
    except KeyError:
56
 
        pass
57
 
 
58
 
def aliasget(fromm):
59
 
    """ retrieve an alias """
60
 
    if aliases.data.has_key(fromm): 
61
 
        return aliases.data[fromm]