#coding: utf-8 ''' msgQ.commands ''' import logging from msgQ import config logger = logging.getLogger('msgQ') subscribers = config.load().get('commands', []) def _topic_cmp(key, topic): key = [_.strip() for _ in key.split('.')] topic = [_.strip() for _ in topic.split('.')] if len(key) > len(topic): return False for i in xrange(len(key)): if key[i] != topic[i] and key[i] != '*' and topic[i] != '*': return False return True def get_commands(topic): logger.debug('Checking commands for %s' % (topic, )) commands = [] for sub in subscribers: if sub.get('activate', True) and _topic_cmp(sub['topic'], topic):
#!/usr/bin/env python import socket import json from msgQ import config _config = config.load() def send(msg, topic='*', mod='*'): recv = None try: sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) sock.connect((_config['address'], _config['port'])) message = dict(msg=msg, topic=topic, mod=mod) sock.send(json.dumps(message) + '\n') recv = sock.recv(1024) finally: sock.close() return recv
#coding: utf-8 ''' msgQ.commands ''' import logging from msgQ import config logger = logging.getLogger('msgQ') subscribers = config.load().get('commands', []) def _topic_cmp(key, topic): key = [_.strip() for _ in key.split('.')] topic = [_.strip() for _ in topic.split('.')] if len(key) > len(topic): return False for i in xrange(len(key)): if key[i] != topic[i] and key[i] != '*' and topic[i] != '*': return False return True def get_commands(topic): logger.debug('Checking commands for %s' % (topic, )) commands = []