Commit ab1b4fad authored by Federico Sismondi's avatar Federico Sismondi

added new utils like exceptions, fixed imports to allow run libs as external...

added new utils like exceptions, fixed imports to allow run libs as external libs and also from __main__
parent 4026ee7c
import os
import pika
from messages import *
VERSION = '0.0.5'
# for using it as library and as a __main__
try:
from messages import *
except:
from .messages import *
VERSION = '0.0.6'
AMQP_EXCHANGE = 'amq.topic'
def publish_message(connection, message):
""" Published which uses message object metadata
:param channel:
:param message:
:return:
"""
Publishes message into the correct topic (uses Message object metadata)
Creates temporary channel on it's own
Connection must be a pika.BlockingConnection
"""
channel = None
......@@ -33,7 +37,13 @@ def publish_message(connection, message):
def amqp_request(connection, request_message, component_id):
# NOTE: channel must be a pika channel
"""
Publishes message into the correct topic (uses Message object metadata)
Returns reply message.
Uses reply_to and corr id amqp's properties for matching the reply
Creates temporary channel, and queues on it's own
Connection must be a pika.BlockingConnection
"""
# check first that sender didnt forget about reply to and corr id
assert request_message.reply_to
......
This diff is collapsed.
class CoordinatorError(Exception):
def __init__(self, message):
self.message = message
def __str__(self):
"""Return the exception message"""
return self.message
class TestSuiteError(Exception):
def __init__(self, message):
self.message = message
def __str__(self):
"""Return the exception message"""
return self.message
class SnifferError(Exception):
def __init__(self, message):
self.message = message
def __str__(self):
"""Return the exception message"""
return self.message
class TatError(Exception):
def __init__(self, message):
self.message = message
def __str__(self):
"""Return the exception message"""
return self.message
class AmqpMessageError(Exception):
def __init__(self, message):
self.message = message
def __str__(self):
"""Return the exception message"""
return self.message
class ApiMessageFormatError(Exception):
def __init__(self, message):
self.message = message
def __str__(self):
"""Return the exception message"""
return self.message
......@@ -5,8 +5,14 @@ import signal
import shutil
import logging
from datetime import datetime
from messages import *
from pure_pcapy import Dumper, Pkthdr, DLT_RAW, DLT_IEEE802_15_4_NOFCS
# use this as main and also lib:
try:
from messages import *
from pure_pcapy import Dumper, Pkthdr, DLT_RAW, DLT_IEEE802_15_4_NOFCS
except:
from .messages import *
from .pure_pcapy import Dumper, Pkthdr, DLT_RAW, DLT_IEEE802_15_4_NOFCS
try:
# For Python 3.0 and later
......@@ -18,7 +24,7 @@ except ImportError:
logger = logging.getLogger(__name__)
VERSION = '0.0.1'
VERSION = '0.0.2'
def launch_amqp_data_to_pcap_dumper(amqp_url=None, amqp_exchange=None, topics=None, dump_dir=None):
def signal_int_handler(self, frame):
......@@ -54,15 +60,11 @@ def launch_amqp_data_to_pcap_dumper(amqp_url=None, amqp_exchange=None, topics=No
# load default values
amqp_url = "amqp://{0}:{1}@{2}/{3}".format("guest", "guest", "localhost", "/")
if topics:
pcap_amqp_topic_subscriptions = topics
else:
pcap_amqp_topic_subscriptions = ['data.serial.fromAgent.coap_client_agent',
'data.serial.fromAgent.coap_server_agent',
'data.tun.fromAgent.coap_server_agent',
'data.tun.fromAgent.coap_client_agent',
]
pcap_amqp_topic_subscriptions = ['data.tun.fromAgent.*',
'data.serial.fromAgent.*']
# init pcap_dumper
pcap_dumper = AmqpDataPacketDumper(
......@@ -298,7 +300,6 @@ class AmqpDataPacketDumper:
else:
logger.info('drop amqp message: ' + repr(m))
except NonCompliantMessageFormatError as e:
print('* * * * * * API VALIDATION ERROR * * * * * * * ')
print("AMQP MESSAGE LIBRARY COULD PROCESS JSON MESSAGE")
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment