コード例 #1
0
ファイル: periodical.py プロジェクト: RetroRodent/my-gozerbot
# JobInterval scheduler
# (c) Wijnand 'tehmaze' Modderman - http://tehmaze.com
# BSD License

# gozerbot imports
from generic import calledfrom, lockdec, rlog, strtotime, handle_exception
import threads.thr as thr

# basic imorts
import datetime, sys, time, thread, types

# locks and vars
plock    = thread.allocate_lock()
locked   = lockdec(plock)
pidcount = 0

class JobError(Exception):

    """ job error exception. """

    pass

class Job(object):

    """ job to be scheduled. """

    group = ''
    pid   = -1

    def __init__(self):
        global pidcount
コード例 #2
0
ファイル: callbacks.py プロジェクト: blaxter/my-gozerbot
# gozerbot imports
from gozerbot.stats import stats
from gozerbot.threads.thr import getname
from config import config
from generic import rlog, handle_exception, calledfrom, makeargrest, lockdec
from utils.dol import Dol
from threads.thr import start_new_thread, getname
from runner import cbrunners

# basic imports
import sys, copy, thread

# locks
callbacklock = thread.allocate_lock()
locked = lockdec(callbacklock)


class Callback(object):

    """ class representing a callback. """

    def __init__(self, func, prereq, plugname, kwargs, threaded=False, speed=5):
        self.func = func  # the callback function
        self.prereq = prereq  # pre condition function
        self.plugname = plugname  # plugin name
        self.kwargs = kwargs  # kwargs to pass on to function
        self.threaded = copy.deepcopy(threaded)  # run callback in thread
        self.speed = copy.deepcopy(speed)  # speed to execute callback with
        stats.up("callbacks", "created")
コード例 #3
0
# gozerbot imports
from gozerbot.stats import stats
from utils.generic import makeoptions
from eventbase import defaultevent
from config import config
from generic import rlog, calledfrom, handle_exception, lockdec
from runner import cmndrunners
from threads.thr import start_new_thread, start_bot_command

# basic imports
import sys, re, copy, types, thread

# lock
commandlock = thread.allocate_lock()
locked = lockdec(commandlock)


class Command(object):
    """ implements a command. """
    def __init__(self,
                 func,
                 perm,
                 plugname,
                 speed=5,
                 threaded=False,
                 allowqueue=True,
                 options={}):

        self.name = str(
            func)  # function name is string representation of the function
コード例 #4
0
__copyright__ = 'this file is in the public domain'

# gozerbot imports
from gozerbot.stats import stats
from gozerbot.threads.thr import getname
from threads.thr import start_new_thread
from generic import handle_exception, rlog, lockdec
from threads.threadloop import RunnerLoop
from periodical import minutely

# basic imports
import Queue, time, thread, random

# locks
runlock = thread.allocate_lock()
locked = lockdec(runlock)


class Runner(RunnerLoop):
    """ a runner is a thread with a queue on which jobs can be pushed. """
    def __init__(self, name="runner"):
        RunnerLoop.__init__(self, name)
        self.working = False
        self.starttime = time.time()
        self.elapsed = self.starttime
        self.finished = time.time()

    def handle(self, descr, func, *args, **kwargs):
        """ schedule a job. """

        self.working = True
コード例 #5
0
#

""" event handler. use to dispatch function in main loop. """

__copyright__ = 'this file is in the public domain'

# gozerbot imports
from generic import handle_exception, rlog, lockdec
from threads.thr import start_new_thread

# basic imports
import Queue, thread

# locks
handlerlock = thread.allocate_lock()
locked = lockdec(handlerlock)

class Eventhandler(object):

    """ events are handled in 11 queues with different priorities:
        queue0 is tried first queue10 last.
    """

    def __init__(self):
        self.sortedlist = []
        self.queues = {}
        for i in range(11):
            self.queues[i] = Queue.Queue()
            self.sortedlist.append(i)
        self.sortedlist.sort()
        self.go = Queue.Queue()
コード例 #6
0
ファイル: commands.py プロジェクト: RetroRodent/my-gozerbot
# gozerbot imports
from gozerbot.stats import stats
from utils.generic import makeoptions
from eventbase import defaultevent
from config import config
from generic import rlog, calledfrom, handle_exception, lockdec
from runner import cmndrunners
from threads.thr import start_new_thread, start_bot_command

# basic imports
import sys, re, copy, types, thread

# lock
commandlock = thread.allocate_lock()
locked = lockdec(commandlock)


class Command(object):

    """ implements a command. """

    def __init__(self, func, perm, plugname, speed=5, threaded=False, allowqueue=True, options={}):

        self.name = str(func) # function name is string representation of the function 
        self.func = func # function to call

        # make sure permission(s) are stored in a list
        if type(perm) == types.ListType:
            self.perms = list(perm)
        else:
コード例 #7
0
# gozerbot imports
from gozerbot.stats import stats
from gozerbot.threads.thr import getname
from config import config
from generic import rlog, handle_exception, calledfrom, makeargrest, lockdec
from utils.dol import Dol
from threads.thr import start_new_thread, getname
from runner import cbrunners

# basic imports
import sys, copy, thread

# locks
callbacklock = thread.allocate_lock()
locked = lockdec(callbacklock)


class Callback(object):
    """ class representing a callback. """

    def __init__(self, func, prereq, plugname, kwargs, threaded=False, \
speed=5):
        self.func = func  # the callback function
        self.prereq = prereq  # pre condition function
        self.plugname = plugname  # plugin name
        self.kwargs = kwargs  # kwargs to pass on to function
        self.threaded = copy.deepcopy(threaded)  # run callback in thread
        self.speed = copy.deepcopy(speed)  # speed to execute callback with
        stats.up('callbacks', 'created')
コード例 #8
0
ファイル: wait.py プロジェクト: GuillaumeFromage/my-gozerbot
#
#
""" wait for ircevent based on ircevent.CMND """

__copyright__ = 'this file is in the public domain'

# gozerbot imports
from generic import rlog, lockdec
import threads.thr as thr

# basic imports
import time, thread

# locks
waitlock = thread.allocate_lock()
locked = lockdec(waitlock)


class Wait(object):
    """ lists of ircevents to wait for """
    def __init__(self):
        self.waitlist = []
        self.ticket = 0

    def register(self, cmnd, catch, queue, timeout=15):
        """ register wait for cmnd. """

        rlog(1, 'wait', 'registering for cmnd ' + cmnd)
        self.ticket += 1
        self.waitlist.insert(0, (cmnd, catch, queue, self.ticket))
        if timeout:
コード例 #9
0
ファイル: wait.py プロジェクト: RetroRodent/my-gozerbot
#

""" wait for ircevent based on ircevent.CMND """

__copyright__ = 'this file is in the public domain'

# gozerbot imports
from generic import rlog, lockdec
import threads.thr as thr

# basic imports
import time, thread

# locks
waitlock = thread.allocate_lock()
locked = lockdec(waitlock)

class Wait(object):

    """ lists of ircevents to wait for """

    def __init__(self):
        self.waitlist = []
        self.ticket = 0

    def register(self, cmnd, catch, queue, timeout=15):

        """ register wait for cmnd. """

        rlog(1, 'wait', 'registering for cmnd ' + cmnd)
        self.ticket += 1
コード例 #10
0
from commands import cmnds
from callbacks import callbacks, jcallbacks
from redispatcher import rebefore, reafter
from irc.ircevent import Ircevent
from aliases import aliascheck
from ignore import shouldignore
from threads.thr import start_new_thread, getname
from persist.persiststate import PersistState
from simplejson import loads
from morphs import inputmorphs, outputmorphs

# basic imports
import os, os.path, thread, time, Queue, re

loadlock = thread.allocate_lock()
loadlocked = lockdec(loadlock)


class Plugins(object):
    """ hold all the plugins. """
    def __init__(self):
        self.plugs = {}  # dict with the plugins
        self.reloadlock = thread.allocate_lock()
        # persisted data for deny of plugins (blacklist)
        self.plugdeny = Persist(datadir + os.sep + 'plugdeny', init=False)
        if not self.plugdeny.data:
            self.plugdeny.data = []
        # persisted data for allowing of plugins (whitelist)
        self.plugallow = Persist(datadir + os.sep + 'plugallow', init=False)
        if not self.plugallow.data:
            self.plugallow.data = []
コード例 #11
0
ファイル: plugins.py プロジェクト: RetroRodent/my-gozerbot
from commands import cmnds
from callbacks import callbacks, jcallbacks
from redispatcher import rebefore, reafter
from irc.ircevent import Ircevent
from aliases import aliascheck
from ignore import shouldignore
from threads.thr import start_new_thread, getname
from persist.persiststate import PersistState
from simplejson import loads
from morphs import inputmorphs, outputmorphs

# basic imports
import os, os.path, thread, time, Queue, re

loadlock = thread.allocate_lock()
loadlocked = lockdec(loadlock)

class Plugins(object):

    """ hold all the plugins. """

    def __init__(self):
        self.plugs = {} # dict with the plugins
        self.reloadlock = thread.allocate_lock()
        # persisted data for deny of plugins (blacklist)
        self.plugdeny = Persist(datadir + os.sep + 'plugdeny', init=False)
        if not self.plugdeny.data:
            self.plugdeny.data = []
        # persisted data for allowing of plugins (whitelist)
        self.plugallow = Persist(datadir + os.sep + 'plugallow', init=False)
        if not self.plugallow.data:
コード例 #12
0
""" implement RE (regular expression) dispatcher. """

__copyright__ = 'this file is in the public domain'

# gozerbot imports
from config import config
from generic import rlog, calledfrom, handle_exception, lockdec
from runner import cmndrunners
import threads.thr as thr

# basic imports
import sys, re, copy, types, thread

# locks
relock = thread.allocate_lock()
locked = lockdec(relock)

class Recallback(object):

    """ a regular expression callback """

    def __init__(self, index, regex, func, perm, plugname, speed=5, \
threaded=True, allowqueue=True, options={}):
        self.name = thr.getname(func) # name of the callback
        self.index = index # index into the list
        self.regex = regex # the RE to match
        self.compiled = re.compile(regex) # compiled RE
        self.func = func # the function to call if RE matches
        # make sure perms is a list
        if type(perm) == types.ListType:
            self.perms = list(perm)
コード例 #13
0
ファイル: runner.py プロジェクト: blaxter/my-gozerbot
__copyright__ = "this file is in the public domain"

# gozerbot imports
from gozerbot.stats import stats
from gozerbot.threads.thr import getname
from threads.thr import start_new_thread
from generic import handle_exception, rlog, lockdec
from threads.threadloop import RunnerLoop
from periodical import minutely

# basic imports
import Queue, time, thread, random

# locks
runlock = thread.allocate_lock()
locked = lockdec(runlock)


class Runner(RunnerLoop):

    """ a runner is a thread with a queue on which jobs can be pushed. """

    def __init__(self, name="runner"):
        RunnerLoop.__init__(self, name)
        self.working = False
        self.starttime = time.time()
        self.elapsed = self.starttime
        self.finished = time.time()

    def handle(self, descr, func, *args, **kwargs):