Author: duncan
Date: Wed Oct 17 10:58:47 2007
New Revision: 9995
Log:
Mostly a change to childapp logging, simplified the logging, no more blank lines
Other changes include fixed to debug message levels and removed others
Modified:
branches/rel-1/freevo/src/childapp.py
branches/rel-1/freevo/src/helpers/recordserver.py
branches/rel-1/freevo/src/tv/ivtv.py
branches/rel-1/freevo/src/tv/plugins/vbi2srt_record.py
branches/rel-1/freevo/src/tv/v4l2.py
Modified: branches/rel-1/freevo/src/childapp.py
==============================================================================
--- branches/rel-1/freevo/src/childapp.py (original)
+++ branches/rel-1/freevo/src/childapp.py Wed Oct 17 10:58:47 2007
@@ -52,6 +52,10 @@
ready = False
def __init__(self, app, debugname=None, doeslogging=0):
+ """
+ Initialise ChildApp
+ """
+ _debug_('ChildApp.__init__(app=%r, debugname=%r, doeslogging=%r)' %
(app, debugname, doeslogging), 1)
self.lock = thread.allocate_lock()
prio = 0
@@ -109,31 +113,35 @@
if doeslogging or config.DEBUG_CHILDAPP:
doeslogging = 1
- stdout_logger = os.path.join(config.FREEVO_LOGDIR, '%s-stdout-%s.log'
% (debug_name, os.getuid()))
- try:
- self.stdout_log = doeslogging and open(stdout_logger, 'w') or None
- except OSError, e:
- _debug_('Cannot open "%s": %s' % (stdout_logger, e), DWARNING)
- self.stdout_log = None
+ if doeslogging:
+ stdout_logger = os.path.join(config.FREEVO_LOGDIR,
'%s-stdout-%s.log' % (debug_name, os.getuid()))
+ try:
+ self.stdout_log = open(stdout_logger, 'w')
+ except OSError, e:
+ _debug_('Cannot open "%s": %s' % (stdout_logger, e), DWARNING)
+ self.stdout_log = None
- stderr_logger = os.path.join(config.FREEVO_LOGDIR, '%s-stderr-%s.log'
% (debug_name, os.getuid()))
- try:
- self.stderr_log = doeslogging and open(stderr_logger, 'w') or None
- except OSError, e:
- _debug_('Cannot open "%s": %s' % (stderr_logger, e), DWARNING)
+ stderr_logger = os.path.join(config.FREEVO_LOGDIR,
'%s-stderr-%s.log' % (debug_name, os.getuid()))
+ try:
+ self.stderr_log = open(stderr_logger, 'w')
+ except OSError, e:
+ _debug_('Cannot open "%s": %s' % (stderr_logger, e), DWARNING)
+ self.stderr_log = None
+ else:
+ self.stdout_log = None
self.stderr_log = None
command_isstr = isinstance(command, str)
if command_isstr:
- #command = command.strip() # strip spaces from the command string
command_shell = True
- command_str = command
+ command_str = command.strip()
else:
command_shell = False
command_str = ' '.join(command)
self.child = None
try:
- self.child = Popen(command, shell=command_shell, stdin=PIPE,
stdout=PIPE, stderr=PIPE)
+ self.child = Popen(command, shell=command_shell, stdin=PIPE,
stdout=PIPE, stderr=PIPE, \
+ universal_newlines=True)
_debug_('Running (%s) "%s"%s with pid %s priority %s' % (\
command_isstr and 'str' or 'list', command_str, command_shell
and ' in shell' or '', \
self.child.pid, prio), 1)
@@ -302,6 +310,11 @@
Enhanced version of ChildApp handling most playing stuff
"""
def __init__(self, app, debugname=None, doeslogging=0, stop_osd=2):
+ """
+ Initialise ChildApp2
+ """
+ _debug_('ChildApp2.__init__(app=%r, debugname=%r, doeslogging=%r,
stop_osd=%r)' % \
+ (app, debugname, doeslogging, stop_osd), 1)
rc.register(self.poll, True, 10)
rc.register(self.stop, True, rc.SHUTDOWN)
@@ -391,9 +404,11 @@
Thread for reading stdout or stderr from the child
"""
def __init__(self, name, fh, callback, logger=None, doeslogging=0):
- '''Constructor of Read_Thread'''
+ """
+ Constructor of Read_Thread
+ """
_debug_('Read_Thread.__init__(name=%r, fh=%r, callback=%r, logger=%r,
doeslogging=%r' % \
- (name, fh, callback, logger, doeslogging), 2)
+ (name, fh, callback, logger, doeslogging), 1)
threading.Thread.__init__(self)
self.name = name
self.fh = fh
@@ -426,38 +441,29 @@
if not data:
_debug_('%s: no data, closing log' % (self.name))
self.fh.close()
- if self.logger: self.logger.close()
+ if saved:
+ self.logger.write(saved+'\n')
+ if self.logger:
+ self.logger.close()
break
else:
- data = data.replace('\r', '\n')
+ data = saved + data
+ complete_last_line = data.endswith('\n')
+ if complete_last_line:
+ data = data.strip('\n')
lines = data.split('\n')
- # Only one partial line?
- if len(lines) == 1:
- saved += data
+ if complete_last_line:
+ complete_lines = lines
+ saved = ''
else:
- # Combine saved data and first line, send to app
+ # not seen a case where there is an incomplete last line,
so this may not work
+ complete_lines = lines[:-1]
+ saved += lines[-1]
+ #print 'saved=%r complete=%s lines=%r' % (saved,
complete_last_line, lines)
+
+ for line in complete_lines:
if self.logger:
- line = (saved + lines[0]).strip('\n')
self.logger.write(line+'\n')
- rc.register(self.callback, False, 0, saved + lines[0])
- saved = ''
-
- # There's one or more lines + possibly a partial line
- if lines[-1] != '':
- # The last line is partial, save it for the next time
- saved = lines[-1]
-
- # Send all lines except the last partial line to the
app
- for line in lines[1:-1]:
- if self.logger:
- line = line.strip('\n')
- self.logger.write(line+'\n')
- rc.register(self.callback, False, 0, line)
- else:
- # Send all lines to the app
- for line in lines[1:]:
- if self.logger:
- line = line.strip('\n')
- self.logger.write(line+'\n')
- rc.register(self.callback, False, 0, line)
+ self.logger.flush()
+ rc.register(self.callback, False, 0, line)
Modified: branches/rel-1/freevo/src/helpers/recordserver.py
==============================================================================
--- branches/rel-1/freevo/src/helpers/recordserver.py (original)
+++ branches/rel-1/freevo/src/helpers/recordserver.py Wed Oct 17 10:58:47 2007
@@ -1,4 +1,3 @@
-#!/usr/bin/env python
# -*- coding: iso-8859-1 -*-
# -----------------------------------------------------------------------
# record_server.py - A network aware TV recording server.
@@ -1568,8 +1567,12 @@
def handleEvents(self):
event = rc_object.get_event()
-
if event:
+ if hasattr(event, 'arg'):
+ _debug_('event=%s arg=%r' % (event, event.arg))
+ else:
+ _debug_('event=%s' % (event))
+
if event == OS_EVENT_POPEN2:
pid = event.arg[1]
_debug_('OS_EVENT_POPEN2 pid: %s' % pid, DINFO)
@@ -1709,12 +1712,17 @@
os.remove(f)
while 1:
- try:
- start = time.time()
- main()
- break
- except:
- traceback.print_exc()
- if start + 10 > time.time():
- _debug_('server problem, sleeping 1 min', DINFO)
- time.sleep(60)
+ main()
+
+ # Don't see the point to this code, errors are system errors or
programming errors
+ # Better to exit. May there was a reason
+ #try:
+ # start = time.time()
+ # main()
+ # break
+ #except Exception, e:
+ # print e
+ # traceback.print_exc()
+ # if start + 10 > time.time():
+ # _debug_('server problem, sleeping 1 min', DINFO)
+ # time.sleep(60)
Modified: branches/rel-1/freevo/src/tv/ivtv.py
==============================================================================
--- branches/rel-1/freevo/src/tv/ivtv.py (original)
+++ branches/rel-1/freevo/src/tv/ivtv.py Wed Oct 17 10:58:47 2007
@@ -161,7 +161,9 @@
framerate = 0
framespergop = tv.v4l2.Videodev.getcontrol(self, 'Video GOP Size')
gop_closure = tv.v4l2.Videodev.getcontrol(self, 'Video GOP
Closure')
- pulldown = tv.v4l2.Videodev.getcontrol(self, 'Video Pulldown')
+ pulldown = 0
+ #pulldown = tv.v4l2.Videodev.getcontrol(self, 'Video Pulldown')
+ #insert_navigation_packets = tv.v4l2.Videodev.getcontrol(self,
'insert_navigation_packets')
stream_type =
self.streamTypeV4l2ToIVTV(tv.v4l2.Videodev.getcontrol(self, 'Stream Type'))
codec_list = (aspect, audio_bitmask, bframes, bitrate_mode,
bitrate, bitrate_peak,
dnr_mode, dnr_spatial, dnr_temporal, dnr_type, framerate,
framespergop, gop_closure,
Modified: branches/rel-1/freevo/src/tv/plugins/vbi2srt_record.py
==============================================================================
--- branches/rel-1/freevo/src/tv/plugins/vbi2srt_record.py (original)
+++ branches/rel-1/freevo/src/tv/plugins/vbi2srt_record.py Wed Oct 17
10:58:47 2007
@@ -63,6 +63,7 @@
Record subtitles from teletext pages (IVTV cards only)
The teletext page number is taken from TV_CHANNELS, eg:
+
TV_CHANNELS = [
#'XMLTV Id', 'Channel Name', 'Freq', 'Times', 'Video Group', 'Teletext
Page Number'
('bbc.co.uk', 'BBC Prime', 'K32', '', '0', '881'),
@@ -96,8 +97,10 @@
class Recorder:
-
+ """
+ """
def __init__(self):
+ _debug_('Recorder.__init__()', 1)
# Disable this plugin if not loaded by record_server.
if string.find(sys.argv[0], 'recordserver') == -1:
return
@@ -168,8 +171,6 @@
self.thread.autokill = float(rec_prog.rec_duration + 10)
self.thread.mode_flag.set()
- _debug_('rec_command=%r' % self.rec_command)
-
def Stop(self):
self.thread.mode = 'stop'
@@ -177,37 +178,21 @@
class RecordApp(childapp.ChildApp):
-
+ """
+ """
def __init__(self, app):
- if DEBUG:
- fname_out = os.path.join(config.FREEVO_LOGDIR,
'vbi2srt-stdout.log')
- fname_err = os.path.join(config.FREEVO_LOGDIR,
'vbi2srt-stderr.log')
- try:
- self.log_stdout = open(fname_out, 'a')
- self.log_stderr = open(fname_err, 'a')
- except IOError:
- _debug_('Cannot open "%s" and "%s" for record logging!' % \
- (fname_out, fname_err), DERROR)
- print
- print 'Please set DEBUG=0 or start Freevo from a directory
that is writeable!'
- print
- else:
- _debug_('Record logging to "%s" and "%s"' % (fname_out,
fname_err), DINFO)
-
- childapp.ChildApp.__init__(self, app)
-
+ _debug_('RecordApp.__init__(app=%r)' % (app), 1)
+ childapp.ChildApp.__init__(self, app, doeslogging=1)
def kill(self):
childapp.ChildApp.kill(self, signal.SIGINT)
- if DEBUG:
- self.log_stdout.close()
- self.log_stderr.close()
-
class Record_Thread(threading.Thread):
-
+ """
+ """
def __init__(self):
+ _debug_('Record_Thread.__init__()', 1)
threading.Thread.__init__(self)
self.mode = 'idle'
@@ -226,10 +211,9 @@
elif self.mode == 'record':
rc.post_event(Event('RECORD_START', arg=self.prog))
- _debug_('cmd=%r' % self.command)
fc = FreevoChannels()
- _debug_('CHAN: %s' % fc.getChannel())
+ _debug_('channel %s' % fc.getChannel())
(v_norm, v_input, v_clist, v_dev) = config.TV_SETTINGS.split()
@@ -245,8 +229,7 @@
_debug_('Setting Channel to %s' % self.prog.tunerid)
fc.chanSet(str(self.prog.tunerid), False)
- _debug_('%s' % v.print_settings())
-
+ _debug_('command %r' % self.command)
self.app = RecordApp(self.command)
_debug_('app child pid: %s' % self.app.child.pid)
Modified: branches/rel-1/freevo/src/tv/v4l2.py
==============================================================================
--- branches/rel-1/freevo/src/tv/v4l2.py (original)
+++ branches/rel-1/freevo/src/tv/v4l2.py Wed Oct 17 10:58:47 2007
@@ -300,7 +300,7 @@
def setinput(self, value):
try:
r = fcntl.ioctl(self.device, i32(SETINPUT_NO),
struct.pack(INPUT_ST, value))
- _debug_('setinput: val=%r, res=%r' % (struct.pack(INPUT_ST,
value), r))
+ _debug_('setinput: val=%r, res=%r' % (struct.pack(INPUT_ST,
value), r), 3)
except IOError:
self.print_settings
raise
-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems? Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/
_______________________________________________
Freevo-cvslog mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/freevo-cvslog