Skip to content

Commit

Permalink
Make inter-process communication with install-printerdriver script mo…
Browse files Browse the repository at this point in the history
…re reliable

For adding package repositories and installing printer driver packages
out of them the install-printerdriver script is used. It provided data
to the caller from both stderr and stdout. As the data could come out
in an unexpected order a buffer could run full (especially with the
openprinting-gutenprint package which has a very long file list) and
block system-config-printer or make it crash (broken pipe).

Now all relevant data (progress and file list) is provided via stdout
and only stdout is read. This way the install-printerdriver script
works reliably.
  • Loading branch information
tillkamppeter authored and twaugh committed Jan 28, 2015
1 parent 25309c9 commit 830aba4
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 17 deletions.
16 changes: 11 additions & 5 deletions install-printerdriver.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,11 @@
def progress(progress, type, user_data):
if (type.value_name == "PK_PROGRESS_TYPE_PERCENTAGE" and
progress.props.package != None):
sys.stderr.write ("%d\n" % progress.props.percentage)
sys.stderr.flush ()
sys.stdout.write ("P%d\n" % progress.props.percentage)
sys.stdout.flush ()
else:
sys.stdout.write ("P%d\n" % -10)
sys.stdout.flush ()

set_debugging (True)

Expand Down Expand Up @@ -46,7 +49,7 @@ def progress(progress, type, user_data):
debugprint("pk.resolve")
try:
res = pk.resolve(PackageKitGlib.FilterEnum.NONE, [package],
None, lambda p, t, d: True, None)
None, progress, None)
repo_enable_needed = False
debugprint("pk.resolve succeeded")
except GLib.GError:
Expand Down Expand Up @@ -90,7 +93,7 @@ def progress(progress, type, user_data):
debugprint("pk.resolve")
try:
res = pk.resolve(PackageKitGlib.FilterEnum.NONE, [package],
None, lambda p, t, d: True, None)
None, progress, None)
debugprint("pk.resolve succeeded")
except GLib.GError:
debugprint("pk.resolve failed")
Expand Down Expand Up @@ -136,7 +139,7 @@ def progress(progress, type, user_data):
debugprint("pk.install_packages errored")
sys.exit(1)

debugprint("done")
debugprint("Package successfully installed")
# If we reach this point, the requested package is on the system, either
# because we have installed it now or because it was already there

Expand All @@ -150,3 +153,6 @@ def progress(progress, type, user_data):
if files:
for f in files[0].get_property('files'):
print(f)

# Tell the caller that we are done
print("done")
28 changes: 16 additions & 12 deletions newprinter.py
Original file line number Diff line number Diff line change
Expand Up @@ -981,24 +981,29 @@ def installdriverpackage (self, driver, onlycheckpresence = False):
try:
self.p = subprocess.Popen (args, env=new_environ, close_fds=True,
stdin=subprocess.DEVNULL,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
stdout=subprocess.PIPE)
# Keep the UI refreshed while we wait for
# the drivers query to complete.
(stdout, stderr) = (self.p.stdout, self.p.stderr)
done = False
while self.p.poll() == None:
line = stderr.readline ().strip()
line = stdout.readline ().strip()
if (len(line) > 0):
if line == "done":
done = True
break
try:
percentage = float(line)
if percentage > 0:
pbar.set_fraction(percentage/100)
except:
pass
elif line.startswith(b"P"):
try:
percentage = float(line[1:])
if percentage >= 0:
pbar.set_fraction(percentage/100)
else:
pbar.set_pulse_step(-percentage/100)
pbar.pulse()
except:
pass
else:
self.installed_driver_files.append(line.decode("utf-8"));
while Gtk.events_pending ():
Gtk.main_iteration ()
if not line:
Expand All @@ -1014,9 +1019,8 @@ def installdriverpackage (self, driver, onlycheckpresence = False):
self._installdialog.destroy ()
self._installdialog = None

if ret:
for line in stdout.readlines ():
self.installed_driver_files.append(line.decode("utf-8"));
if not ret:
self.installed_driver_files = [];

return ret

Expand Down

0 comments on commit 830aba4

Please sign in to comment.