Exemple #1
0
 def gst_mainloop_thread(self):
     try:
         self.mainloop = GLib.MainLoop()
         self.mainloop.run()
         log.debug('gst mainloop exits')
     except:
         util.die('caught a gst mainloop exception, exiting..', 1, True)
Exemple #2
0
def start():
    """
    Use the run_server.py script in ./src
    """
    try:
        parser = argparse.ArgumentParser('Ludit client')
        parser.add_argument('--newcfg',
                            action='store_true',
                            dest='newcfg',
                            help='dump template configuration file to stdout')
        parser.add_argument('--cfg',
                            dest='cfg',
                            help='configuration file to use')
        parser.add_argument('--verbose',
                            action='store_true',
                            help='enable more logging')

        args = parser.parse_args()

        util.get_pid_lock('ludit_server')

        if args.verbose:
            log.setLevel(logging.DEBUG)

        if args.newcfg:
            config = json.dumps(generate_config(), indent=4, sort_keys=True)
            print(config)
            exit(0)

        def ctrl_c_handler(_, __):
            try:
                print(' ctrl-c handler')
                if _server:
                    log.info('terminating by user')
                    _server.terminate()
                    log.debug('terminate done, waiting..')
                    _server.join()
                sys.exit(1)
            except Exception as e:
                log.critical('ctrl-c handler got ' + str(e))

        def ignore(_, __):
            pass

        signal.signal(signal.SIGINT, ctrl_c_handler)
        signal.signal(signal.SIGPIPE, ignore)

        _server = None
        _server = Server(args.cfg)
        _server.join()
        log.info('server exiting')

    except Exception as e:
        if args.verbose:
            print(traceback.format_exc())
        util.die('server exception: %s' % str(e))
Exemple #3
0
 def multicast_rx(self, message):
     command = message['command']
     if command == 'server_socket':
         if not self.socket:
             endpoint = message['endpoint']
             if endpoint == "None":
                 log.critical("server refused the connection (check the group and device name)")
                 time.sleep(1)
                 util.die('exiting..', 1, True)
             log.info('server found, connecting to %s' % endpoint)
             self.server_endpoint = util.split_tcp(endpoint)
             self.start_socket()
Exemple #4
0
def load_configuration(configuration_file):
    try:
        with open(configuration_file) as f:
            configuration = json.loads(f.read())
            version = configuration.get('version')
            log.info('loaded configuration %s' % configuration_file)
            if version != util.CONFIG_VERSION:
                util.die('expected configuration version %s but found version %s' % (util.CONFIG_VERSION, version))
    except Exception:
        log.warning('no configuration file specified (--cfg), using defaults')
        configuration = generate_config()
    return configuration
Exemple #5
0
 def load_configuration(self):
     try:
         with open(self.configuration_file) as f:
             self.configuration = json.loads(f.read())
             version = self.configuration.get('version')
             log.info('loaded configuration %s' % self.configuration_file)
             if version != util.CONFIG_VERSION:
                 util.die(
                     'expected configuration version %s but found version %s'
                     % (util.CONFIG_VERSION, version))
     except Exception:
         log.warning(
             'no configuration file specified (--cfg), using template configuration'
         )
         self.configuration = generate_config()
Exemple #6
0
 def load_configuration(self):
     try:
         with open(self.configuration_file) as f:
             self.configuration = json.loads(f.read())
             version = self.configuration.get('version')
             log.info('loaded configuration %s' % self.configuration_file)
             if version != util.CONFIG_VERSION:
                 util.die(
                     'expected configuration version %s but found version %s'
                     % (util.CONFIG_VERSION, version))
     except json.JSONDecodeError as e:
         util.die(f'got fatal error loading configuration file "{e}"')
     except Exception as e:
         print(str(e))
         log.warning(
             'no configuration file specified (--cfg), using template configuration'
         )
         self.configuration = generate_config()