def __init__(self, producer, raw_source, header):
     print('initing {}'.format(self.__class__))
     self._producer = producer
     self._is_commander = False
     self._raw_telemetry_source = raw_source
     self._command_parser = CommandParser()
     self._header = header
Example #2
0
def main():
    # parse arguments and get command
    parser = CommandParser()
    command = parser.parse(sys.argv[1:])

    # execute command
    invoker = CommandInvoker()
    invoker.invoke(command)
class ServeTelemetry(LineReceiver):
    """Serve the telemetry"""
    def __init__(self, producer, raw_source, header):
        print('initing {}'.format(self.__class__))
        self._producer = producer
        self._is_commander = False
        self._raw_telemetry_source = raw_source
        self._command_parser = CommandParser()
        self._header = header

    def connectionMade(self):
        self.proxy = ProducerConsumerBufferProxy(self._producer, self)
        self.transport.registerProducer(self.proxy, True)
        self.proxy.write(self._header + '\r\n')
        self.proxy.resumeProducing()

    def lineReceived(self, line):
        print('from {} received line {}'.format(self.transport.getPeer(),
                                                line))
        if line == 'commander':
            self._is_commander = True
            self._command_parser
        elif self._is_commander:
            valid, command = self._command_parser.parse_command(line.rstrip())
            if valid:
                self._raw_telemetry_source.async_tx(command)
            else:
                print('command not valid')

    def connectionLost(self, reason):
        print('connection lost from {}'.format(self.transport.getPeer()))
        self.transport.unregisterProducer()
 def __init__(self, producer, raw_source, header):
     print('initing {}'.format(self.__class__))
     self._producer = producer
     self._is_commander = False
     self._raw_telemetry_source = raw_source
     self._command_parser = CommandParser()
     self._header = header
class ServeTelemetry(LineReceiver):
    """Serve the telemetry"""
    def __init__(self, producer, raw_source, header):
        print('initing {}'.format(self.__class__))
        self._producer = producer
        self._is_commander = False
        self._raw_telemetry_source = raw_source
        self._command_parser = CommandParser()
        self._header = header

    def connectionMade(self):
        self.proxy = ProducerConsumerBufferProxy(self._producer, self)
        self.transport.registerProducer(self.proxy, True)
        self.proxy.write(self._header+'\r\n')
        self.proxy.resumeProducing()

    def lineReceived(self, line):
        print('from {} received line {}'.format(
            self.transport.getPeer(), line))
        if line == 'commander':
            self._is_commander = True
            self._command_parser
        elif self._is_commander:
            valid, command = self._command_parser.parse_command(line.rstrip())
            if valid:
                self._raw_telemetry_source.async_tx(command)
            else:
                print('command not valid')


    def connectionLost(self, reason):
        print('connection lost from {}'.format(self.transport.getPeer()))
        self.transport.unregisterProducer()
Example #6
0
def main():
    opts = cmd_opt_parse()

    multi_cmd_patterns, key_patterns = fetch_cmd_patterns(
        opts.pattern, opts.pattern_file, opts.pattern_sep)

    ofname = opts.output if opts.output else opts.input + '.fetch'
    of = open(ofname, 'w')
    readable_fname = opts.readable if opts.readable else \
        opts.input + '.fetch_readable'
    readable_f = open(readable_fname, 'w')
    filtered_fname = opts.filtered if opts.filtered else \
        opts.input + '.filtered'
    filtered_f = open(filtered_fname, 'w')
    filtered_rfname = opts.input + '.filtered_readable'
    filtered_rf = open(filtered_rfname, 'w')

    # fetch all commands on the specified keys
    matched_cmds = []
    with open(opts.input) as f:
        cmd_parser = CommandParser(f)

        # iterate each command in AOF
        for cmds, raw_buf in cmd_parser:
            key = cmds[1]

            for key_pattern in key_patterns:
                if not key_pattern.match(key):
                    continue

                matched_cmds.append((cmds, raw_buf))

    # filter specified commands
    for cmds, raw_buf in matched_cmds:
        old_part_num = len(cmds)
        matched, skip = match_and_filter_cmds(cmds, multi_cmd_patterns,
                                              filtered_f, filtered_rf)
        if matched:
            output_f = filtered_f
            output_readable_f = filtered_rf
        else:
            output_f = of
            output_readable_f = readable_f

        if not skip:
            if old_part_num != len(cmds):
                raw_buf = format_cmd_buf(cmds)

            write_array(raw_buf, output_f)
            output_readable_f.write(' '.join(cmds) + '\n')

    of.close()
    readable_f.close()
    filtered_f.close()
Example #7
0
def main():
    opts = cmd_opt_parse()

    conn = redis.StrictRedis(opts.host, opts.port)

    with open(opts.input) as f:
        parser = CommandParser(f)

        for cmd_detail, _ in parser:
            cmd = cmd_detail[0].lower()
            if cmd == 'del':
                cmd = 'delete'

            func = getattr(conn, cmd)

            # redo command
            func(*cmd_detail[1:])
Example #8
0
class Vision:
    online = False
    spot_handler = SpotifyHandler()
    desktop_handler = DesktopHandler("Programs")
    speech_handler = SpeechHandler(desktop_handler)
    command_parser = CommandParser()
    settings_handler = SettingsHandler()
    search_handler = SearchHandler()

    def start(self):
        self.online = True
        self.settings_handler.load_settings("settings.json")
        self.command_parser.get_command_file("commands.json")
        self.speech_handler.listen(self)

    def stop(self):
        print("Vision shutting down...")
        self.settings_handler.save_settings()
        self.online = False
def main():
    opts = cmd_opt_parse()

    multi_cmd_patterns, _ = fetch_cmd_patterns(opts.pattern, opts.pattern_file,
                                               opts.pattern_sep)

    ofname = opts.output if opts.output else opts.input + '.new'
    of = open(ofname, 'w')
    filtered_fname = opts.filtered if opts.filtered else \
        opts.input + '.filtered'
    filtered_f = open(filtered_fname, 'w')
    readable_fname = opts.readable if opts.readable else \
        opts.input + '.filtered_readable'
    readable_f = open(readable_fname, 'w')

    with open(opts.input) as f:
        cmd_parser = CommandParser(f)

        for cmds, raw_buf in cmd_parser:
            old_part_num = len(cmds)
            matched, skip = match_and_filter_cmds(cmds, multi_cmd_patterns,
                                                  filtered_f, readable_f)
            if matched:
                output_file = filtered_f
                if not skip:
                    readable_f.write(' '.join(cmds) + '\n')
            else:
                output_file = of

            if not skip:
                if old_part_num != len(cmds):
                    raw_buf = format_cmd_buf(cmds)

                write_array(raw_buf, output_file)

    of.close()
    filtered_f.close()
    readable_f.close()
Example #10
0
from network import NetworkManager, ClientDisconnected
from response import Response
from error import ParseError, ExecutionError, ValidationError
from http import HTTPStatus
from commands.disconnect import Disconnect
from controller import Controller
from configparser import ConfigParser
from logging.handlers import RotatingFileHandler
from logging import Formatter, basicConfig, getLogger, StreamHandler

if __name__ == '__main__':

    config = ConfigParser()
    config.read('../config.ini')
    network_manager = NetworkManager(config)
    parser = CommandParser()

    # Logging configuration
    level = config['LOGGING'].get('level', 'ERROR')
    log_on_console = config['LOGGING'].get('console', False)
    log_on_console = log_on_console == '1' or log_on_console == 'True' or log_on_console == 'true'
    filename = config['LOGGING'].get('filename', '/var/log/sc_driver.log')
    max_bytes = int(config['LOGGING'].get('max_bytes', str(1024 * 1024)))
    backup_count = int(config['LOGGING'].get('backup_count', str(5)))
    log_format = '%(asctime)s - %(name)s - %(levelname)s -- %(message)s'
    formatter = Formatter(log_format)
    fileHandler = RotatingFileHandler(filename, maxBytes=max_bytes, backupCount=backup_count)
    consoleHandler = StreamHandler()
    consoleHandler.setFormatter(formatter)
    fileHandler.setFormatter(formatter)
    handlers = [fileHandler, consoleHandler] if log_on_console else [fileHandler]
Example #11
0
def clean_shutdown(sig, frame):
    logger.info("Server shutting down")
    for t in thread_pool:
        t.stop()

    jserver.close()

    for t in thread_pool:
        t.join()

    logging.shutdown()
    sys.exit(0)


signal.signal(signal.SIGINT, clean_shutdown)

while True:
    jsock = jserver.accept()

    # Add log message with ip from connected client

    cmd_thread = CommandParser(jsock, cmd_queue, control_thread)
    cmd_thread.start()

    #response_thread = MessageDispatcher(jsock, response_queue)
    #response_thread.start()

    thread_pool.append(cmd_thread)
    #thread_pool.append(response_thread)
    thread_pool = [t for t in thread_pool if t.is_alive()]
Example #12
0
#!/usr/bin/python

import sys
import getopt
import wx
from command import CommandParser
from ui.ui import MainWindow
import core
import uml
from core.model import Database
from misc import *

# Command line arguments:
paramDescriptor = parseParameters(sys.argv[0], sys.argv[1:])
db = Database()
commandsToExecute = []
if paramDescriptor[PARAM_INPUTFILESET]:
    print ("Loading input file %s." % paramDescriptor[PARAM_INPUTFILENAME])
    commandsToExecute = loadCommandsFromFile(paramDescriptor[PARAM_INPUTFILENAME])

cp = CommandParser(db, commandsToExecute)
app = wx.App(0)
MainWindow(None, -1, 'RapidBreeze', cp)
app.MainLoop()
cp.stop()