Exemplo n.º 1
0
def hdhr_process(config, _tuner_queue):
    global logger
    utils.logging_setup(config['paths'])
    logger = logging.getLogger(__name__)
    if config['hdhomerun']['udp_netmask'] is None:
        logger.error(
            'Config setting [hdhomerun][udp_netmask] required. Exiting hdhr service'
        )
        return

    try:
        net = IPv4Network(config['hdhomerun']['udp_netmask'])
    except (ipaddress.AddressValueError, ValueError) as err:
        logger.error(
            'Illegal value in [hdhomerun][udp_netmask].  '
            'Format must be #.#.#.#/#. Exiting hdhr service. ERROR: {}'.format(
                err))
        return

    hdhr = HDHRServer(config, _tuner_queue)
    # startup the multicast thread first which will exit when this function exits
    p_multi = Process(target=hdhr.run_multicast,
                      args=(config["web"]["bind_ip"], ))
    p_multi.daemon = True
    p_multi.start()

    # startup the standard tcp listener, but have this hang the process
    # the socket listener will terminate from main.py when the process is stopped
    hdhr.run_listener(config["web"]["bind_ip"])
    logger.info('hdhr_processing terminated')
Exemplo n.º 2
0
 def __init__(self,
              _script_dir=None,
              _opersystem=None,
              _args=None,
              _config=None):
     self.logger = None
     self.defn_json = None
     self.script_dir = str(_script_dir)
     self.defn_json = config_defn.load_default_config_defns()
     self.data = self.defn_json.get_default_config()
     if _script_dir is not None:
         config_file = TVHUserConfig.get_config_path(_script_dir, _args)
         self.import_config(config_file)
         self.defn_json.call_oninit(self)
         utils.logging_setup(self.data)
         # at this point, the config is setup
         self.db = DBConfigDefn(self.data)
         self.db.reinitialize_tables()
         self.defn_json.set_config(self.data)
         self.defn_json.save_defn_to_db()
     else:
         self.set_config(_config)
         self.defn_json.garbage_collect()
     self.db = DBConfigDefn(self.data)
     self.db.add_config(self.data)
Exemplo n.º 3
0
 def start_httpserver(cls,
                      _plugins,
                      _hdhr_queue,
                      _port,
                      _http_server_class,
                      _sched_queue=None):
     server_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
     server_socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
     server_socket.bind((_plugins.config_obj.data['web']['bind_ip'], _port))
     server_socket.listen(
         int(_plugins.config_obj.data['web']['concurrent_listeners']))
     utils.logging_setup(_plugins.config_obj.data)
     logger = logging.getLogger(__name__)
     cls.init_class_var(_plugins, _hdhr_queue, _sched_queue)
     if cls.total_instances == 0:
         _plugins.config_obj.data['web']['concurrent_listeners']
     logger.debug(
         'Now listening for requests. Number of listeners={}'.format(
             cls.total_instances))
     for i in range(cls.total_instances):
         _http_server_class(server_socket, _plugins)
     try:
         while True:
             time.sleep(3600)
     except KeyboardInterrupt:
         pass
Exemplo n.º 4
0
 def init_logger_config(self):
     log_sections = [
         'loggers', 'logger_root', 'handlers', 'formatters',
         'handler_filehandler', 'handler_loghandler', 'formatter_extend',
         'formatter_simple'
     ]
     for section in log_sections:
         try:
             self.config_handler.add_section(section)
         except configparser.DuplicateSectionError:
             pass
         for key, value in self.data[section].items():
             self.config_handler.set(section, key, str(value))
     with open(self.data['paths']['config_file'], 'w') as config_file:
         self.config_handler.write(config_file)
     utils.logging_setup(self.data)
Exemplo n.º 5
0
    def import_config(self, config_file):
        self.config_handler.read(config_file)
        self.data['paths']['config_file'] = str(config_file)
        try:
            utils.logging_setup(self.data)
        except KeyError:
            self.init_logger_config()
        self.logger = logging.getLogger(__name__)
        self.logger.info("Loading Configuration File: " + str(config_file))

        for each_section in self.config_handler.sections():
            lower_section = each_section.lower()
            if lower_section not in self.data.keys():
                self.data.update({lower_section: {}})
            for (each_key,
                 each_val) in self.config_handler.items(each_section):
                lower_key = each_key.lower()
                self.data[lower_section][lower_key] = \
                    self.fix_value_type(lower_section, lower_key, each_val)
Exemplo n.º 6
0
    def run_multicast(self, _bind_ip=''):
        utils.logging_setup(self.config['paths'])
        self.logger = logging.getLogger(__name__ + '_udp')
        self.logger.info('UDP: Starting HDHR multicast server')
        self.sock_multicast = socket.socket(socket.AF_INET, socket.SOCK_DGRAM,
                                            socket.IPPROTO_UDP)
        self.sock_multicast.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST,
                                       1)

        self.sock_multicast.bind(('0.0.0.0', HDHR_PORT))
        mreq = struct.pack('4sl', socket.inet_aton(HDHR_ADDR),
                           socket.INADDR_ANY)
        self.sock_multicast.setsockopt(socket.IPPROTO_IP,
                                       socket.IP_ADD_MEMBERSHIP, mreq)
        self.sock_multicast.settimeout(2)

        while True:
            try:
                data, addr = self.sock_multicast.recvfrom(1024)
                self.datagram_received(data, addr)
            except socket.timeout:
                continue
Exemplo n.º 7
0
 def __init__(self, _config):
     self.config = _config
     self.sock = None
     utils.logging_setup(self.config['paths'])
     self.logger = logging.getLogger(__name__)