Subprocess.call pipeline exit to progress bar

I use growisofs to write iso through my Python application. I have two classes in two different files; GUI () (main.py) and Boxblaze () (core.py). GUI () creates a window and handles all events and stuff, and Boxblaze () has all the methods that GUI () calls.

Now that the user has selected a device for recording and a file for recording, I need to call a method that calls the following command: `

growisofs -use-the-force-luke=dao -use-the-force-luke=break:1913760 -dvd-compat -speed=2 -Z /burner/device=/full/path/to.iso

This command should produce a similar result:

Executing 'builtin_dd if=/home/nevon/games/Xbox 360 isos/The Godfather 2/alls-tgod2.iso of=/dev/scd0 obs=32k seek=0'
/dev/scd0: "Current Write Speed" is 2.5x1352KBps.
#more of the lines below, indicating progress.
7798128640/7835492352 (99.5%) @3.8x, remaining 0:06 RBU 100.0% UBU  99.8%
7815495680/7835492352 (99.7%) @3.8x, remaining 0:03 RBU  59.7% UBU  99.8%
7832862720/7835492352 (100.0%) @3.8x, remaining 0:00 RBU   7.9% UBU  99.8%
builtin_dd: 3825936*2KB out @ average 3.9x1352KBps
/dev/burner: flushing cache
/dev/burner: closing track
/dev/burner: closing disc

This command is run in the burn () method in Boxblaze (). It just looks like this:

def burn(self, file, device):
    subprocess.call(["growisofs", '-dry-run', "-use-the-force-luke=dao", "-use-the-force-luke=break:1913760", "-dvd-compat", "-speed=2", "-Z",  device +'='+ file])

Now my questions are as follows:

  • How can I get the result from the output (percentage in brackets) and set the progress bar to “follow” this progress? My execution line is called in the GUI () class:

    get = builder.get_object

    self.progress_window = get ( "progressWindow" )

    self.progressbar = get ( "progressbar" )

  • , ( , )? , ?


Launchpad, . , :

bzr branch lp:boxblaze

, , , Linux, - .

+3
4

glib.io_add_watch() , stdout stderr .

proc = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
stdout_id = glib.io_add_watch(proc.stdout, glib.IO_IN|glib.IO_HUP, stdout_cb)
stderr_id = glib.io_add_watch(proc.stderr, glib.IO_IN|glib.IO_HUP, stderr_cb)

, , , ProgressBar. io, , , pty, , , , .

+2

, subprocess.Popen. (stdout = subprocess.PIPE)

( )

, , GUI filedescriptor .

, , ( ), , .

## You might have to redirect stderr instead/as well
proc = sucprocess.Popen(command,stdout=subprocess.PIPE)
for line in proc.stdout.readlines():
    ## might not work - not sure about reading lines
    ## Parse the line to extract progress
    ## Pass progress to GUI thread

Edit:

, -, , , , stdout, stderr.

stdout stderr .

growisofs [options] >stdout 2>stderr

, stdout stderr.

stderr, stdout=subprocess.PIPE stderr=subprocess.PIPE , .

Edit2:

- - .

:

gtk.gdk.threads_init()
threading.Thread.__init__(self)

- - , gtk?

, run(), :

core.Burning.run(self.burning, self.filechooser.get_filename(), self.listofdevices[self.combobox.get_active()])

:

self.burning.run(self.filechooser.get_filename(), self.listofdevices[self.combobox.get_active()])

( __init__())

, , . , growisofs , gtk + background threading code, . - , .

. , python, , ..

+1

? , , subProcess . growiso.read(.1), outdata (, , errdata).

0

gui gobject.idle_add. "Burning", , :

self.burning = core.Burning(self.filechooser.get_filename(), self.listofdevices[self.combobox.get_active()], self.progressbar)
self.burning.start()

, core.Burning. , ​​:

def set_progress_bar_fraction(self, fraction): 
    self.progress_bar.set_fraction(fraction)

: gobject.idle_add(self.set_progress_bar_fraction, fraction)

More info on pygtk with threads here .

0
source

Source: https://habr.com/ru/post/1715268/


All Articles