예제 #1
0
    def __init__(self,
                 when,
                 do,
                 scope,
                 continual=False,
                 ratelimit=0,
                 setup="pass",
                 *args,
                 **kwargs):

        #This event type is not polled. Note that it doesn't even have a check() method.
        self.polled = False

        def action_wrapper(topic, message):
            #Since we aren't under the BaseEvent.check() lock, we need to get it ourselves.
            with self.lock:
                #setup environment
                self.scope['__topic'] = topic
                self.scope['__message'] = message
                #We delegate the actual execution ofthe body to the on_trigger
                self._on_trigger()

        #When the object is deleted so will this reference and the message bus's auto unsubscribe will handle it
        self.action_wrapper_because_we_need_to_keep_a_reference = action_wrapper

        #Handle whatever stupid whitespace someone puts in
        #What this does is to eliminate leading whitespace, split on first space,
        #Then get rid of any extra spaces in between the command and argument.
        t = when.strip().split(' ', 1)[1].strip()
        #Subscribe our new function to the topic we want
        messagebus.subscribe(t, action_wrapper)
        BaseEvent.__init__(self, when, do, scope, continual, ratelimit, setup,
                           *args, **kwargs)
        self._init_setup_and_action(setup, do)
예제 #2
0
 def __init__(self,when,do,scope,continual=False,ratelimit=0,setup = "pass",*args,**kwargs):
     
     #This event type is not polled. Note that it doesn't even have a check() method.
     self.polled = False
     def action_wrapper(topic,message):
         #Since we aren't under the BaseEvent.check() lock, we need to get it ourselves.
         with self.lock:
             #setup environment
             self.scope['__topic'] = topic
             self.scope['__message'] = message
             #We delegate the actual execution ofthe body to the on_trigger
             self._on_trigger()
         
     #When the object is deleted so will this reference and the message bus's auto unsubscribe will handle it
     self.action_wrapper_because_we_need_to_keep_a_reference = action_wrapper
     
     #Handle whatever stupid whitespace someone puts in
     #What this does is to eliminate leading whitespace, split on first space,
     #Then get rid of any extra spaces in between the command and argument.
     t = when.strip().split(' ',1)[1].strip()
     #Subscribe our new function to the topic we want
     messagebus.subscribe(t,action_wrapper)
     BaseEvent.__init__(self,when,do,scope,continual,ratelimit,setup,*args,**kwargs)
     self._init_setup_and_action(setup,do)
예제 #3
0
#This file is part of Kaithem Automation.

#Kaithem Automation 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, version 3.

#Kaithem Automation 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 Kaithem Automation.  If not, see <http://www.gnu.org/licenses/>.

import messagebus, time
from config import config

keep_notifications = config['notifications-to-keep']
notificationslog = []


def subscriber(topic, message):
    global notificationslog
    print(message)
    notificationslog.append((time.time(), topic, message))
    #Delete all but the most recent N notifications, where N is from the config file.
    notificationslog = notificationslog[-keep_notifications:]


messagebus.subscribe('/system/notifications', subscriber)
예제 #4
0
def messagelistener(topic,message):
    global log
    global approxtotallogentries
    if topic not in log:
        log[topic] = []
    
    log[topic].append((time.time(),message))
    #This is not threadsafe. Hence the approx.
    approxtotallogentries +=1
    if approxtotallogentries > config['log-dump-size']:
        print('dumped')
        workers.do(dumpLogFile)


messagebus.subscribe('/',messagelistener)

def listlogdumps():
    where =os.path.join(directories.logdir,'dumps')
    logz = []
    r = re.compile(r'^([0-9]*\.[0-9]*)\.json(\.gz|\.bz2)?$')
    for i in util.get_files(where):
        m = r.match(i)
        if not m == None:
            #Make time,fn,ext,size tuple
            logz.append((float(m.groups('')[0]), os.path.join(where,i),m.groups('Uncompressed')[1],os.path.getsize(os.path.join(where,i))))
    return logz


class WebInterface(object):
    @cherrypy.expose
예제 #5
0
 def subscribe(topic, callback):
     messagebus.subscribe(topic, callback)
예제 #6
0
#Copyright Daniel Black 2013
#This file is part of Kaithem Automation.

#Kaithem Automation 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, version 3.

#Kaithem Automation 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 Kaithem Automation.  If not, see <http://www.gnu.org/licenses/>.

import messagebus,time
from config import config

keep_notifications = config['notifications-to-keep']
notificationslog =   []

def subscriber(topic,message):
    global notificationslog
    print(message)
    notificationslog.append((time.time(),topic,message))
    #Delete all but the most recent N notifications, where N is from the config file.
    notificationslog = notificationslog[-keep_notifications:] 
    
messagebus.subscribe('/system/notifications',subscriber)
예제 #7
0
 def subscribe(topic,callback ):
     messagebus.subscribe(topic,callback)