forked from jinglemansweep/MHub
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Performance improvements and a couple of extra plugins
- Loading branch information
1 parent
68ae5e7
commit b2a8ab2
Showing
10 changed files
with
181 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,3 +3,5 @@ | |
MANIFEST | ||
build | ||
dist | ||
#*# | ||
*~ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import datetime | ||
import fnmatch | ||
|
||
class Plugin(object): | ||
|
||
""" Events plugin """ | ||
|
||
def __init__(self, cfg, producer, logger): | ||
|
||
""" Constructor """ | ||
|
||
self.name = "events" | ||
self.description = "Event management plugin" | ||
self.author = "MHub" | ||
self.cfg = cfg | ||
self.producer = producer | ||
self.logger = logger | ||
self.tasks = list() | ||
|
||
|
||
def on_message(self, data, message): | ||
|
||
""" On AMQP message handler """ | ||
|
||
action, params = data.get("action"), data.get("params") | ||
|
||
self.process_events(action, params) | ||
|
||
|
||
def on_init(self): | ||
|
||
""" On Init """ | ||
|
||
self.events = self.cfg.get("events", list()) | ||
|
||
|
||
def process_events(self, action, params): | ||
|
||
""" Event processor helper """ | ||
|
||
for name, event in self.events.iteritems(): | ||
|
||
triggers = event.get("triggers", list()) | ||
actions = event.get("actions", list()) | ||
|
||
match = False | ||
|
||
for trigger in triggers: | ||
|
||
if fnmatch.fnmatch(action, trigger): | ||
match = True | ||
break | ||
|
||
if match: | ||
|
||
for action in actions: | ||
|
||
self.producer.publish({ | ||
"action": action.get("action"), | ||
"params": action.get("params", dict()) | ||
}) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import datetime | ||
import fnmatch | ||
|
||
class Plugin(object): | ||
|
||
""" Notify Plugin """ | ||
|
||
def __init__(self, cfg, producer, logger): | ||
|
||
""" Constructor """ | ||
|
||
self.name = "notify" | ||
self.description = "Notifications (libnotify)" | ||
self.author = "MHub" | ||
self.cfg = cfg | ||
self.producer = producer | ||
self.logger = logger | ||
self.tasks = list() | ||
|
||
|
||
def on_message(self, data, message): | ||
|
||
""" On AMQP message handler """ | ||
|
||
action, params = data.get("action"), data.get("params") | ||
|
||
if self.matches_patterns(action): | ||
|
||
title = params.get("title", "") | ||
message = params.get("message", "") | ||
|
||
try: | ||
import pynotify | ||
if pynotify.init("MHub"): | ||
n = pynotify.Notification(title, message) | ||
n.show() | ||
except: | ||
pass | ||
|
||
|
||
def on_init(self): | ||
|
||
""" On Init """ | ||
|
||
self.patterns = self.cfg.get("patterns", list("*")) | ||
|
||
|
||
def matches_patterns(self, action): | ||
|
||
match = False | ||
|
||
for pattern in self.patterns: | ||
match = fnmatch.fnmatch(action, pattern) | ||
if match: break | ||
|
||
return match |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters