From: <te...@us...> - 2003-08-06 12:22:18
|
Update of /cvsroot/quickrip/quickrip In directory sc8-pr-cvs1:/tmp/cvs-serv8375 Modified Files: base.py Removed Files: commandthread.py Log Message: Added threading support to base.py, and removed commandthread.py This way, you should still be able to use the base.QuickRip.run() method as before, only it will use a seperate thread :) Also updates on the CLI... have a look to see how much of a pain curses can be :) Index: base.py =================================================================== RCS file: /cvsroot/quickrip/quickrip/base.py,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** base.py 6 Aug 2003 11:01:07 -0000 1.4 --- base.py 6 Aug 2003 12:22:15 -0000 1.5 *************** *** 11,18 **** --- 11,64 ---- from __future__ import generators + from threading import * from time import sleep import sys, os, re, popen2, ConfigParser, copy import config # QuickRip global configuration. + + class CommandThread(Thread): + """Handle threading of external commands""" + def __init__(self, command, flushbuffer): + Thread.__init__(self) + self.command = command + self.flushbuffer = flushbuffer + + def run(self): + self.pipe = popen2.Popen4(self.command) + pid = self.pipe.pid + while 1: + try: + if self.flushbuffer: + line = self.pipe.fromchild.read(1000) + else: + line = self.pipe.fromchild.readline() + if not line: + break + yield line + except: + # For PyGtk... weird! + continue + + # Clean up process table + try: + self.kill_pipe() + except: + pass + try: + os.waitpid(pid, os.WNOHANG) + except: + pass + + + def kill_pipe(self): + """Kills current process (pipe)""" + try: + os.kill(self.pipe.pid, 9) + os.waitpid(self.pipe.pid, os.WNOHANG) + except: + pass + + + class QuickRip: """QuickRip base class, including the following methods: *************** *** 128,156 **** command[:0] = [self.config[program]] ! self.pipe = popen2.Popen4(command) ! pid = self.pipe.pid ! while 1: ! try: ! if flushbuffer: ! line = self.pipe.fromchild.read(1000) ! else: ! line = self.pipe.fromchild.readline() ! if not line: ! break ! yield line ! except: ! # For PyGtk... weird! ! sleep(1) ! continue ! # Clean up process table ! try: ! self.kill_pipe() ! except: ! pass ! try: ! os.waitpid(pid, os.WNOHANG) ! except: ! pass --- 174,181 ---- command[:0] = [self.config[program]] ! self.thread = CommandThread(command, flushbuffer) ! for line in self.thread.run(): ! yield line *************** *** 168,171 **** --- 193,197 ---- arguments = ['-vo', 'null', '-ao', 'null', '-v', 'dvd://', '-identify', '-quiet', '-nocache'] + numtitles = 0 re_title = re.compile('There are (\d*) titles on this DVD') re_error = re.compile('libdvdread: Could not open device') *************** *** 174,181 **** self.int_noTitles() if re_title.search(line): ! numtitles = re_title.search(line).group(1) return numtitles def getTitleInfo(self, no): """Find number of chapters, audio/subtitle languages & length for title""" --- 200,211 ---- self.int_noTitles() if re_title.search(line): ! numtitles = int(re_title.search(line).group(1)) ! ! if not numtitles: ! self.int_noTitles() return numtitles + def getTitleInfo(self, no): """Find number of chapters, audio/subtitle languages & length for title""" *************** *** 226,229 **** --- 256,261 ---- self.numtitles = self.getDVDInfo() + if self.numtitles is 0: + return self.int_dispDVD(self.numtitles) --- commandthread.py DELETED --- |