예제 #1
0
#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):
예제 #2
0
#!/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
예제 #3
0
파일: commands.py 프로젝트: bcho/msgQ
#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 = []