| 1 |
#!/usr/bin/python3 |
| 2 |
|
| 3 |
## Printing troubleshooter |
| 4 |
|
| 5 |
## Copyright (C) 2010, 2014 Red Hat, Inc. |
| 6 |
## Copyright (C) 2010 Jiri Popelka <[email protected]> |
| 7 |
|
| 8 |
## This program is free software; you can redistribute it and/or modify |
| 9 |
## it under the terms of the GNU General Public License as published by |
| 10 |
## the Free Software Foundation; either version 2 of the License, or |
| 11 |
## (at your option) any later version. |
| 12 |
|
| 13 |
## This program is distributed in the hope that it will be useful, |
| 14 |
## but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 |
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 |
## GNU General Public License for more details. |
| 17 |
|
| 18 |
## You should have received a copy of the GNU General Public License |
| 19 |
## along with this program; if not, write to the Free Software |
| 20 |
## Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
| 21 |
|
| 22 |
from gi.repository import Gtk |
| 23 |
|
| 24 |
import subprocess |
| 25 |
from .base import * |
| 26 |
import os |
| 27 |
from timedops import TimedSubprocess |
| 28 |
|
| 29 |
class VerifyPackages(Question): |
| 30 |
def __init__ (self, troubleshooter): |
| 31 |
Question.__init__ (self, troubleshooter, "Verify packages") |
| 32 |
troubleshooter.new_page (Gtk.Label (), self) |
| 33 |
|
| 34 |
def display (self): |
| 35 |
self.answers = {} |
| 36 |
packages_verification = {} |
| 37 |
|
| 38 |
package_manager="/bin/rpm" |
| 39 |
if not os.access (package_manager, os.X_OK): |
| 40 |
return False |
| 41 |
|
| 42 |
packages = ["cups", |
| 43 |
"foomatic", |
| 44 |
"gutenprint", |
| 45 |
"hpijs", |
| 46 |
"hplip", |
| 47 |
"system-config-printer"] |
| 48 |
parent = self.troubleshooter.get_window () |
| 49 |
|
| 50 |
new_environ = os.environ.copy() |
| 51 |
new_environ['LC_ALL'] = "C" |
| 52 |
|
| 53 |
for package in packages: |
| 54 |
verification_args = [package_manager, "-V", package] |
| 55 |
try: |
| 56 |
self.op = TimedSubprocess (parent=parent, |
| 57 |
args=verification_args, |
| 58 |
close_fds=True, |
| 59 |
env=new_environ, |
| 60 |
stdin=subprocess.DEVNULL, |
| 61 |
stdout=subprocess.PIPE, |
| 62 |
stderr=subprocess.DEVNULL) |
| 63 |
(verif_stdout, verif_stderr, result) = self.op.run () |
| 64 |
except: |
| 65 |
# Problem executing command. |
| 66 |
return False |
| 67 |
packages_verification[package] = verif_stdout[:-1] |
| 68 |
|
| 69 |
self.answers['packages_verification'] = packages_verification |
| 70 |
return False |
| 71 |
|
| 72 |
def collect_answer (self): |
| 73 |
return self.answers |
| 74 |
|
| 75 |
def cancel_operation (self): |
| 76 |
self.op.cancel () |