On 06/22/2017 10:54 AM, Radostin Stoyanov wrote: > --- > virtManager/create.py | 39 ++++++++++++++++++++++++++++++++++++--- > 1 file changed, 36 insertions(+), 3 deletions(-) > > diff --git a/virtManager/create.py b/virtManager/create.py > index 7396aba..d540bae 100644 > --- a/virtManager/create.py > +++ b/virtManager/create.py > @@ -18,10 +18,12 @@ > # MA 02110-1301 USA. > # > > +import fcntl > import logging > import threading > import time > import subprocess > +from os import O_NONBLOCK Similarly just use os.O_NONBLOCK > from os.path import exists, isdir > try: > import commands # Python2 only > @@ -32,6 +34,7 @@ from gi.repository import GObject > from gi.repository import Gtk > from gi.repository import Gdk > from gi.repository import Pango > +from gi.repository import Vte > > import virtinst > from virtinst import util > @@ -2551,9 +2554,26 @@ class vmmCreate(vmmGObjectUI): > > def _create_directory_tree(self, asyncjob, src, dest, user, passwd): > """ > - Call virt-bootstrap and wait until exitCode is returned > + Call virt-bootstrap and show state/details > """ > > + def feed_Vte_terminal(terminal, data): > + """Set the cursor of new line in Vte terminal at the beinging.""" *beginning Generally looks okay though - Cole > + terminal.feed(data.replace("\n", "\r\n")) > + > + def non_block_read(block): > + """Read stdout/stderr.""" > + fd = block.fileno() > + fl = fcntl.fcntl(fd, fcntl.F_GETFL) > + fcntl.fcntl(fd, fcntl.F_SETFL, fl | O_NONBLOCK) > + try: > + return block.read() > + except: > + return '' > + > + meter = asyncjob.get_meter() > + asyncjob.details_enable(Vte.Terminal(), feed_Vte_terminal) > + > cmd = ["virt-bootstrap", src, dest] > if user: > cmd += ["--username", user] > @@ -2566,11 +2586,24 @@ class vmmCreate(vmmGObjectUI): > stdout=subprocess.PIPE, > stderr=subprocess.PIPE) > > - stdout, stderr = bootstrap_proc.communicate() > + output = [] > + while bootstrap_proc.poll() is None: > + stdout = non_block_read(bootstrap_proc.stdout) > + stderr = non_block_read(bootstrap_proc.stderr) > + if stdout: > + asyncjob.details_update(stdout) > + if stderr: > + asyncjob.details_update(stderr) > + output.append(stderr) > + # Show the content of messages with type "Info" > + if stderr.startswith('INFO:'): > + meter.start( > + text=_(" ".join(stderr.split('\n')[0].split(':')[2:]))) > + > > if bootstrap_proc.returncode != 0: > asyncjob.set_error("virt-bootstrap did not complete successfully", > - "{}\n{}".format(stdout, stderr)) > + "\n".join(output)) > > def _container_image_bootstrap(self, src, dest, > src_auth_user=None, > _______________________________________________ virt-tools-list mailing list virt-tools-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/virt-tools-list