Author: duncan
Date: Sun Mar 16 17:09:16 2008
New Revision: 10534
Log:
Some additional debug information
Moved TvChannel variables back to class varibles
Setting varibles before creating a TvProgram instance
Replaced has_key() with in
Modified:
branches/rel-1/freevo/src/tv/epg_types.py
branches/rel-1/freevo/src/tv/epg_xmltv.py
branches/rel-1/freevo/src/tv/tvguide.py
Modified: branches/rel-1/freevo/src/tv/epg_types.py
==============================================================================
--- branches/rel-1/freevo/src/tv/epg_types.py (original)
+++ branches/rel-1/freevo/src/tv/epg_types.py Sun Mar 16 17:09:16 2008
@@ -39,7 +39,9 @@
EPG_VERSION = 6
class TvProgram:
-
+ """
+ Holds information about a TV programme
+ """
channel_id = None
title = None
desc = None
@@ -58,19 +60,18 @@
allowDuplicates = None
onlyNew = None
-
- def __init__(self, title='', channel_id='', start=0, stop=0, desc=''):
- _debug_('TvProgram.__init__(title=%r, channel_id=%r, start=%r,
stop=%r, desc=%r)' % (title, channel_id, start, stop, desc), 1)
+ def __init__(self, channel_id='', start=0, pdc_start=0, stop=0, title='',
sub_title='', desc='', categories=[], ratings={}):
+ _debug_('TvProgram.__init__(channel_id=%r, start=%r, stop=%r,
title=%r)' % (channel_id, start, stop, title), 1)
self.title = title
self.channel_id = channel_id
self.desc = desc
- self.sub_title = ''
+ self.sub_title = sub_title
self.start = start
- self.pdc_start = 0.0
+ self.pdc_start = pdc_start
self.stop = stop
- self.ratings = {}
+ self.ratings = ratings
self.advisories = []
- self.categories = []
+ self.categories = categories
self.date = None
# Due to problems with Twisted's marmalade this should not be changed
@@ -134,7 +135,7 @@
"""
return the specific attribute as string or an empty string
"""
- _debug_('getattr(attr=%r)' % (attr,), 1)
+ _debug_('getattr(attr=%r)' % (attr,), 3)
if attr == 'start':
return Unicode(time.strftime(config.TV_TIME_FORMAT,
time.localtime(self.start)))
if attr == 'pdc_start':
@@ -154,7 +155,7 @@
"""
Decode all internal strings from Unicode to String
"""
- _debug_('utf2str()', 1)
+ _debug_('utf2str()', 3)
ret = copy.copy(self)
for var in dir(ret):
if not var.startswith('_') and isinstance(getattr(ret, var),
unicode):
@@ -166,7 +167,7 @@
"""
Encode all internal strings from String to Unicode
"""
- _debug_('str2utf()', 1)
+ _debug_('str2utf()', 3)
ret = copy.copy(self)
for var in dir(ret):
if not var.startswith('_') and isinstance(getattr(ret, var), str):
@@ -178,7 +179,13 @@
"""
Holds information about a TV channel
"""
- logo = None
+ id = ''
+ displayname = ''
+ tunerid = ''
+ logo = ''
+ times = None
+ programs = None
+
def __init__(self, id, displayname, tunerid, logo='', times=[],
programs=[]):
""" Copy the programs that are inside the indicated time bracket """
_debug_('TvChannel.__init__(id=%r, displayname=%r, tunerid=%r,
logo=%r, times=%r, programs=%r)' % (id, displayname, tunerid, logo, times,
programs), 1)
@@ -198,7 +205,7 @@
def sort(self):
""" Sort the programs so that the earliest is first in the list """
- _debug_('TvChannel.sort()', 1)
+ _debug_('TvChannel.sort(), displayname=%r' % (self.displayname,), 1)
f = lambda a, b: cmp(a.start, b.start)
self.programs.sort(f)
@@ -215,7 +222,7 @@
def __repr__(self):
- return '<TvChannel %r>' % (self.id)
+ return '<TvChannel %r %r>' % (self.id, self.displayname)
@@ -236,29 +243,32 @@
def add_channel(self, channel):
_debug_('add_channel(channel=%r)' % (channel,), 1)
- if not self.chan_dict.has_key(channel.id):
- # Add the channel to both the dictionary and the list. This works
- # well in Python since they will both point to the same object!
- self.chan_dict[channel.id] = channel
- self.chan_list += [channel]
+ if channel.id in self.chan_dict:
+ return
+ # Add the channel to both the dictionary and the list. This works
+ # well in Python since they will both point to the same object!
+ self.chan_dict[channel.id] = channel
+ self.chan_list += [channel]
def add_program(self, program):
""" The channel must be present, or the program is silently dropped """
_debug_('add_program(program=%r)' % (program,), 1)
- if self.chan_dict.has_key(program.channel_id):
- p = self.chan_dict[program.channel_id].programs
- if len(p) and p[-1].start < program.stop and p[-1].stop >
program.start:
+ if program.channel_id not in self.chan_dict:
+ return
+ programs = self.chan_dict[program.channel_id].programs
+ if len(programs) > 0:
+ if programs[-1].start < program.stop and programs[-1].stop >
program.start:
+ _debug_('invalid stop time: %r' %
self.chan_dict[program.channel_id].programs[-1])
# the tv guide is corrupt, the last entry has a stop time
higher than
# the next start time. Correct that by reducing the stop time
of
# the last entry
- _debug_('wrong stop time: %s' %
String(self.chan_dict[program.channel_id].programs[-1]))
self.chan_dict[program.channel_id].programs[-1].stop =
program.start
-
- if len(p) and p[-1].start == p[-1].stop:
+ if programs[-1].start == programs[-1].stop:
+ _debug_('program has no duration %r' %
self.chan_dict[program.channel_id].programs[-1])
# Oops, something is broken here
- self.chan_dict[program.channel_id].programs = p[:-1]
- self.chan_dict[program.channel_id].programs += [program]
+ self.chan_dict[program.channel_id].programs = programs[:-1]
+ self.chan_dict[program.channel_id].programs += [program]
def get_programs(self, start=0, stop=2147483647, channel_id=None):
Modified: branches/rel-1/freevo/src/tv/epg_xmltv.py
==============================================================================
--- branches/rel-1/freevo/src/tv/epg_xmltv.py (original)
+++ branches/rel-1/freevo/src/tv/epg_xmltv.py Sun Mar 16 17:09:16 2008
@@ -246,52 +246,53 @@
if not p['channel'] in needed_ids:
continue
try:
- prog = TvProgram()
- prog.channel_id = p['channel']
- prog.title = Unicode(p['title'][0][0])
- if p.has_key('date'):
- prog.date = Unicode(p['date'])
- if p.has_key('category'):
- prog.categories = [ cat[0] for cat in p['category'] ]
- if p.has_key('rating'):
+ channel_id = p['channel']
+ date = 'date' in p and Unicode(p['date']) or None
+ start = None
+ pdc_start = None
+ stop = None
+ title = Unicode(p['title'][0][0])
+ desc = 'desc' in p and Unicode(util.format_text(p['desc'][0][0]))
or None
+ sub_title = 'sub-title' in p and Unicode(p['sub-title'][0][0]) or
None
+ categories = 'category' in p and [ cat[0] for cat in p['category']
] or None
+ advisories = []
+ ratings = {}
+
+ if 'rating' in p:
for r in p['rating']:
if r.get('system') == 'advisory':
- prog.advisories.append(String(r.get('value')))
+ advisories.append(String(r.get('value')))
continue
- prog.ratings[String(r.get('system'))] =
String(r.get('value'))
- if p.has_key('desc'):
- prog.desc = Unicode(util.format_text(p['desc'][0][0]))
- if p.has_key('sub-title'):
- prog.sub_title = p['sub-title'][0][0]
+ ratings[String(r.get('system'))] = String(r.get('value'))
try:
- prog.start = timestr2secs_utc(p['start'])
- if p.has_key('pdc_start'):
- prog.pdc_start = timestr2secs_utc(p['pdc_start'])
- else:
- prog.pdc_start = prog.start
+ start = timestr2secs_utc(p['start'])
+ pdc_start = 'pdc_start' in p and
timestr2secs_utc(p['pdc_start']) or start
try:
- prog.stop = timestr2secs_utc(p['stop'])
+ stop = timestr2secs_utc(p['stop'])
except:
# Fudging end time
- prog.stop = timestr2secs_utc(p['start'][0:8] + '235900' + \
- p['start'][14:18])
- # Don't think that this is ever raised
- except EpgException:
+ stop = timestr2secs_utc(p['start'][0:8] + '235900' +
p['start'][14:18])
+ except EpgException, why:
+ _debug_('EpgException: %s' % (why,), DWARNING)
continue
- # fix bad German titles to make favorites working
- if prog.title.endswith('. Teil'):
- prog.title = prog.title[:-6]
- if prog.title.rfind(' ') > 0:
+
+ # fix bad German titles to make favorites work
+ if title.endswith('. Teil'):
+ title = title[:-6]
+ if title.rfind(' ') > 0:
try:
- part = int(prog.title[prog.title.rfind(' ')+1:])
- prog.title = prog.title[:prog.title.rfind('
')].rstrip()
- if prog.sub_title:
- prog.sub_title = u'Teil %s: %s' % (part,
prog.sub_title)
+ part = int(title[title.rfind(' ')+1:])
+ title = title[:title.rfind(' ')].rstrip()
+ if sub_title:
+ sub_title = u'Teil %s: %s' % (part, sub_title)
else:
- prog.sub_title = u'Teil %s' % part
+ sub_title = u'Teil %s' % part
except Exception, e:
print 'Teil:', e
+ prog = TvProgram(channel_id, start, pdc_start, stop, title,
sub_title, desc, categories, ratings)
+ prog.advisories = advisories
+ prog.date = date
guide.add_program(prog)
except:
traceback.print_exc()
@@ -360,3 +361,15 @@
timestr = timestr.replace('EST', '')
secs = time.mktime(strptime.strptime(timestr,
xmltv.date_format))
return secs
+
+
+if __name__ == '__main__':
+ xmltv_file = config.XMLTV_FILE
+ if len(sys.argv) > 1:
+ xmltv_file = sys.argv[1]
+ import pdb
+ pdb.set_trace()
+ guide = load_guide(True, xmltv_file)
+ print '%r' % (guide,)
+ print '%r' % (dir(guide),)
+ print '%r' % (guide.__dict__,)
Modified: branches/rel-1/freevo/src/tv/tvguide.py
==============================================================================
--- branches/rel-1/freevo/src/tv/tvguide.py (original)
+++ branches/rel-1/freevo/src/tv/tvguide.py Sun Mar 16 17:09:16 2008
@@ -41,6 +41,9 @@
from item import Item
from programitem import ProgramItem
+from util.benchmark import benchmark
+benchmarking = False
+
import tv.epg_xmltv
from tv.epg_types import TvProgram
from tv.record_client import RecordClient
@@ -120,6 +123,7 @@
self.favorite_programs.append(prog.str2utf())
+ @benchmark(benchmarking)
def update_schedules(self, force=False):
"""
update schedule
@@ -130,11 +134,7 @@
if not force and self.last_update + 60 > time.time():
return
- # less than one second? Do not belive the force update
- #if self.last_update + 1 > time.time():
- # return
-
- _debug_('update schedule', 2)
+ _debug_('update schedule', 1)
self.last_update = time.time()
self.scheduled_programs = []
self.overlap_programs = []
@@ -142,6 +142,7 @@
self.recordclient.getScheduledRecordings(self.update_schedules_cb)
+ @benchmark(benchmarking)
def eventhandler(self, event, menuw=None):
"""
Handles events in the tv guide
@@ -297,6 +298,7 @@
skin.clear()
+ @benchmark(benchmarking)
def refresh(self, force_update=True):
"""refresh the guide
@@ -312,6 +314,7 @@
skin.draw(self.type, self)
+ @benchmark(benchmarking)
def update(self, force=False):
""" update the guide
@@ -389,6 +392,7 @@
self.rebuild(new_start_time, new_end_time, start_channel, selected)
+ @benchmark(benchmarking)
def rebuild(self, start_time, stop_time, start_channel, selected):
""" rebuild the guide
@@ -444,7 +448,7 @@
if chan.programs[i] == selected:
flag_selected = 1
- table += [ chan ]
+ table += [ chan ]
n += 1
if flag_selected == 0:
@@ -466,6 +470,7 @@
self.refresh(force_update=False)
+ @benchmark(benchmarking)
def change_program(self, value, full_scan=False):
"""
Move to the next program
@@ -535,6 +540,7 @@
self.rebuild(start_time, stop_time, start_channel, prg)
+ @benchmark(benchmarking)
def change_channel(self, value):
"""
Move to the next channel
-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Freevo-cvslog mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/freevo-cvslog