|
From: <ni...@us...> - 2010-11-11 14:49:08
|
Revision: 108
http://openautomation.svn.sourceforge.net/openautomation/?rev=108&view=rev
Author: nilss1
Date: 2010-11-11 14:49:01 +0000 (Thu, 11 Nov 2010)
Log Message:
-----------
add scheduler support
Modified Paths:
--------------
PyWireGate/trunk/WireGate.py
Added Paths:
-----------
PyWireGate/trunk/scheduler.py
Modified: PyWireGate/trunk/WireGate.py
===================================================================
--- PyWireGate/trunk/WireGate.py 2010-11-11 14:48:26 UTC (rev 107)
+++ PyWireGate/trunk/WireGate.py 2010-11-11 14:49:01 UTC (rev 108)
@@ -28,7 +28,9 @@
import ConfigParser
import datastore
+import scheduler
+
class WireGate(daemon.Daemon):
def __init__(self,REDIRECTIO=False):
self._parent = self
@@ -47,7 +49,6 @@
## Start the Datastore
self.DATASTORE = datastore.datastore(self)
-
## Start the Daemon
daemon.Daemon.__init__(self,self.config['WireGate']['pidfile'],REDIRECTIO)
@@ -138,6 +139,10 @@
except:
self.WG.errorlog(connector)
pass
+
+ ## Start the Sheduler
+ self.SCHEDULER = scheduler.scheduler(self)
+ self.SCHEDULER.start()
if os.getuid() == 0:
import pwd
@@ -186,6 +191,8 @@
#for dobj in self.DATASTORE.dataobjects.keys():
# print dobj+": "+str(self.DATASTORE.dataobjects[dobj].getValue())
self.log("### Shutdown WireGated ###")
+
+ self.SCHEDULER.shutdown()
for instance in self.connectors.keys():
try:
self.connectors[instance].shutdown()
Added: PyWireGate/trunk/scheduler.py
===================================================================
--- PyWireGate/trunk/scheduler.py (rev 0)
+++ PyWireGate/trunk/scheduler.py 2010-11-11 14:49:01 UTC (rev 108)
@@ -0,0 +1,88 @@
+# -*- coding: iso8859-1 -*-
+## -----------------------------------------------------
+## Cycler
+## -----------------------------------------------------
+## Copyright (c) 2010, knx-user-forum e.V, All rights reserved.
+##
+## This program 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; either
+## version 3 of the License, or (at your option) any later version.
+##
+## This program 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 this program;
+## if not, see <http://www.gnu.de/documents/gpl-3.0.de.html>.
+
+import time
+import sys
+from datetime import datetime
+try:
+ from apscheduler.scheduler import Scheduler as apscheduler
+except ImportError:
+ print >> sys.stderr, "apt-get install python-apscheduler"
+ sys.exit(1)
+
+
+
+class scheduler:
+ def __init__(self,parent):
+ self._parent = parent
+ if parent:
+ self.WG = parent.WG
+ self.SCHEDULER = apscheduler()
+
+ def start(self):
+ self.load()
+ self.log("SCHEDULER starting up")
+ self.SCHEDULER.start()
+
+ def load(self):
+ schedules = filter(lambda x: x.startswith("SCHEDULER:"),self.WG.DATASTORE.dataobjects.keys())
+ for shed in schedules:
+ obj = self.WG.DATASTORE.dataobjects[shed]
+ if 'cron' in obj.config:
+ kwargs = {}
+ for uoption in obj.config['cron'].keys():
+ kwargs[str(uoption)] = str(obj.config['cron'][uoption])
+
+ print "Adding %s - %r" % (shed,obj)
+ setattr(obj.sendConnected.im_func,'__name__',"%s" % shed.encode('UTF-8'))
+ self.SCHEDULER.add_cron_job(self.WG.DATASTORE.dataobjects[shed].sendConnected,**kwargs)
+
+ def shutdown(self):
+ print self.SCHEDULER.dump_jobs()
+ self.SCHEDULER.shutdown()
+
+ def debug(self,msg):
+ self.log(msg,'debug')
+
+
+ ## Central logging
+ def log(self,msg,severity='info',instance=False):
+ self.WG.log(msg,severity,"scheduler")
+
+
+if __name__ == '__main__':
+ s = scheduler(False)
+ time.sleep(155)
+ s.shutdown()
+
+
+## "SHEDULER:cron_job-001": {
+## "config": {
+## "cron" : {
+## "day_of_week" : "mon-fri",
+## "hour" : "8",
+## "minute" : "30"
+## }
+##
+## },
+## "connected": [ "KNX:14/1/50" ],
+## "id": "cron_job-001",
+## "lastupdate": 0,
+## "name": "Test Cronjob weekday 8:30",
+## "value": 1
+## }
+
\ No newline at end of file
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|