Example #1
0
    def add(self,
            what,
            func,
            prereq=None,
            kwargs=None,
            threaded=False,
            nr=False,
            speed=5):
        """ add a callback. """

        what = what.upper()

        # get the plugin this callback was registered from
        plugname = calledfrom(sys._getframe(1))

        # check if plugname is in loadlist .. if not don't add callback
        if config['loadlist'] and not plugname in config['loadlist']:
            return

        # see if kwargs is set if not init to {}
        if not kwargs:
            kwargs = {}

        # add callback to the dict of lists
        if nr != False:
            self.cbs.insert(
                nr, what,
                Callback(func, prereq, plugname, kwargs, threaded, speed))
        else:
            self.cbs.add(
                what, Callback(func, prereq, plugname, kwargs, threaded,
                               speed))

        rlog(-3, 'callbacks', 'added %s (%s)' % (what, plugname))
Example #2
0
    def addjob(self, sleeptime, repeat, function, description="" , *args, **kw): 

        """ add a periodical job. """

        job = JobInterval(sleeptime, repeat, function, *args, **kw)
        job.group = calledfrom(sys._getframe())
        job.description = str(description)
        self.jobs.append(job)
        return job.pid
Example #3
0
    def add(self, name, callback, pre, threaded=False):
        """ add a monitoring callback. """

        name = calledfrom(sys._getframe(0))

        if config['loadlist'] and name not in config['loadlist']:
            return

        self.outs.append((name, callback, pre, threaded))
        rlog(0, self.name, 'added %s (%s)' % (name, str(callback)))
Example #4
0
    def add(self, name, callback, pre, threaded=False):

        """ add a monitoring callback. """

        name = calledfrom(sys._getframe(0))

        if config['loadlist'] and name not in config['loadlist']:
            return

        self.outs.append((name, callback, pre, threaded))
        rlog(0, self.name, 'added %s (%s)' % (name, str(callback)))
Example #5
0
def daily(function):

    """ day decorator. """

    rlog(-15, 'periodical', '@daily(%s)' % str(function))
    daily.func_dict = function.func_dict
    group = calledfrom(sys._getframe())

    def wrapper(*args, **kw):
        job = JobInterval(86400, 0, function, *args, **kw)
        job.group =  group
        periodical.jobs.append(job)
        rlog(-15, 'periodical', 'new interval job %d running daily' % job.id())

    return wrapper
Example #6
0
def minutely(function):

    """ minute decorator. """

    minutely.func_dict = function.func_dict
    group = calledfrom(sys._getframe())

    def wrapper(*args, **kw):
        job = JobInterval(60, 0, function, *args, **kw)
        job.group = group
        periodical.jobs.append(job)
        rlog(-15, 'periodical', 'new interval job %d running minutely' % \
job.id())

    return wrapper
Example #7
0
    def add(self, cmnd, func, perm, speed=5, threaded=False, allowqueue=True, options={}):

        """ add a command. """

        # plugin where the command is added
        plugname = calledfrom(sys._getframe(1))

        # check if plugin is in loadlist .. if not dont register command. 
        if config['loadlist'] and plugname not in config['loadlist']:
            return

        rlog(-3, 'commands', 'added %s (%s) ' % (cmnd, plugname))

        # add command
        self[cmnd.lower()] = Command(func, perm, plugname, speed, threaded, allowqueue, options)
        self[cmnd.lower()].name = cmnd.lower()
    def add(self, index, regex, func, perm, speed=5, threaded=True, allowqueue=True, options={}):

        """ add a command. """

        try:
            # get plugin name from where callback is added
            plugname = calledfrom(sys._getframe())
            if config['loadlist'] and plugname not in config['loadlist']:
                return
            # add Recallback
            self.relist.append(Recallback(index, regex, func, perm, plugname, \
speed, threaded, allowqueue, options))
            # sort of index number
            self.relist.sort(lambda a, b: cmp(a.index, b.index))
            rlog(0, 'redispatcher', 'added %s (%s) ' % (regex, plugname))
        finally:
            pass
Example #9
0
def at(start, interval=1, repeat=1):

    """ at decorator. """

    group = calledfrom(sys._getframe())

    def decorator(function):
        decorator.func_dict = function.func_dict

        def wrapper(*args, **kw):
            job = JobAt(start, interval, repeat, function, *args, **kw)
            job.group = group
            periodical.jobs.append(job)

        wrapper.func_dict = function.func_dict
        return wrapper

    return decorator
Example #10
0
def interval(sleeptime, repeat=0):

    """ interval decorator. """

    group = calledfrom(sys._getframe())

    def decorator(function):
        decorator.func_dict = function.func_dict

        def wrapper(*args, **kw):
            job = JobInterval(sleeptime, repeat, function, *args, **kw)
            job.group = group
            periodical.jobs.append(job)
            rlog(-15, 'periodical', 'new interval job %d with sleeptime %d' % \
(job.id(), sleeptime))

        return wrapper

    return decorator
Example #11
0
    def add(self,
            cmnd,
            func,
            perm,
            speed=5,
            threaded=False,
            allowqueue=True,
            options={}):
        """ add a command. """

        # plugin where the command is added
        plugname = calledfrom(sys._getframe(1))

        # check if plugin is in loadlist .. if not dont register command.
        if config['loadlist'] and plugname not in config['loadlist']:
            return

        rlog(-3, 'commands', 'added %s (%s) ' % (cmnd, plugname))

        # add command
        self[cmnd.lower()] = Command(func, perm, plugname, speed, threaded,
                                     allowqueue, options)
        self[cmnd.lower()].name = cmnd.lower()
Example #12
0
    def add(self, what, func, prereq=None, kwargs=None, threaded=False, nr=False, speed=5):

        """ add a callback. """

        what = what.upper()

        # get the plugin this callback was registered from
        plugname = calledfrom(sys._getframe(1))

        # check if plugname is in loadlist .. if not don't add callback
        if config["loadlist"] and not plugname in config["loadlist"]:
            return

        # see if kwargs is set if not init to {}
        if not kwargs:
            kwargs = {}

        # add callback to the dict of lists
        if nr != False:
            self.cbs.insert(nr, what, Callback(func, prereq, plugname, kwargs, threaded, speed))
        else:
            self.cbs.add(what, Callback(func, prereq, plugname, kwargs, threaded, speed))

        rlog(-3, "callbacks", "added %s (%s)" % (what, plugname))
Example #13
0
    def kill(self):

        ''' kill all jobs invoked by another module. '''

        group = calledfrom(sys._getframe())
        self.killgroup(group)