Author: dmeyer
Date: Sat Jan 13 20:39:08 2007
New Revision: 8976
Modified:
trunk/tvdev/bin/freevo-tvdev
Log:
support start/stop
Modified: trunk/tvdev/bin/freevo-tvdev
==============================================================================
--- trunk/tvdev/bin/freevo-tvdev (original)
+++ trunk/tvdev/bin/freevo-tvdev Sat Jan 13 20:39:08 2007
@@ -1,10 +1,39 @@
#!/usr/bin/env python
+# -*- coding: iso-8859-1 -*-
+# -----------------------------------------------------------------------------
+# freevo-tvdev - start script for the tvdev
+# -----------------------------------------------------------------------------
+# $Id$
+#
+# -----------------------------------------------------------------------------
+# Freevo - A Home Theater PC framework
+# Copyright (C) 2002-2007 Krister Lagerstrom, Dirk Meyer, et al.
+#
+# Maintainer: Dirk Meyer <[EMAIL PROTECTED]>
+#
+# Please see the file 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 sys
import os
import socket
import getopt
-import ConfigParser
import logging
# insert freevo path information
@@ -16,8 +45,10 @@
# fix possible path problems (it crashes on some python installations)
if os.path.dirname(__file__) in sys.path:
sys.path.remove(os.path.dirname(__file__))
-
+
+# kaa imports
import kaa
+import kaa.utils
# FIXME: we only need to import this because we need i18n and logging
import freevo.conf
@@ -34,93 +65,107 @@
# force special config file
cfgfile = ''
-def usage():
- bin = os.path.basename(sys.argv[0])
- print '\nusage:'
- print '"%s" to start' % bin
- print '"%s list" to list all devices' % bin
- print '"%s scan device" scan for channels (analog tv only)' % bin
- print
+def usage(error_code):
+ print 'freevo-tvdev [options]'
print 'options:'
- print '-c config file'
- sys.exit(0)
-
+ print '-c configfile set config filename'
+ print '--background start tvdev in background'
+ print '--stop stop running tvdev'
+ print '--list list all devices'
+ print '--help | -h this message'
+ sys.exit(error_code)
options = 'hc:'
-loptions = ['help']
+loptions = [ 'background', 'stop', 'list' 'help']
try:
opts, args = getopt.getopt(sys.argv[1:], options, loptions)
except getopt.GetoptError, e:
- print 'Error:', e
- usage()
+ usage(1)
for o, a in opts:
if o in ('-h', '--help'):
- usage()
+ usage(0)
+
if o == '-c':
cfgfile = a
-if len(args) == 0:
- freevo.tvdev.detect(cfgfile)
- if not freevo.tvdev.create():
- log.error('no active devices found, terminate')
- usage()
+ if o == '--background':
+ if kaa.utils.is_running('freevo-tvdev'):
+ print 'tvdev already running'
+ sys.exit(1)
+ kaa.utils.daemonize()
+
+ if o == '--stop':
+ pid = kaa.utils.is_running('freevo-tvdev')
+ if not pid:
+ print 'tvdev not running'
+ sys.exit(1)
+ os.kill(pid, 15)
sys.exit(0)
- # create controller
- c = freevo.tvdev.Controller()
+ if o == '--list':
+ freevo.tvdev.detect(cfgfile)
- # start main loop
- kaa.main()
+ for card in freevo.tvdev.cards:
+ print '*** %s ***' % card.device
+ print card.info()
+
+ filename = freevo.tvdev.config.get_filename()
+ if cfgfile:
+ print 'using given config file', cfgfile
+ else:
+ print 'using system config file /etc/freevo/tvdev.conf'
+ if filename != '/etc/freevo/tvdev.conf':
+ print 'and personal file', filename
+ sys.exit(0)
- # print debug at the end
- log.info('terminate')
- sys.exit(0)
+ if o == '--scan':
+ from kaa.record.v4l_tuner import V4L as Tuner
+ from kaa.record.v4l_scan import scan
+ from kaa.record.v4l_frequencies import CHANLIST
+ from kaa.record._vbi import VBI
+
+ freevo.tvdev.detect(cfgfile)
+
+ for card in freevo.tvdev.cards:
+ if card.device == args[1]:
+ break
+ else:
+ print 'Invalid device %s' % args[1]
+ sys.exit(1)
+
+ tuner = Tuner(card.vdev, card.norm, card.chanlist)
+ # FIXME: make this an option
+ tuner.setinput(0)
+
+ vbi = VBI(card.vdev.replace('/video', '/vbi'))
+ channels = kaa.record.v4l_scan.scan(tuner, vbi,
CHANLIST[card.chanlist])
+ # Now we need to write the channels to a channels.conf we
+ # can read again later. This is still missing
+ print 'FIXME: we can not save the config right now, sorry'
+ sys.exit(0)
-if args[0] == 'list':
- freevo.tvdev.detect(cfgfile)
- for card in freevo.tvdev.cards:
- print '*** %s ***' % card.device
- print card.info()
-
- filename = freevo.tvdev.config.get_filename()
- if cfgfile:
- print 'using given config file', cfgfile
- else:
- print 'using system config file /etc/freevo/tvdev.conf'
- if filename != '/etc/freevo/tvdev.conf':
- print 'and personal file', filename
- sys.exit(0)
+# normal start
-elif args[0] == 'scan':
- from kaa.record.v4l_tuner import V4L as Tuner
- from kaa.record.v4l_scan import scan
- from kaa.record.v4l_frequencies import CHANLIST
- from kaa.record._vbi import VBI
-
- if len(args) < 2:
- usage()
-
- freevo.tvdev.detect(cfgfile)
-
- for card in freevo.tvdev.cards:
- if card.device == args[1]:
- break
- else:
- print 'Invalid device %s' % args[1]
- sys.exit(1)
-
- tuner = Tuner(card.vdev, card.norm, card.chanlist)
- # FIXME: make this an option
- tuner.setinput(0)
-
- vbi = VBI(card.vdev.replace('/video', '/vbi'))
- channels = kaa.record.v4l_scan.scan(tuner, vbi, CHANLIST[card.chanlist])
- # Now we need to write the channels to a channels.conf we
- # can read again later. This is still missing
- print 'FIXME: we can not save the config right now, sorry'
+if kaa.utils.is_running('freevo-tvdev'):
+ print 'tvdev already running'
+ sys.exit(1)
-else:
+kaa.utils.set_running('freevo-tvdev')
+
+freevo.tvdev.detect(cfgfile)
+if not freevo.tvdev.create():
+ log.error('no active devices found, terminate')
usage()
+ sys.exit(0)
+
+# create controller
+c = freevo.tvdev.Controller()
+
+# start main loop
+kaa.main()
+
+# print debug at the end
+log.info('terminate')
-------------------------------------------------------------------------
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