<commit_before># -*- coding: iso-8859-1 -*-
# -----------------------------------------------------------------------------
# source_vdr.py - Get EPG information from VDR.
# -----------------------------------------------------------------------------
# $Id: $
#
# -----------------------------------------------------------------------------
# kaa-epg - Python EPG module
# Copyright (C) 2002-2005 <NAME>, <NAME>, et al.
#
# First Edition: <NAME> <<EMAIL>>
# Maintainer:    <NAME> <<EMAIL>>
#
# Please see the file doc/AUTHORS for a complete list of authors.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of MER-
# CHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
# Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
# -----------------------------------------------------------------------------

# python imports
import os
import string
import logging

# kaa imports
import kaa.notifier

# vdr imports
from vdr.vdr import VDR

# get logging object
log = logging.getLogger('epg')


class UpdateInfo:
    pass

def _update_data_thread(epg, vdr_dir=None, channels_file=None, epg_file=None,
                        host=None, port=None, access_by='sid', 
                        limit_channels='conf', exclude_channels=None):
    """
    Update the guide.
    """
    log.debug('_update_data_thread')

    info = UpdateInfo()
    info.total = 0

    if not (isinstance(exclude_channels, list) or \
            isinstance(exclude_channels, tuple)):
        exclude_channels = []

    log.info('excluding channels: %s' % exclude_channels)

    info.vdr = VDR(host=host, port=port, videopath=vdr_dir,
                   channelsfile=channels_file, epgfile=epg_file,
                   close_connection=0)

    if info.vdr.epgfile and os.path.isfile(info.vdr.epgfile):
        log.info('Using VDR EPG from %s.' % info.vdr.epgfile)
        if os.path.isfile(info.vdr.channelsfile):
            info.vdr.readchannels()
        else:
            log.warning('VDR channels file not found: %s.' % info.vdr.channelsfile)
        info.vdr.readepg()
    elif info.vdr.host and info.vdr.port:
        log.info('Using VDR EPG from %s:%s.' % (info.vdr.host, info.vdr.port))
        info.vdr.retrievechannels()
        info.vdr.retrieveepg()
    else:
        log.info('No source for VDR EPG.')
        return False

    for c in info.vdr.channels.values():
        for e in c.events:
            info.total += 1

    info.access_by        = access_by
    info.limit_channels   = limit_channels
    info.exclude_channels = exclude_channels
    info.cur              = 0
    info.epg              = epg
    info.progress_step    = info.total / 100

    timer = kaa.notifier.Timer(_update_process_step, info)
    timer.set_prevent_recursion()
    timer.start(0)


def _update_process_step(info):

    chans = info.vdr.channels.values()
    for c in chans:
        if c.id in info.exclude_channels:  continue

        if string.lower(info.limit_channels) == 'epg' and not c.in_epg:
            continue
        elif string.lower(info.limit_channels) == 'conf' and not c.in_conf:
            continue
        elif string.lower(info.limit_channels) == 'both' and \
                 not (c.in_conf and c.in_epg):
            continue

        if info.access_by == 'name':
            access_id = c.name
        elif info.access_by == 'rid':
            access_id = c.rid
        else:
            access_id = c.sid

        log.info('Adding channel: %s as %s' % (c.id, access_id))

        chan_db_id = info.epg._add_channel_to_db(tuner_id=Unicode(access_id), 
                                                 short_name=Unicode(c.name), 
                                                 long_name=None)

        for e in c.events:
            subtitle = e.subtitle
            if not subtitle:
                subtitle = ''
            desc = e.desc
            if not desc:
                desc = ''

            info.epg._add_program_to_db(chan_db_id, e.start, int(e.start+e.dur),
                                        Unicode(e.title), Unicode(desc))

            info.cur +=1
            if info.cur % info.progress_step == 0:
                info.epg.signals["update_progress"].emit(info.cur, info.total)

    info.epg.signals["update_progress"].emit(info.cur, info.total)
    return False
<commit_msg>Unicode fix.<commit_after># -*- coding: iso-8859-1 -*-
# -----------------------------------------------------------------------------
# source_vdr.py - Get EPG information from VDR.
# -----------------------------------------------------------------------------
# $Id: $
#
# -----------------------------------------------------------------------------
# kaa-epg - Python EPG module
# Copyright (C) 2002-2005 <NAME>, <NAME>, et al.
#
# First Edition: <NAME> <<EMAIL>>
# Maintainer:    <NAME> <<EMAIL>>
#
# Please see the file doc/AUTHORS for a complete list of authors.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of MER-
# CHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
# Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
# -----------------------------------------------------------------------------

# python imports
import os
import string
import logging

# kaa imports
from kaa.base import strutils
import kaa.notifier

# vdr imports
from vdr.vdr import VDR

# get logging object
log = logging.getLogger('epg')


class UpdateInfo:
    pass

def _update_data_thread(epg, vdr_dir=None, channels_file=None, epg_file=None,
                        host=None, port=None, access_by='sid', 
                        limit_channels='conf', exclude_channels=None):
    """
    Update the guide.
    """
    log.debug('_update_data_thread')

    info = UpdateInfo()
    info.total = 0

    if not (isinstance(exclude_channels, list) or \
            isinstance(exclude_channels, tuple)):
        exclude_channels = []

    log.info('excluding channels: %s' % exclude_channels)

    info.vdr = VDR(host=host, port=port, videopath=vdr_dir,
                   channelsfile=channels_file, epgfile=epg_file,
                   close_connection=0)

    if info.vdr.epgfile and os.path.isfile(info.vdr.epgfile):
        log.info('Using VDR EPG from %s.' % info.vdr.epgfile)
        if os.path.isfile(info.vdr.channelsfile):
            info.vdr.readchannels()
        else:
            log.warning('VDR channels file not found: %s.' % info.vdr.channelsfile)
        info.vdr.readepg()
    elif info.vdr.host and info.vdr.port:
        log.info('Using VDR EPG from %s:%s.' % (info.vdr.host, info.vdr.port))
        info.vdr.retrievechannels()
        info.vdr.retrieveepg()
    else:
        log.info('No source for VDR EPG.')
        return False

    for c in info.vdr.channels.values():
        for e in c.events:
            info.total += 1

    info.access_by        = access_by
    info.limit_channels   = limit_channels
    info.exclude_channels = exclude_channels
    info.cur              = 0
    info.epg              = epg
    info.progress_step    = info.total / 100

    timer = kaa.notifier.Timer(_update_process_step, info)
    timer.set_prevent_recursion()
    timer.start(0)


def _update_process_step(info):

    chans = info.vdr.channels.values()
    for c in chans:
        if c.id in info.exclude_channels:  continue

        if string.lower(info.limit_channels) == 'epg' and not c.in_epg:
            continue
        elif string.lower(info.limit_channels) == 'conf' and not c.in_conf:
            continue
        elif string.lower(info.limit_channels) == 'both' and \
                 not (c.in_conf and c.in_epg):
            continue

        if info.access_by == 'name':
            access_id = c.name
        elif info.access_by == 'rid':
            access_id = c.rid
        else:
            access_id = c.sid

        log.info('Adding channel: %s as %s' % (c.id, access_id))

        chan_db_id = info.epg._add_channel_to_db(tuner_id=strutils.str_to_unicode(access_id), 
                                                 short_name=strutils.str_to_unicode(c.name), 
                                                 long_name=None)

        for e in c.events:
            subtitle = e.subtitle
            if not subtitle:
                subtitle = ''
            desc = e.desc
            if not desc:
                desc = ''

            info.epg._add_program_to_db(chan_db_id, e.start, int(e.start+e.dur),
                                        strutils.str_to_unicode(e.title), strutils.str_to_unicode(desc))

            info.cur +=1
            if info.cur % info.progress_step == 0:
                info.epg.signals["update_progress"].emit(info.cur, info.total)

    info.epg.signals["update_progress"].emit(info.cur, info.total)
    return False

{'fraction_non_alphanumeric': 0.15927026750025622, 'fraction_numerical': 0.007789279491647022, 'mean_word_length': 1.7848173515981736, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 10, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7012495', 'n_tokens_mistral': 2935, 'n_tokens_neox': 2797, 'n_words': 765}