Now shows the progress percentage when converting a file

Added better error checking (still needs to show an error window)
This commit is contained in:
Sergio Costas 2014-07-26 23:13:53 +02:00
parent 889325aaed
commit 8de307fd73
6 changed files with 86 additions and 50 deletions

View file

@ -7,6 +7,7 @@
<property name="height_request">270</property>
<property name="can_focus">False</property>
<property name="title" translatable="yes">devede</property>
<property name="window_position">center</property>
<property name="icon_name">devede.svg</property>
<property name="type_hint">dialog</property>
<child internal-child="vbox">

View file

@ -34,11 +34,14 @@ class avconv_converter(devede.executor.executor):
@staticmethod
def check_is_installed():
handle = subprocess.Popen(["avconv","-version"], stdout = subprocess.PIPE, stderr = subprocess.PIPE)
(stdout, stderr) = handle.communicate()
if 0==handle.wait():
return True
else:
try:
handle = subprocess.Popen(["avconv","-version"], stdout = subprocess.PIPE, stderr = subprocess.PIPE)
(stdout, stderr) = handle.communicate()
if 0==handle.wait():
return True
else:
return False
except:
return False
def __init__(self):
@ -312,7 +315,7 @@ class avconv_converter(devede.executor.executor):
def process_stdout(self,data):
pass
return
def process_stderr(self,data):
@ -321,5 +324,6 @@ class avconv_converter(devede.executor.executor):
pos+=5
pos2 = data[0].find(" ",pos)
if (pos2 != -1):
t = float(data[0][pos:pos2])
self.progress_bar[1].set_fraction(t / self.final_length)
t = float(data[0][pos:pos2]) / self.final_length
self.progress_bar[1].set_fraction(t)
self.progress_bar[1].set_text("%.1f%%" % (100.0 * t))

View file

@ -83,10 +83,10 @@ class executor(GObject.GObject):
def run(self, progress_bar):
self.progress_bar = progress_bar
self.launch_process(self.command_var)
self.progress_bar[0].set_label(self.text)
self.progress_bar[1].set_fraction(0.0)
self.progress_bar[0].show_all()
self.launch_process(self.command_var)
def remove_ansi(self,line):
@ -115,31 +115,50 @@ class executor(GObject.GObject):
return output
def launch_process(self,command):
def launch_process(self,command,redirect_output = True):
self.launch_command = "Launching:"
self.launch_command = "\n\nLaunching:"
for e in command:
self.launch_command += (e+" ")
self.launch_command += (" "+e)
self.launch_command += "\n"
print(self.launch_command)
try:
if (self.stdin_file != None):
self.handle = subprocess.Popen(command,stdin = subprocess.PIPE, stdout = subprocess.PIPE, stderr = subprocess.PIPE)
self.channel_stdin = GLib.IOChannel(self.handle.stdin.fileno())
self.channel_stdin.add_watch(GLib.IO_OUT | GLib.IO_HUP, self.read_stdin_from_file)
self.file_in = open(self.stdin_file,"rb")
else:
self.handle = subprocess.Popen(command,stdout = subprocess.PIPE, stderr = subprocess.PIPE)
except Exception as error_launch:
self.stderr_data += str(error_launch)
self.wait_end()
return
if (self.stdin_file != None):
self.handle = subprocess.Popen(command,stdin = subprocess.PIPE, stdout = subprocess.PIPE, stderr = subprocess.PIPE)
self.channel_stdin = GLib.IOChannel(self.handle.stdin.fileno())
self.channel_stdin.add_watch(GLib.IO_OUT | GLib.IO_HUP, self.read_stdin_from_file)
self.file_in = open(self.stdin_file,"rb")
if (redirect_output):
self.stdout_buf = ""
self.stderr_buf = ""
self.channel_stdout = GLib.IOChannel(self.handle.stdout.fileno())
self.channel_stderr = GLib.IOChannel(self.handle.stderr.fileno())
if (self.stdout_file != None):
self.channel_stdout.add_watch(GLib.IO_IN | GLib.IO_HUP,self.read_stdout_to_file)
self.file_out = open(self.stdout_file,"wb")
else:
self.channel_stdout.add_watch(GLib.IO_IN | GLib.IO_HUP,self.read_stdout)
self.channel_stderr.add_watch(GLib.IO_IN | GLib.IO_HUP,self.read_stderr)
else:
self.handle = subprocess.Popen(command,stdout = subprocess.PIPE, stderr = subprocess.PIPE)
self.channel_stdout = GLib.IOChannel(self.handle.stdout.fileno())
self.channel_stderr = GLib.IOChannel(self.handle.stderr.fileno())
if (self.stdout_file != None):
self.channel_stdout.add_watch(GLib.IO_IN | GLib.IO_HUP,self.read_stdout_to_file)
self.file_out = open(self.stdout_file,"wb")
else:
self.channel_stdout.add_watch(GLib.IO_IN | GLib.IO_HUP,self.read_stdout)
self.channel_stderr.add_watch(GLib.IO_IN | GLib.IO_HUP,self.read_stderr)
self.stdout_buf = ""
self.stderr_buf = ""
(stdout_r, stderr_r) = self.handle.communicate()
self.config.append_log(self.launch_command)
try:
self.config.append_log(stdout_r.decode("utf-8"))
except:
self.config.append_log(stdout_r.decode("latin-1"))
try:
self.config.append_log(stderr_r.decode("utf-8"))
except:
self.config.append_log(stderr_r.decode("latin-1"))
return (stdout_r, stderr_r)
def read_stdout_to_file(self,source,condition):
@ -176,7 +195,11 @@ class executor(GObject.GObject):
self.wait_end()
return False
else:
line_data = self.stdout_buf+(self.handle.stdout.read1(4096).decode("utf-8"))
read_data = self.handle.stdout.read1(4096)
try:
line_data = self.stdout_buf+(read_data.decode("utf-8"))
except:
line_data = self.stdout_buf+(read_data.decode("latin-1"))
self.stdout_data += line_data
data = (line_data).replace("\r","\n").split("\n")
if (len(data) == 1):
@ -198,7 +221,11 @@ class executor(GObject.GObject):
self.wait_end()
return False
else:
line_data = self.stderr_buf+(self.handle.stderr.read1(4096).decode("utf-8"))
read_data = self.handle.stderr.read1(4096)
try:
line_data = self.stderr_buf+(read_data.decode("utf-8"))
except:
line_data = self.stderr_buf+(read_data.decode("latin-1"))
self.stderr_data += line_data
data = (line_data).replace("\r","\n").split("\n")
if (len(data) == 1):
@ -226,5 +253,8 @@ class executor(GObject.GObject):
self.config.append_log(self.launch_command)
self.config.append_log(self.stdout_data)
self.config.append_log(self.stderr_data)
retval = self.handle.wait()
if self.handle != None:
retval = self.handle.wait()
else:
retval = -1
self.emit("ended",retval)

View file

@ -29,15 +29,19 @@ class mplayer_detector(devede.executor.executor):
@staticmethod
def check_is_installed():
handle = subprocess.Popen(["mplayer","-v"], stdout = subprocess.PIPE, stderr = subprocess.PIPE)
(stdout, stderr) = handle.communicate()
if 0==handle.wait():
return True
else:
try:
handle = subprocess.Popen(["mplayer","-v"], stdout = subprocess.PIPE, stderr = subprocess.PIPE)
(stdout, stderr) = handle.communicate()
if 0==handle.wait():
return True
else:
return False
except:
return False
def __init__(self):
devede.executor.executor.__init__(self)
self.config = devede.configuration_data.configuration.get_config()
def get_film_data(self, file_name):
@ -61,8 +65,7 @@ class mplayer_detector(devede.executor.executor):
command_line = ["mplayer","-loop","1","-identify", "-vo", "null", "-ao", "null", "-frames", frames , file_name]
handle = subprocess.Popen(command_line, stdout = subprocess.PIPE, stderr = subprocess.PIPE)
(stdout, stderr) = handle.communicate()
(stdout, stderr) = self.launch_process(command_line, False)
minimum_audio=-1
self.audio_list=[]
@ -75,8 +78,14 @@ class mplayer_detector(devede.executor.executor):
self.original_audiorate = 0
self.original_audiorate_uncompressed = 0
self.original_fps = 0
self.original_aspect_ratio = 0
for line in str(stdout).split("\\n"):
try:
stdout2 = stdout.decode("utf-8")
except:
stdout2 = stdout.decode("latin1")
for line in stdout2.split("\n"):
line=self.remove_ansi(line)
if line == "":
continue

View file

@ -41,13 +41,4 @@ class mux_dvd_menu(devede.executor.executor):
def process_stderr(self,data):
print("spumux: "+str(data))
return
pos = data[0].find("time=")
if (pos != -1):
pos+=5
pos2 = data[0].find(" ",pos)
if (pos2 != -1):
t = float(data[0][pos:pos2])
self.progress_bar[1].set_fraction(t / self.sound_length)

View file

@ -51,6 +51,7 @@ class runner(GObject.GObject):
f = Gtk.Frame()
p = Gtk.ProgressBar()
p.set_orientation(Gtk.Orientation.HORIZONTAL)
p.set_show_text(True)
f.add(p)
# A frame, a progress bar, and the process running in that bar
self.progress_bars.append([f, p, None])