<commit_before>import libxml2, sys, time, os, weakref, cPickle
import logging

from kaa import ipc, db
from kaa.notifier import Signal, OneShotTimer, execute_in_timer
from server import *
from channel import *
from program import *

__all__ = ['Client']

log = logging.getLogger()


class Client(object):
    def __init__(self, server_or_socket, auth_secret = None):
        self.connected = True
        self._ipc = ipc.IPCClient(server_or_socket, auth_secret = auth_secret)
        self._server = self._ipc.get_object("guide")

        self.signals = {
            "updated": Signal(),
            "update_progress": Signal(),
            "disconnected": Signal()
        }

        self._load()
        self._ipc.signals["closed"].connect(self._disconnected)

        # Connect to server signals. The callbacks itself are called with
        # a OneShotTimer to avoid some strange problems because of the ipc
        # code (the server will wait for the return)
        # FIXME: this whole signals over ipc stuff is ugly
        self._server.signals["updated"].connect(self._updated)
        self._server.signals["update_progress"].connect(self._update_progress)


    def _disconnected(self):
        self.connected = False
        self.signals["disconnected"].emit()


    execute_in_timer(OneShotTimer, 0)
    def _updated(self):
        self._load()
        self.signals["updated"].emit()


    execute_in_timer(OneShotTimer, 0)
    def _update_progress(self):
        self.signals["update_progress"].emit()

        
    def _load(self):
        self._channels_by_name = {}
        self._channels_by_db_id = {}
        self._channels_by_tuner_id = {}
        self._channels_list = []
        data = self._server.query(type="channel", __ipc_noproxy_result = True)
        for row in db.iter_raw_data(data, ("id", "tuner_id", "name", "long_name")):
            db_id, tuner_id, name, long_name = row
            chan = Channel(tuner_id, name, long_name, self)
            chan.db_id = db_id
            self._channels_by_name[name] = chan
            self._channels_by_db_id[db_id] = chan<commit_msg>add args to update_progress signal<commit_after>import libxml2, sys, time, os, weakref, cPickle
import logging

from kaa import ipc, db
from kaa.notifier import Signal, OneShotTimer, execute_in_timer
from server import *
from channel import *
from program import *

__all__ = ['Client']

log = logging.getLogger()


class Client(object):
    def __init__(self, server_or_socket, auth_secret = None):
        self.connected = True
        self._ipc = ipc.IPCClient(server_or_socket, auth_secret = auth_secret)
        self._server = self._ipc.get_object("guide")

        self.signals = {
            "updated": Signal(),
            "update_progress": Signal(),
            "disconnected": Signal()
        }

        self._load()
        self._ipc.signals["closed"].connect(self._disconnected)

        # Connect to server signals. The callbacks itself are called with
        # a OneShotTimer to avoid some strange problems because of the ipc
        # code (the server will wait for the return)
        # FIXME: this whole signals over ipc stuff is ugly
        self._server.signals["updated"].connect(self._updated)
        self._server.signals["update_progress"].connect(self._update_progress)


    def _disconnected(self):
        self.connected = False
        self.signals["disconnected"].emit()


    execute_in_timer(OneShotTimer, 0)
    def _updated(self):
        self._load()
        self.signals["updated"].emit()


    execute_in_timer(OneShotTimer, 0)
    def _update_progress(self, *args, **kwargs):
        self.signals["update_progress"].emit(*args, **kwargs)

        
    def _load(self):
        self._channels_by_name = {}
        self._channels_by_db_id = {}
        self._channels_by_tuner_id = {}
        self._channels_list = []
        data = self._server.query(type="channel", __ipc_noproxy_result = True)
        for row in db.iter_raw_data(data, ("id", "tuner_id", "name", "long_name")):
            db_id, tuner_id, name, long_name = row
            chan = Channel(tuner_id, name, long_name, self)
            chan.db_id = db_id
            self._channels_by_name[name] = chan
            self._channels_by_db_id[db_id] = chan
{'fraction_non_alphanumeric': 0.10668229777256741, 'fraction_numerical': 0.001406799531066823, 'mean_word_length': 2.7819148936170213, 'pattern_counts': {'":': 6, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2586348', 'n_tokens_mistral': 1332, 'n_tokens_neox': 1285, 'n_words': 300}