Example #1
0
    prog="bw_client.py",
    description="""BOSWatch is a Python Script to receive and
                                 decode german BOS information with rtl_fm and multimon-NG""",
    epilog="""More options you can find in the extern client.ini
                                 file in the folder /config""")
parser.add_argument("-c",
                    "--config",
                    help="Name to configuration File",
                    required=True)
parser.add_argument("-t",
                    "--test",
                    help="Start Client with testdata-set",
                    action="store_true")
args = parser.parse_args()

bwConfig = ConfigYAML()
if not bwConfig.loadConfigFile(paths.CONFIG_PATH + args.config):
    logging.error("cannot load config file")
    exit(1)

# ========== CLIENT CODE ==========
bwClient = None
inputSource = None
inputQueue = queue.Queue()

try:
    ip = bwConfig.get("server", "ip", default="127.0.0.1")
    port = bwConfig.get("server", "port", default="8080")

    if bwConfig.get("client", "useBroadcast", default=False):
        broadcastClient = BroadcastClient()
Example #2
0
def getFilledConfig():
    """!Build a config object and fill it with the config data"""
    filledConfig = ConfigYAML()
    assert filledConfig.loadConfigFile(paths.TEST_PATH +
                                       "test_config.yaml") is True
    return filledConfig
Example #3
0
def getConfig():
    """!Build a config object"""
    return ConfigYAML()
Example #4
0
    def buildRouters(self, config):
        """!Initialize Routers from given config file

        @param config: instance of ConfigYaml class
        @return True or False"""
        self._routerDict = {
        }  # all routers and instances of modules/plugins would be destroyed
        routerDict_tmp = {}
        logging.debug("build routers")

        # first we have to init all routers
        # because a router can be a valid target and we need his reference
        for router in config.get("router"):
            if router.get("name") is None or router.get("route") is None:
                logging.error("name or route not found in router: %s", router)
                return False
            if router.get("name") in self._routerDict:
                logging.error("duplicated router name: %s", router.get("name"))
                return False
            routerDict_tmp[router.get("name")] = Router(router.get("name"))

        for router in config.get("router"):
            routerName = router.get("name")

            for route in router.get("route"):
                routeType = route.get("type")
                routeRes = route.get("res")
                routeName = route.get("name", default=routeRes)

                routeConfig = route.get(
                    "config",
                    default=ConfigYAML())  # if no config - build a empty

                if routeType is None or routeRes is None:
                    logging.error("type or name not found in route: %s", route)
                    return False

                try:
                    if routeType == "plugin":
                        importedFile = importlib.import_module(routeType +
                                                               "." + routeRes)
                        loadedClass = importedFile.BoswatchPlugin(routeConfig)
                        routerDict_tmp[routerName].addRoute(
                            Route(routeName, loadedClass._run,
                                  loadedClass._getStatistics,
                                  loadedClass._cleanup))

                    elif routeType == "module":
                        importedFile = importlib.import_module(routeType +
                                                               "." + routeRes)
                        loadedClass = importedFile.BoswatchModule(routeConfig)
                        routerDict_tmp[routerName].addRoute(
                            Route(routeName, loadedClass._run,
                                  loadedClass._getStatistics,
                                  loadedClass._cleanup))

                    elif routeType == "router":
                        routerDict_tmp[routerName].addRoute(
                            Route(routeName,
                                  routerDict_tmp[routeRes].runRouter))

                    else:
                        logging.error("unknown type '%s' in %s", routeType,
                                      route)
                        return False

                # except ModuleNotFoundError:  # only since Py3.6
                except ImportError:
                    logging.error("%s not found: %s", route.get("type"),
                                  route.get("res"))
                    return False

        logging.debug("finished building routers")
        self._routerDict = routerDict_tmp
        self._showRouterRoute()
        return True
Example #5
0
header.infoToLog()

# With -h or --help you get the Args help
parser = argparse.ArgumentParser(
    prog="bw_server.py",
    description="""BOSWatch is a Python Script to receive and
                                 decode german BOS information with rtl_fm and multimon-NG""",
    epilog="""More options you can find in the extern client.ini
                                 file in the folder /config""")
parser.add_argument("-c",
                    "--config",
                    help="Name to configuration File",
                    required=True)
args = parser.parse_args()

bwConfig = ConfigYAML()
if not bwConfig.loadConfigFile(paths.CONFIG_PATH + args.config):
    logging.fatal("cannot load config file")
    exit(1)

# ############################# begin server system
bwRoutMan = None
bwServer = None
bcServer = None

try:
    bwRoutMan = RouterManager()
    if not bwRoutMan.buildRouters(bwConfig):
        logging.fatal("Error while building routers")
        exit(1)
Example #6
0
def makeDescriptor():
    """!Build a descriptor object with loaded configuration"""
    config = ConfigYAML()
    assert config.loadConfigFile(paths.TEST_PATH + "test_config.yaml") is True
    descriptor = Descriptor(config.get("descriptor_test"))
    return descriptor