Update of /cvsroot/freevo/kaa/epg/bin
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv4101/epg/bin

Added Files:
        .cvsignore kaa-epg 
Log Message:
move pyepg to kaa.epg

--- NEW FILE: .cvsignore ---
*.pyc *.pyo

--- NEW FILE: kaa-epg ---
#!/usr/bin/python

import getopt
import os
import sys
import time
import logging

import kaa.epg

def usage(return_value):
    print '\nUsage: kaa-epg [config] [options]'
    print '\nConfig:'
    print '  --db file               Database file'
    print '\nOptions:'
    print '  -h, --help              Print help and exit.'
    print '  -l, --list              List your channels.'
    print '  -f file, --fill=file    Fill db with xmltv from file.'
    print '  -s prog, --search=prog  Search db for matching program.'
    sys.exit(return_value)


def list_channels():
    """
    List all channels in the database.
    """
    for c in kaa.epg.channels:
        print c


def search_progs(subs):
    """
    Search for programs in database.
    """
    programs = kaa.epg.search(subs)
    for p in programs:
        start = time.strftime('%b %d %H:%M', time.localtime(p.start))
        stop = time.strftime('%H:%M', time.localtime(p.stop))
        channel = p.channel.name.encode('latin-1', 'ignore')
        title   = p.title.encode('latin-1', 'ignore')
        if len(title) > 30:
            title = title[:27] + '...'
        print '%s-%s %-30s on %s (%d)' % (start, stop, title, channel, p.id)


def main():
    # config
    db = None

    options = 'f:hls:'
    long_options = ['db=', 'fill=', 'help', 'list', 'search=']
    action = None
    action_args = []

    try:
        opts, args = getopt.getopt(sys.argv[1:], options, long_options)
    except getopt.GetoptError, e:
        print 'Error:', e
        usage(1)

    for o, a in opts:
        if o in ('-h', '--help'):
            usage(0)

        # config
        if o == '--db':
            db = a

        # options
        if o in ('-f', '--fill'):
            action = kaa.epg.update
            action_args = ['xmltv', a]
        if o in ('-l', '--list'):
            action = list_channels
            action_args = []
        if o in ('-s', '--search'):
            action = search_progs
            action_args = [ a ]

    if not db:
        print 'Error: No database file given.'
        usage(1)

    if not action:
        usage(1)

    kaa.epg.connect('sqlite', db)
    # TV_CHANNELS, TV_CHANNELS_EXCLUDE
    kaa.epg.load([], [])

    action(*action_args)



if __name__ == "__main__":
    # create and setup the root logger object.
    # using logging.getLogger() gives the root logger, calling
    # logging.getLogger('foo') returns a new logger with the same default
    # settings.
    logger = logging.getLogger()

    # set stdout logging
    formatter = logging.Formatter('%(levelname)s %(module)s'+\
                                  '(%(lineno)s): %(message)s')
    handler = logging.StreamHandler()
    handler.setFormatter(formatter)
    logger.addHandler(handler)
    
    # set log level
    logger.setLevel(logging.INFO)
    main()



-------------------------------------------------------
SF.Net email is sponsored by: Discover Easy Linux Migration Strategies
from IBM. Find simple to follow Roadmaps, straightforward articles,
informative Webcasts and more! Get everything you need to get up to
speed, fast. http://ads.osdn.com/?ad_id=7477&alloc_id=16492&op=click
_______________________________________________
Freevo-cvslog mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/freevo-cvslog

Reply via email to