Back to index

system-config-printer  1.3.9+20120706
VerifyPackages.py
Go to the documentation of this file.
00001 #!/usr/bin/python
00002 
00003 ## Printing troubleshooter
00004 
00005 ## Copyright (C) 2010 Red Hat, Inc.
00006 ## Copyright (C) 2010 Jiri Popelka <jpopelka@redhat.com>
00007 
00008 ## This program is free software; you can redistribute it and/or modify
00009 ## it under the terms of the GNU General Public License as published by
00010 ## the Free Software Foundation; either version 2 of the License, or
00011 ## (at your option) any later version.
00012 
00013 ## This program is distributed in the hope that it will be useful,
00014 ## but WITHOUT ANY WARRANTY; without even the implied warranty of
00015 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016 ## GNU General Public License for more details.
00017 
00018 ## You should have received a copy of the GNU General Public License
00019 ## along with this program; if not, write to the Free Software
00020 ## Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
00021 
00022 import subprocess
00023 from base import *
00024 import os
00025 from timedops import TimedSubprocess
00026 
00027 class VerifyPackages(Question):
00028     def __init__ (self, troubleshooter):
00029         Question.__init__ (self, troubleshooter, "Verify packages")
00030         troubleshooter.new_page (gtk.Label (), self)
00031 
00032     def display (self):
00033         self.answers = {}
00034         packages_verification = {}
00035 
00036         package_manager="/bin/rpm"
00037         if not os.access (package_manager, os.X_OK):
00038             return False
00039 
00040         packages = ["cups",
00041                     "foomatic",
00042                     "gutenprint",
00043                     "hpijs",
00044                     "hplip",
00045                     "system-config-printer"]
00046         null = file ("/dev/null", "r+")
00047         parent = self.troubleshooter.get_window ()
00048 
00049         new_environ = os.environ.copy()
00050         new_environ['LC_ALL'] = "C"
00051 
00052         for package in packages:
00053             verification_args = [package_manager, "-V", package]
00054             try:
00055                 self.op = TimedSubprocess (parent=parent,
00056                                            args=verification_args,
00057                                            close_fds=True,
00058                                            env=new_environ,
00059                                            stdin=null,
00060                                            stdout=subprocess.PIPE,
00061                                            stderr=null)
00062                 (verif_stdout, verif_stderr, result) = self.op.run ()
00063             except:
00064                 # Problem executing command.
00065                 return False
00066             packages_verification[package] = verif_stdout[:-1]
00067 
00068         self.answers['packages_verification'] = packages_verification
00069         return False
00070 
00071     def collect_answer (self):
00072         return self.answers
00073 
00074     def cancel_operation (self):
00075         self.op.cancel ()