minor class renaming
[pyvconv.git] / command_executer.py
blob0fdddc5f5e1e344d621c26b090d5736842bb137c
1 # Pyvconv - A simple frontend for ffmpeg/mencoder
2 # Copyright (C) 2008, Kristian Rumberg (kristianrumberg@gmail.com)
4 # Permission to use, copy, modify, and/or distribute this software for any
5 # purpose with or without fee is hereby granted, provided that the above
6 # copyright notice and this permission notice appear in all copies.
8 # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16 import os
17 import subprocess
18 import thread
19 from commands import Variable
21 class CommandExecuterView:
22 def __init__(self):
23 pass
25 def starting_conversion(self, infile, index, total, outfile):
26 pass
28 def update_progress(self, logline):
29 pass
31 def finished_conversion(self, infile, outfile):
32 pass
34 def finished_all(self):
35 pass
37 class CommandExecuter:
38 def __init__(self, cmdexecview, command, infilelist, outdir):
39 self.cmdexecview = cmdexecview
40 self.command = command
41 self.infilelist = infilelist
42 self.outdir = outdir
44 thread.start_new_thread(self._run_conversion, ())
46 def _run_conversion(self):
47 index = 0
48 total = len(self.infilelist)
50 for infile in self.infilelist:
51 outfile = self.outdir + "/" + os.path.basename(infile) + "_converted"
53 index = index + 1
55 self.command.put_var(Variable("in", infile))
56 self.command.put_var(Variable("out", outfile))
58 self.cmdexecview.starting_conversion(infile, index, total, outfile)
60 p = subprocess.Popen(str(self.command), shell = True, universal_newlines=True, stderr = subprocess.PIPE)
61 ostream = p.stderr
62 newline = str(chr(32) * 4)
63 buff = ""
64 c = 1
65 iskip = 10
66 skipc = 0
68 while c:
69 c = ostream.read(1)
70 buff = buff + c
71 if buff.endswith(newline):
72 skipc = (skipc + 1) % iskip
73 if skipc == 0:
74 self.cmdexecview.update_progress(buff.strip())
75 buff = ""
77 ostream.close()
79 self.cmdexecview.finished_conversion(infile, outfile)
81 self.cmdexecview.finished_all()