]>
git.ipfire.org Git - oddments/cappie.git/blob - cappie/events.py
2 ###############################################################################
5 # Copyright (C) 2010 Michael Tremer #
7 # This program is free software: you can redistribute it and/or modify #
8 # it under the terms of the GNU General Public License as published by #
9 # the Free Software Foundation, either version 3 of the License, or #
10 # (at your option) any later version. #
12 # This program is distributed in the hope that it will be useful, #
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of #
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
15 # GNU General Public License for more details. #
17 # You should have received a copy of the GNU General Public License #
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. #
20 ###############################################################################
29 def __init__(self
, interface
):
30 self
.cappie
= interface
.cappie
31 self
.interface
= interface
32 self
.log
= interface
.log
33 self
.db
= self
.cappie
.db
36 return self
.__class
__.__name
__
38 def addEvent(self
, event
):
39 return self
.cappie
.queue
.add(event
)
42 raise NotImplementedError
45 class EventShell(Event
):
49 def __init__(self
, interface
, script
):
50 Event
.__init
__(self
, interface
)
55 args
= " ".join([self
.script
, self
.interface
.dev
])
58 self
.log
.debug("Running: %s" % args
)
60 p
= subprocess
.Popen(args
,
63 stdin
=open("/dev/null", "r"),
64 stdout
=subprocess
.PIPE
,
65 stderr
=subprocess
.STDOUT
)
67 while p
.poll() is None:
68 time
.sleep(self
.heartbeat
)
69 if (time
.time() - start
) > self
.timeout
:
74 raise EventTimeout
, "Script took too long to return"
76 for line
in p
.stdout
.read().splitlines():
78 self
.log
.debug(" %s" % line
)
80 self
.cappie
.log
.debug("Child process returned with exit code: %s" % \