Author: tack
Date: Wed Dec 6 16:47:21 2006
New Revision: 2158
Modified:
trunk/epg/src/server.py
trunk/epg/src/source_zap2it.py
Log:
Use logging for zap2it backend; add more logging info with processing times;
don't read guide data from server all into memory at once (it could be
potentially huge) -- read in 50KB chunks and output to a file; don't bother
gunzipping the downloaded xml data, as libxml2 supports reading gzipped data
natively; remove the tmp file after processing; make certain log output in
server debug rather than info (reduce verbosity for log mode INFO).
Modified: trunk/epg/src/server.py
==============================================================================
--- trunk/epg/src/server.py (original)
+++ trunk/epg/src/server.py Wed Dec 6 16:47:21 2006
@@ -230,7 +230,7 @@
self._tuner_ids.append(t)
# TODO: if everything is the same do not update
- log.info('update channel %s', name)
+ log.debug('update channel %s', name)
self._db.update_object(("channel", c2["id"]),
tuner_id = c2["tuner_id"],
long_name = long_name)
@@ -244,7 +244,7 @@
else:
self._tuner_ids.append(t)
- log.info('add channel %s %s %s', tuner_id, name, long_name)
+ log.debug('add channel %s %s %s', tuner_id, name, long_name)
o = self._db.add_object("channel", tuner_id = tuner_id, name = name,
long_name = long_name)
return o["id"]
@@ -289,7 +289,7 @@
removed.append(r['id'])
# Now add the new program
- log.info('adding program: %s', title)
+ log.debug('adding program: %s', title)
o = self._db.add_object("program", parent = ("channel", channel_db_id),
start = start, stop = stop, title = title,
**attributes)
Modified: trunk/epg/src/source_zap2it.py
==============================================================================
--- trunk/epg/src/source_zap2it.py (original)
+++ trunk/epg/src/source_zap2it.py Wed Dec 6 16:47:21 2006
@@ -28,11 +28,13 @@
# -----------------------------------------------------------------------------
# python imports
+import os
import md5
import time
import httplib
import gzip
import calendar
+import logging
from StringIO import StringIO
import libxml2
@@ -42,6 +44,8 @@
from kaa.strutils import str_to_unicode
from kaa.config import Var, Group
+# get logging object
+log = logging.getLogger('epg')
ZAP2IT_HOST = "datadirect.webservices.zap2it.com:80"
ZAP2IT_URI = "/tvlistings/xtvdService"
@@ -121,6 +125,7 @@
def request(username, passwd, host, uri, start, stop, auth = None):
+ t0 = time.time()
conn = httplib.HTTPConnection(host)
start_str = time.strftime("%Y-%m-%dT%H:%M:%SZ", time.gmtime(start))
stop_str = time.strftime("%Y-%m-%dT%H:%M:%SZ", time.gmtime(stop))
@@ -137,36 +142,38 @@
if auth:
headers["Authorization"] = auth
else:
- # FIXME: find a better way to convey this.
- print "Connecting to zap2it ..."
+ log.info('Connecting to zap2it server')
conn.request("POST", uri, None, headers)
conn.send(soap_request)
response = conn.getresponse()
if response.status == 401 and auth:
# Failed authentication.
- raise ValueError, "zap2it authentication failed; bad username or
password?"
+ log.error('zap2it authentication failed; bad username or password?')
+ return
if not auth and response.getheader("www-authenticate"):
header = response.getheader("www-authenticate")
auth = get_auth_digest_response_header(username, passwd, uri, header)
return request(username, passwd, host, uri, start, stop, auth)
- print "Downloading guide update ..."
- data = response.read()
+ log.info('Connected in %.02f seconds; downloading guide update.' %
(time.time() - t0))
- dfile = open("/tmp/zapdebug", "w+")
- dfile.write(data)
+ t0 = time.time()
+ fname = '/tmp/zap2it.xml.gz'
+ dfile = open(fname, 'w+')
+ # Read data in 50KB chunks.
+ while True:
+ data = response.read(50*1024)
+ if not data:
+ break
+ dfile.write(data)
dfile.close()
- data = gzip.GzipFile(fileobj = StringIO(data)).read()
-
- xfile = open("/tmp/guide.xml", "w")
- xfile.write(data)
- xfile.close()
-
conn.close()
- return data
+ log.info('Downloaded %dKB in %.02f seconds.' % \
+ (os.path.getsize(fname) / 1024.0, time.time() - t0))
+ return fname
def iternode(node):
@@ -253,8 +260,10 @@
pass
def _update_parse_xml_thread(epg, username, passwd, start, stop):
- data = request(username, passwd, ZAP2IT_HOST, ZAP2IT_URI, start, stop)
- doc = libxml2.parseMemory(data, len(data))
+ filename = request(username, passwd, ZAP2IT_HOST, ZAP2IT_URI, start, stop)
+ if not filename:
+ return
+ doc = libxml2.parseFile(filename)
stations_by_id = {}
roots = {}
@@ -275,6 +284,7 @@
info.stations_by_id = stations_by_id
info.epg = epg
info.progress_step = info.total / 100
+ info.t0 = time.time()
timer = kaa.notifier.Timer(_update_process_step, info)
timer.start(0)
@@ -295,8 +305,10 @@
break
if not info.node and not info.roots:
+ os.unlink(info.doc.name)
info.doc.freeDoc()
info.epg.guide_changed()
+ log.info('Processed %d programs in %.02f seconds' %
(info.epg._num_programs, time.time() - info.t0))
return False
return True
-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Freevo-cvslog mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/freevo-cvslog