Пример #1
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) or whichmodule()
     self.jobs.append(job)
     return job.pid
Пример #2
0
 def add(self, cmnd, func, perms, threaded=False, wait=False, orig=None, how=None, *args, **kwargs):
     """ add a command. """
     modname = calledfrom(sys._getframe())
     try: prev = self[cmnd]
     except KeyError: prev = None
     target = Command(modname, cmnd, func, perms, threaded, wait, orig, how)
     if how == "regex":
         logging.info("regex command detected - %s" % cmnd)
         self.regex.append(target)
         target.regex = cmnd 
         return self
     self[cmnd] = target
     try:
         c = cmnd.split('-')[1]
         if not self.subs: self.subs = LazyDict()
         if self.subs.has_key(c):
             if not self.subs[c]: self.subs[c] = []
             if prev in self.subs[c]: self.subs[c].remove(prev) 
             if target not in self.subs[c]: self.subs[c].append(target)
         else: self.subs[c] = [target, ]
     except IndexError: pass
     try:
         p = cmnd.split('-')[0]
         if not self.pre: self.pre = LazyDict()
         if self.pre.has_key(p):
             if not self.pre[p]: self.pre[p] = []
             if prev in self.pre[p]: self.pre[p].remove(prev) 
             if target not in self.pre[p]: self.pre[p].append(target)
         else: self.pre[p] = [target, ]
     except IndexError: pass
     return self
Пример #3
0
 def add(self,
         what,
         func,
         prereq=None,
         kwargs=None,
         threaded=False,
         nr=False,
         speed=5,
         force=False):
     """  add a callback. """
     what = what.upper()
     modname = calledfrom(sys._getframe())
     if not kwargs: kwargs = {}
     if nr != False:
         self.cbs.insert(
             nr, what,
             Callback(modname, func, prereq, kwargs, threaded, speed,
                      force))
     else:
         self.cbs.add(
             what,
             Callback(modname, func, prereq, kwargs, threaded, speed,
                      force))
     logging.debug('added %s (%s)' % (what, modname))
     return self
Пример #4
0
 def __init__(self, *args, **kwargs):
     self.plugname = calledfrom(sys._getframe())
     logging.debug('persiststate - initialising %s' % self.plugname)
     PersistState.__init__(
         self,
         getdatadir() + os.sep + 'state' + os.sep + 'plugs' + os.sep +
         self.plugname + os.sep + 'state')
Пример #5
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) or whichmodule()
     self.jobs.append(job)
     return job.pid
Пример #6
0
 def add(self, taskname, func):
     """ add a task. """
     logging.debug("tasks - added task %s - %s" % (taskname, func))
     self.handlers[taskname] = func
     plugin = self.plugins[taskname] = calledfrom(sys._getframe())
     plugs.load_mod(plugin)
     return True
Пример #7
0
 def add(self, taskname, func):
     """ add a task. """
     logging.debug("tasks - added task %s - %s" % (taskname, func))
     self.handlers[taskname] = func
     plugin = self.plugins[taskname] = calledfrom(sys._getframe())
     plugs.load_mod(plugin)
     return True
Пример #8
0
 def add(self, what, func, prereq=None, kwargs=None, threaded=False, nr=False, speed=5):
     """  add a callback. """
     what = what.upper()
     modname = calledfrom(sys._getframe())
     if not kwargs: kwargs = {}
     if nr != False: self.cbs.insert(nr, what, Callback(modname, func, prereq, kwargs, threaded, speed))
     else: self.cbs.add(what, Callback(modname, func, prereq, kwargs, threaded, speed))
     logging.debug('callbacks - added %s (%s)' % (what, modname))
     return self
Пример #9
0
 def __getattribute__(self, name):
     # make sure the attribute data is not called from Persist or
     # PersistConfig returning a persist compatible (key, value) dict
     # instead of the rich persistconfig
     cf = calledfrom(sys._getframe())
     ## (key, option(value, ...)) is only for persistconfig internal usage.
     if name == "data" and cf != "persistconfig" and cf != "persist" and cf != self.__basename__:
         # intercept data block, return a clean dict with lazy binding
         # to option.value
         return LazyValueDict(self)
     return super(PersistConfig, self).__getattribute__(name)
Пример #10
0
 def outnocb(self, waveid, txt, result=[], event=None, origin="", dot=", ", *args, **kwargs):
     """ output to the root id. """
     if not self.domain in self._server_rpc_base:
         credentials = _import_byfile("credentials", getdatadir() + os.sep + "config" + os.sep + "credentials.py")
         rpc_base = credentials.RPC_BASE[waveid.split("!")[0]]
         self._server_rpc_base = rpc_base
         logging.warn("%s - %s - server_rpc_base is %s" % (self.name, waveid, self._server_rpc_base))
     if not event: logging.error("wave - event not set - %s" % calledfrom(sys._getframe(0)))
     logging.warn("wave - creating new event.")
     wave = Wave(waveid)
     wave.say(self, txt)
Пример #11
0
 def __init__(self):
     self.__basename__ = self.__class__.__name__
     self.plugname = calledfrom(sys._getframe())
     Persist.__init__(self, os.path.join(datadir, "%s-config" % self.plugname), {})
     self.__callbacks = {}
     cmndname = "%s-cfg" % self.plugname
     logging.info("added command %s (%s)" % (cmndname, self.plugname))
     cmnds[cmndname] = Command(self.cmnd_cfg, "OPER", self.plugname, threaded=True)
     examples.add(cmndname, "plugin configuration", cmndname)
     cmndnamesave = cmndname + "save"
     cmnds[cmndnamesave] = Command(self.cmnd_cfgsave, "OPER", self.plugname, threaded=True)
     examples.add(cmndnamesave, "save plugin configuration", cmndnamesave)
Пример #12
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
        job.description = whichmodule()
        periodical.jobs.append(job)
        logging.warn('new interval job %d running minutely' % job.id())

    return wrapper
Пример #13
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
        job.description = whichmodule()
        periodical.jobs.append(job)
        logging.warn('new interval job %d running minutely' % job.id())

    return wrapper
Пример #14
0
def daily(function):
    """ day decorator. """
    logging.warn('@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
        job.description = whichmodule()
        periodical.jobs.append(job)
        logging.warb('new interval job %d running daily' % job.id())

    return wrapper
Пример #15
0
def daily(function):
    """ day decorator. """
    logging.warn('@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
        job.description = whichmodule()
        periodical.jobs.append(job)
        logging.warb('new interval job %d running daily' % job.id())

    return wrapper
Пример #16
0
 def start(self):
     """ start the REST server. """
     self.name = calledfrom(sys._getframe(0))
     self.stop = False
     self.running = False
     self.handlers = {}
     self.webmods = {}
     self.state = ObjectState()
     self.state.define('whitelistenable', 0)
     self.state.define('whitelist', [])
     self.state.define('blacklist', [])
     self.state.define('disable', [])
     self.poll = select.poll()
     self.poll.register(self)
     start_new_thread(self.serve, ())
Пример #17
0
 def add(self,
         cmnd,
         func,
         perms,
         threaded=False,
         wait=False,
         orig=None,
         how=None,
         speed=None,
         regex=False,
         needcc=False,
         *args,
         **kwargs):
     """ add a command. """
     modname = calledfrom(sys._getframe())
     try:
         prev = self[cmnd]
     except KeyError:
         prev = None
     target = Command(modname,
                      cmnd,
                      func,
                      perms,
                      threaded,
                      wait,
                      orig,
                      how,
                      speed=speed,
                      needcc=needcc)
     if regex:
         logging.info("regex command detected - %s" % cmnd)
         self.regex.append(target)
         target.regex = cmnd
         return self
     self[cmnd] = target
     try:
         p = cmnd.split('-')[0]
         if not self.pre: self.pre = LazyDict()
         if self.pre.has_key(p):
             if not self.pre[p]: self.pre[p] = []
             if prev in self.pre[p]: self.pre[p].remove(prev)
             if target not in self.pre[p]: self.pre[p].append(target)
         else: self.pre[p] = [
             target,
         ]
     except IndexError:
         pass
     return self
Пример #18
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
            job.description = whichmodule()
            periodical.jobs.append(job)
            logging.warn('new interval job %d with sleeptime %d' % (job.id(), sleeptime))
        return wrapper

    return decorator
Пример #19
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
            job.description = whichmodule()
            periodical.jobs.append(job)

        wrapper.func_dict = function.func_dict
        return wrapper

    return decorator
Пример #20
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
            job.description = whichmodule()
            periodical.jobs.append(job)
            logging.warn('new interval job %d with sleeptime %d' %
                         (job.id(), sleeptime))

        return wrapper

    return decorator
Пример #21
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
            job.description = whichmodule()
            periodical.jobs.append(job)

        wrapper.func_dict = function.func_dict
        return wrapper

    return decorator
Пример #22
0
 def add(self, cmnd, func, perms, threaded=False, wait=False, orig=None, how=None, *args, **kwargs):
     """ add a command. """
     modname = calledfrom(sys._getframe())
     target = Command(modname, cmnd, func, perms, threaded, wait, orig, how)
     self[cmnd] = target
     try:
         c = cmnd.split('-')[1]
         if not self.subs: self.subs = LazyDict()
         if self.subs.has_key(c):
             if not self.subs[c]: self.subs[c] = []
             if target not in self.subs[c]: self.subs[c].append(target)
         else: self.subs[c] = [target, ]
     except IndexError: pass
     try:
         p = cmnd.split('-')[0]
         if not self.pre: self.pre = LazyDict()
         if self.pre.has_key(p):
             if not self.pre[p]: self.pre[p] = []
             if target not in self.pre[p]: self.pre[p].append(target)
         else: self.pre[p] = [target, ]
     except IndexError: pass
     return self
Пример #23
0
 def outnocb(self,
             waveid,
             txt,
             result=[],
             event=None,
             origin="",
             dot=", ",
             *args,
             **kwargs):
     """ output to the root id. """
     if not self.domain in self._server_rpc_base:
         credentials = _import_byfile(
             "credentials",
             getdatadir() + os.sep + "config" + os.sep + "credentials.py")
         rpc_base = credentials.RPC_BASE[waveid.split("!")[0]]
         self._server_rpc_base = rpc_base
         logging.warn("%s - %s - server_rpc_base is %s" %
                      (self.name, waveid, self._server_rpc_base))
     if not event:
         logging.error("wave - event not set - %s" %
                       calledfrom(sys._getframe(0)))
     logging.warn("wave - creating new event.")
     wave = Wave(waveid)
     wave.say(self, txt)
Пример #24
0
 def kill(self):
     """ kill all jobs invoked by another module. """
     group = calledfrom(sys._getframe())
     self.killgroup(group)
Пример #25
0
 def __init__(self, *args, **kwargs):
     PersistState.__init__(
         self,
         getdatadir() + os.sep + 'state' + os.sep +
         calledfrom(sys._getframe(1)) + '.state')
Пример #26
0
 def save(self):
     """ save the config. """
     logging.info("save called from %s" % calledfrom(sys._getframe(2)))
     self.issaved = True
     if self.isdb: self.todb()
     else: self.tofile(self.cfile)
Пример #27
0
 def __init__(self, *args, **kwargs):
     PersistState.__init__(self, getdatadir() + os.sep + 'state' + os.sep + calledfrom(sys._getframe(1))+'.state')
Пример #28
0
 def __init__(self, *args, **kwargs):
     self.plugname = calledfrom(sys._getframe())
     logging.debug('persiststate - initialising %s' % self.plugname)
     PersistState.__init__(self, getdatadir() + os.sep + 'state' + os.sep + 'plugs' + os.sep + self.plugname + os.sep + 'state')
Пример #29
0
def plugfile(datadir):
    return datadir + os.sep + calledfrom(sys._getframe())
Пример #30
0
 def save(self):
     """ save the config. """
     logging.info("config - save called from %s" % calledfrom(sys._getframe(1)))
     if self.isdb: self.todb()
     else: self.tofile()
Пример #31
0
 def __init__(self, func):
     self.modname = calledfrom(sys._getframe(1))
     self.func = func
     self.activate = True
Пример #32
0
 def __init__(self, func):
     self.modname = calledfrom(sys._getframe(1))
     self.func = func
     self.activate = True
Пример #33
0
 def kill(self):
     """ kill all jobs invoked by another module. """
     group = calledfrom(sys._getframe())
     self.killgroup(group)