Beispiel #1
0
 def __init__(self, token, configFile):
     PlugIn.__init__(self)
     self.architecture = "all"
     self.override_dict ={}
     self.jid = Config.get("jabber","jid")
     global backend
     backend = Config.get("Defaults","backend")
     global scenario
     scenario = "default"
     #plugin itself
     self.content = Container("plugin", token, "This is a Defaults Plugin")
     self.content.addContainer("cmd","getBackend","getBackend", self.getBackend)
     for pair in Config.getSection("Defaults"):
         if pair[0].endswith('_plain'):
             title= pair[0].replace('_plain','')
             container = Container("cmd",title,pair[1],self.general)
             container.rendering = Container.PLAIN
         else:
             container = Container("cmd",pair[0],pair[1],self.general)
             container.setUseArgs(backend)
         self.content.addChild(container)
         
         #self.content.addContainer("cmd", pair[0], pair[1], use=self.general, args="test")
         
     self.content.addContainer("cmd","set","set",self.override)
     self.content.addContainer("cmd","setScenario","set a Scenario", self.setScenario)
     self.content.addContainer("cmd","getScenario", "get current Scenario", self.getScenario)
    def __init__(self, absPath):

        EventEngine.configFile = 'server.properties'
        EventEngine.root = Container("root", "root", "this is the root node")

        #print "initializing EventEngine..."
        EventEngine.root.addContainer("instance", Config.jid, "this is the tree instance "+Config.jid)

        # assign me node to Eventengine.root.me
        EventEngine.root.me = EventEngine.root.getChild(Config.jid)

        # generate all plugins
        p = PlugIns(Config.plugInsFolder, EventEngine.configFile).getChildList()

        # load plugin tree into me-node
        EventEngine.root.me.addChildList(p)

        # starting xmppEngine
        if Config.get("server", "jabber").__eq__("on"):
            print "starting xmppEngine"
            xmpp = XMPPEngineStart(EventEngine.root)
        else:
            print "jabber not active"

        # start webEngine
        if Config.get("server", "web").__eq__("on"):
            print "starting webEngine"
            webserver = WebEngine(EventEngine.root)
    def __init__(self, type, token, information="empty"):
        ThreadContainer.__init__(self, type, token, information="empty")
        self.lastval = 0
        self.information = information

        ##
        # Hardware Initialization
        ##

        try: #try:
            lib=Config.absPath+Config.get("avrBridge", "lib")
	    #print lib
            self.mega=cdll.LoadLibrary(lib)
            self.mega.initUsbLib()
            self.port = 1



            #print '!-!-!-!-! PLANTMONITOR sucessfully initialized'

            for tuple in Config.getSection("Plantmonitor"):
                tmpcont = Container("plugin", tuple[0], tuple[1])
                tmpcont.pin = tuple[1]
                tmpcont.setUse(self.leafuse)

                self.mega.setPortPinDir(self.port,tmpcont.pin,0)
                self.mega.setPortPin(self.port,tmpcont.pin,1)

                self.addChild(tmpcont)


        except Exception,e:
            print "[PLANTMONITOR ERROR] Could not init plugin\n"+str(e)
Beispiel #4
0
    def sched(self):

        d = Config.getSection("Scheduler")

	if not d == []:
            #print d
            while True:

                sleeptime = None
                for elem in d:
                    rhythm = eval(elem[1].split("|")[1])
                    # when has the thread to wake up next time for specific value?
                    tmp = rhythm - round(time.time()) % rhythm
                    if not sleeptime:
                        sleeptime = tmp
                    if sleeptime > tmp:
                        sleeptime = tmp

                time.sleep(sleeptime)

                execute = []
                for elem in d:
                    rhythm = eval(elem[1].split("|")[1])
                    if rhythm - round(time.time()) % rhythm == rhythm:
                        execute.append(elem)

                for elem in execute:
                    addr = Address(elem[1].split("|")[0])
                    print addr.__str__()
                    print EventEngine.root.getByAddress(addr.__str__()).use()
 def send(self):
     my_socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
     my_socket.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1)
     print 'start Broadcasting ...'
 
     while True :
         my_socket.sendto(Config.get("server", "token"), ('<broadcast>' , 8081))
         time.sleep(60)
Beispiel #6
0
    def __init__(self, token, configFile):
        PlugIn.__init__(self)
        self.architecture = "all"


        #plugin itself
        self.content = Container("plugin", token, "This is a global Status Plugin")
        self.content.logging = True

        # set add container
        

        if not Config.getSection('Global').__eq__(''):
            for pair in Config.getSection("Global"): 
                container = Container("cmd", pair[0], "global cmd" )
                container.setUse(self.getState,pair[1])
                self.content.addChild(container)
    def execAlarm():
        global alarmEvent
        alarmEvent = None
        print "ALARM ALARM"

        addr = Address(Config.get("AlarmClock", "exec"))
        print addr.__str__()
        print EventEngine.root.getByAddress(addr.__str__()).use()
        
        time.sleep(1)
        print AlarmClock.schedAlarm()
    def __init__(self, pluginsFolder, configFile):

        #absolute folder to plugins
        absPluginsFolder = Config.absPath + "/" + Config.get("Plugins", "PlugInsFolder")

        #creating list whrer all plugins are loaded in
        self.content = []

        # load all plugins into container
        print "loading all plugins..."
        self.content = self.loadPlugins(absPluginsFolder, pluginsFolder, configFile)

        print "loaded all plugins sucessfully"
Beispiel #9
0
    def __init__(self, token, configFile):
        PlugIn.__init__(self)
        self.architecture = "all"
        self.jid = Config.get("jabber","jid")
        #plugin itself
        self.content = Container("plugin", token, "This is a Sensors Plugin")
	cmd=""
        for pair in Config.getSection("Sensors"):
            if '?' in pair[1]:
            	tmp = pair[1].split('?')
            	self.content.arg = tmp[1].replace('string=','')
		cmd = tmp[0]
            else:
            	self.content.arg=""
            
            if pair[0].endswith('_plain'):
                title= pair[0].replace('_plain','')
                container = Container("cmd",title,pair[1],self.general)
                container.rendering = Container.PLAIN
            else:
                container = Container("cmd",pair[0],cmd,self.general)
            self.content.addChild(container)
    def __init__(self, token, configFile):
        PlugIn.__init__(self)
        self.architecture = "all"


        #plugin itself
        self.content = Container("plugin", token, "Filesystem Plugin")

        # load all items from config
        for pair in Config.getSection("Filesystem"):
            print "+-+"+Config.absPath
            print pair[0], pair[1]
            self.loadFilesystem(pair)
    def __init__(self, token, configFile):
        PlugIn.__init__(self)
        self.architecture = "macos"


        if self.architecture.__eq__(Config.get("server", "architecture")):

            # plugin itself
            self.content = avrContainer("plugin", token, "This hopefully will be a Threaded SoftKey  Plugin")
            self.content.rendering = Container.PLAIN
            self.content.start()

        else:
            self.content = Container("plugin", token, "not supported")
    def __init__(self, token, configFile):
        PlugIn.__init__(self)
        self.architecture = "all"

        #plugin itself
        self.content = Container("plugin", token, "this is a Prowl plugin")
		
		#get platform we're running on
	platform = Config.get('server','architecture')
		
	if (platform == "macos"):
        # set add container
        	self.content.addContainer("cmd","Prowl", "send Push notification", self.prowl)
        else:
        	import pynotify
        	self.content.addContainer("cmd","Ubuntu", "show Ubuntu Notification", self.unotify)
    def processRoster(self):

        self.rosterTree = {}

        self.roster = self.client.getRoster()

        # DIRTY!!!!
        XMPPEngine.roster = self.roster

        for elem in self.roster.getItems():
            if not self.rosterTree.has_key(elem) and not elem.__eq__(Config.get("jabber", "jid")):
                self.rosterTree[elem]=elem
                self.send("#type help to explore me.", elem)
                self.root.addChild(BuddyContainer("buddy", str(elem), "Buddy, maybe over the sea...", self.send))

                print elem
    def __init__(self, token, configFile):
        PlugIn.__init__(self)
        self.architecture = "all"
        
        global active, ringTime, wday, scheduler, alarmEvent
        wday = []
        alarmEvent = None
        #Read from Config
        active = AlarmClock.strToBool(Config.get("AlarmClock", "active"))
        ringTime = Config.get("AlarmClock", "time")
        wday.append(AlarmClock.strToBool(Config.get("AlarmClock", "monday")))
        wday.append(AlarmClock.strToBool(Config.get("AlarmClock", "tuesday")))
        wday.append(AlarmClock.strToBool(Config.get("AlarmClock", "wednesday")))
        wday.append(AlarmClock.strToBool(Config.get("AlarmClock", "thursday")))
        wday.append(AlarmClock.strToBool(Config.get("AlarmClock", "friday")))
        wday.append(AlarmClock.strToBool(Config.get("AlarmClock", "saturday")))
        wday.append(AlarmClock.strToBool(Config.get("AlarmClock", "sunday")))
        
        scheduler = sched.scheduler(time.time, time.sleep)
        AlarmClock.schedAlarm()

        #Build Tree
        #plugin itself
        self.content = Container("plugin", token, "Alarm Clock")
        #ON/OFF
        self.content.addChild(SwitchContainer("cmd", "TurnOnAlarm", "Turn On Alarm", self.toogleAlarm, on=Config.jid + "/AlarmClock/TurnOnAlarm?string=True", off=Config.jid + "/AlarmClock/TurnOnAlarm?string=False", checked=active))
        #Time
        self.content.addChild(TimefieldContainer("cmd", "Time", "Set Time", self.setTime, target=Config.jid + "/AlarmClock/Time", value=ringTime))
        #Days
        self.content.addChild(CheckBoxContainer("cmd", "Monday", "Alarm on Monday", self.checkMonday, toogle=Config.jid + "/AlarmClock/Monday", checked=wday[0]))
        self.content.addChild(CheckBoxContainer("cmd", "Tuesday", "Alarm on Tuesday", self.checkTuesday, toogle=Config.jid + "/AlarmClock/Tuesday", checked=wday[1]))
        self.content.addChild(CheckBoxContainer("cmd", "Wednesday", "Alarm on Wednesday", self.checkWednesday, toogle=Config.jid + "/AlarmClock/Wednesday", checked=wday[2]))
        self.content.addChild(CheckBoxContainer("cmd", "Thursday", "Alarm on Thursday", self.checkThursday, toogle=Config.jid + "/AlarmClock/Thursday", checked=wday[3]))
        self.content.addChild(CheckBoxContainer("cmd", "Friday", "Alarm on Friday", self.checkFriday, toogle=Config.jid + "/AlarmClock/Friday", checked=wday[4]))
        self.content.addChild(CheckBoxContainer("cmd", "Saturday", "Alarm on Saturday", self.checkSaturday, toogle=Config.jid + "/AlarmClock/Saturday", checked=wday[5]))
        self.content.addChild(CheckBoxContainer("cmd", "Sunday", "Alarm on Sunday", self.checkSunday, toogle=Config.jid + "/AlarmClock/Sunday", checked=wday[6]))
        #Save
        self.content.addContainer("cmd", "save", "save alarm", self.save)
    def __init__(self, token, configFile):
        PlugIn.__init__(self)
        self.architecture = "all"

        #plugin itself, is threaded uses the its process method
        self.content = ThreadContainer("plugin", token, "This hopefully will be a Threaded Feedreader Plugin") #ThreadContainer
        self.content.setDo(self.process)
        self.content.setUse(self.display)

        for touple in Config.getSection("FeedReader"):
            #t = touple.split(">")
            tmpcont = Container("plugin", touple[0], touple[1])
            #tmpcont.setUse(self.display)
            self.content.addChild(tmpcont)

        self.content.addContainer("cmd", "Random", "/FeedReader/mondayjazz", self.playRandom)

        self.content.start()
Beispiel #16
0
    def loadPlugins(self, PluginsPath, PackagePath, configFile):


        # get all elements in folder into list
        pluginFiles = os.listdir(PluginsPath)
        #print pluginFiles
        #print PluginsPath, PackagePath

        result = []

        for elem in pluginFiles:
            # add plugin files
            if elem[-3:].__eq__(".py") and not (elem[:1].__eq__("_")):
                print "*** loading: " + PackagePath + "." + elem
                #print("from "+PackagePath+"."+elem[:-3]+" import "+elem[:-3])

                try:
                    exec("from " + PackagePath + "." + elem[:-3] + " import " + elem[:-3])
                    #print("plugin = "+elem[:-3]+"(\""+elem[:-3]+"\", \""+configFile+"\")")
                    exec("plugin = " + elem[:-3] + "(\"" + elem[:-3] + "\", \"" + configFile + "\")")
                    #print("result.append(plugin.getTree())")
                    #print plugin.architecture


                    # If its a Master Plugin, it only should loaded by Masters, else, check architecture
                    if plugin.master == True:
                        #Check if it amiServer is configured as master
                        if Config.get("server", "master").__eq__("on"):
                            result.append(plugin.getTree())

                    elif plugin.architecture.__eq__("all") or plugin.architecture.__eq__(Config.architecture):
                        result.append(plugin.getTree())

                except Exception,e:
                    print "[PLUGIN ERROR] Counld not load Plugin", elem
                    print e

            # add folders as plugin
            if os.path.isdir(PluginsPath + "/" + elem):
                print "+++ loding folder: " + PluginsPath + "." + elem
                tmpcont = Container("folder", elem, "this is the tree representation of a folder")
                tmpcont.setUse(self.display)
                tmpcont.addChildList(self.loadPlugins(PluginsPath + "/" + elem, PackagePath + "." + elem, configFile))
                result.append(tmpcont)
    def __init__(self, token, configFile):
        PlugIn.__init__(self)
        self.architecture = "all"


        #plugin itself
        self.content = Container("plugin", token, "This is a Defaults Plugin")

        # add container, set information to standard-path from config
        #self.content.addContainer("cmd", "Play", Config.audioPlay, self.play)

	#self.content.addContainer("cmd", "Stop", Config.audioStop, self.stop)

        #self.content.addContainer("cmd", "SetVol", Config.setVol, self.setVol)

        #self.content.addContainer("cmd", "Notification", Config.setVol, self.notify)

        for pair in Config.getSection("Defaults"):
            self.content.addContainer("cmd", pair[0], pair[1], self.general)
    def __init__(self, token, configFile):
        PlugIn.__init__(self)
        # set plugins "hardware" architecture for system dependencies
        self.architecture = "all"

        # create plugin itself
        self.content = ThreadContainer("plugin", token, "Listening to Broadcasts for Client amiServers")
        
        if Config.get("server", "master").__eq__("on"):
            method = self.listen
            ThreadName = "ClientListener"
        else:
            method = self.send
            ThreadName = "Broadcaster"
            
            
        self.content.setDo(method)
        # dont know wheather it works, shold set the name of the thread
        self.content.name = ThreadName

        # start thread
        self.content.start()
Beispiel #19
0
    def __init__(self, type, token, information="empty"):
        ThreadContainer.__init__(self, type, token, information="empty")
        self.information = "hehehehe, arschloch"
        self.lastval = 0

        ##
        # Hardware Initialization
        ##

        try:
            lib=Config.absPath+Config.get("avrBridge", "lib")
	    print lib
            self.mega=cdll.LoadLibrary(lib)

            self.mega.initUsbLib()

            # init poti
            self.mega.setPortPinDir(1,1,0)
            self.mega.setPortPin(1,1,1)

            # set pins input
            self.mega.setPortPinDir(0,0,0)
            self.mega.setPortPinDir(0,1,0)
            self.mega.setPortPinDir(0,2,0)

            # enable internal pullup
            self.mega.setPortPin(0,0,1)
            self.mega.setPortPin(0,1,1)
            self.mega.setPortPin(0,2,1)

            #LED output
            self.mega.setPortPinDir(2,7,1)

            # light up the led
            self.mega.setPortPin(2,7,1)
	except Exception,e:
            print "[SOFTKEY ERROR] Could not init plugin\n"+str(e)
 def stop(self, string=""):
     os.system(Config.get("iTunes", "scriptpath")+" stop")
 def vol_down(self, string=""):
     os.system(Config.get("iTunes", "scriptpath")+" vol down")
 def vol_up(self, string=""):
     os.system(Config.get("iTunes", "scriptpath")+" vol up")
 def prev(self, string=""):
     os.system(Config.get("iTunes", "scriptpath")+" prev")
 def next(self, string=""):
     os.system(Config.get("iTunes", "scriptpath")+" next")
 def pause(self, string=""):
     os.system(Config.get("iTunes", "scriptpath")+" pause")
 def play(self, string=""):
     os.system(Config.get("iTunes", "scriptpath")+" play")
 def mute(self, string=""):
     os.system(Config.get("iTunes", "scriptpath")+" mute")
 def unotify(self, text="Notification"):
     text = self.getText(text)
     pynotify.init(Config.get('server', 'token'))
     n=pynotify.Notification(Config.get('server', 'token'), text)
     n.show()
     return text
Beispiel #29
0
    def element(self, var=''):
        #declarations
        file_name = 'MyEstate'
        requestArray = {}
        
        #open and parse the file 
        try:
            file = codecs.open(Config.absPath + Config.get('XML', file_name), "r")
            xmlString = file.read()
            file.close()
            xml_object = parseString(xmlString)
        except:
            return "ERROR: FILE NOT FOUND"
        print var
        
        list = xml_object
        #building the json
        try:
            requestString = json.loads(var)
        except:
            return "ERROR: JSON SYNTAX"

        #filling the JSON into the requestArray
        for key, value in requestString.items():
            requestArray[key] = value
            print key + ': ' + value
            
        #if level is defined
        if requestArray.has_key('l'):
            #searching the levels
            for level in xml_object.getElementsByTagName('level'):
                #if requested id is in xml
                if int(requestArray['l']) >= int(xml_object.getElementsByTagName('level').length):
                    return "ERROR: OUT OF RANGE"
                #if level id == requested id
                elif level.getElementsByTagName('id')[0].firstChild.data == requestArray['l']:
                    #print level id and name to the console
                    print 'level ' + level.getElementsByTagName('id')[0].firstChild.data + ": " + level.getElementsByTagName('name')[0].firstChild.data
                    list = level
                    #if room is defined
                    if requestArray.has_key('r'):
                        #searching the rooms on the requested level
                        for room in level.getElementsByTagName('room'):
                            #if requested id is in xml
                            if int(requestArray['r']) >= int(level.getElementsByTagName('room').length):
                                return "ERROR: OUT OF RANGE"
                            #if level id == requested id 
                            elif room.getElementsByTagName('id')[0].firstChild.data == requestArray['r']:
                                #print room id and name to the console
                                print 'room ' + room.getElementsByTagName('id')[0].firstChild.data + ": " + room.getElementsByTagName('name')[0].firstChild.data
                                list = room
                                #if device is defined
                                if requestArray.has_key('d'):
                                    #searching the devices
                                    for device in room.getElementsByTagName('device'):
                                        #if requested id is in xml
                                        if int(requestArray['d']) >= int(room.getElementsByTagName('device').length):
                                            return "ERROR: OUT OF RANGE"
                                        #if device id == requested id 
                                        elif device.getElementsByTagName('id')[0].firstChild.data == requestArray['d']:
                                            #print device id and name to the console
                                            print 'device ' + device.getElementsByTagName('id')[0].firstChild.data + ": " + device.getElementsByTagName('name')[0].firstChild.data
                                            list = device
                                            #if state is defined
                                            if requestArray.has_key('s'):
                                                #searching the state
                                                for state in device.getElementsByTagName('state'):
                                                    #if requested id is in xml
                                                    if int(requestArray['s']) >= int(device.getElementsByTagName('state').length):
                                                        return "ERROR: OUT OF RANGE"
                                                    #if state id == requested id
                                                    elif state.getElementsByTagName('id')[0].firstChild.data == requestArray['s']:
                                                            #print state id and dimension to the console
                                                            print 'state ' + state.getElementsByTagName('id')[0].firstChild.data
                                                            list = state
  
        print 'old value'
        print requestArray['e'] + ': ' + list.getElementsByTagName(requestArray['e'])[0].firstChild.data
        list.getElementsByTagName(requestArray['e'])[0].firstChild.data = requestArray['nv']
        
        print 'new value'
        print requestArray['e'] + ': ' + list.getElementsByTagName(requestArray['e'])[0].firstChild.data
        
        #try to open the file and write new data
        try:
            file = open(Config.absPath + Config.get('XML', file_name), "w")
            print 'open file'
            tmp = xml_object.toxml()
            print 'object parsed'
            file.write(tmp)
            print 'file written'
            file.close()
            print 'file closed'
        except:
            return 'ERROR: NOTHING WRITTEN'
        
        print "SUCCESSFUL"
        return "SUCCESSFUL"     
Beispiel #30
0
 def saveEnergy(timestamp, level, room, device, watt):
     #declarations
     level = 'level'+level
     room = 'room'+room
     device = 'device'+device   
     #time the device was on         
     hours = float(time.mktime(time.localtime()) - time.mktime(timestamp)) / 3600.0
     kw = float(watt) / 1000.0
     kwh = float(kw * hours)
     #e.g. Jan-2010
     currentMonth = str(time.strftime("%b-%Y",time.localtime()))
     
     #if the level node is in energy.xml
     if str(energy_object.getElementsByTagName(level)) != '[]':
         print 'level'
         #link the level node
         levelNode = energy_object.getElementsByTagName(level)[0]
         #and so on....
         if str(levelNode.getElementsByTagName(room)) != '[]':
             print 'room'
             roomNode = levelNode.getElementsByTagName(room)[0]
             if str(roomNode.getElementsByTagName(device)) != '[]':
                 print 'device'
                 deviceNode = roomNode.getElementsByTagName(device)[0]
                 if str(deviceNode.getElementsByTagName(currentMonth)) != '[]':
                     print 'month'
                     monthNode = deviceNode.getElementsByTagName(currentMonth)[0]
                     #adds the new kwh to the old value
                     monthNode.firstChild.data = float(monthNode.firstChild.data) + float(kwh)
                     print str(kwh) + ' kWh added'
                 else:
                     #create month with kwh
                     print 'no month'
                     newElement(deviceNode, currentMonth, str(kwh))
             else:
                 #create device, month with kwh
                 print 'no device'
                 newElement(roomNode, device, '')
                 deviceNode = roomNode.getElementsByTagName(device)[0]
                 newElement(deviceNode, currentMonth, str(kwh))
         else:
             #create room, device, month with kwh
             print 'no room'
             newElement(levelNode, room, '')   
             roomNode = levelNode.getElementsByTagName(room)[0]    
             newElement(roomNode, device, '')
             deviceNode = roomNode.getElementsByTagName(device)[0]
             newElement(deviceNode, currentMonth, str(kwh))
     else:
         #create level, room, device, month with kwh
         print 'no level'
         newElement(energy_object.firstChild, level, '')
         levelNode = energy_object.getElementsByTagName(level)[0]
         newElement(levelNode, room, '')   
         roomNode = levelNode.getElementsByTagName(room)[0]    
         newElement(roomNode, device, '')
         deviceNode = roomNode.getElementsByTagName(device)[0]
         newElement(deviceNode, currentMonth, str(kwh))
         
     #save file
     try:
         energy_file = open(Config.absPath + Config.get('XML', 'Energy'), "w")
         print 'open'
         tmp1 = energy_object.toxml()
         print 'new'
         energy_file.write(tmp1)
         print 'written'
         energy_file.close()
         print 'closed'
     except:
         return 'ERROR: NOTHING WRITTEN'
     
     return ''