Viewing file: SinglePackageWindow.py (9.49 KB) -rw-r--r-- Select action/file-type: (+) | (+) | (+) | Code (+) | Session (+) | (+) | SDB (+) | (+) | (+) | (+) | (+) | (+) |
#!/usr/bin/python # # Installs a single package and its deps # # most of the code here is ripped straight out of InstallDruid.py # # Copyright 2002, 2003 Red Hat, Inc. # # This software may be freely redistributed under the terms of the GNU # General Public License. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. #
import os, sys, string import locale, signal, getopt import rpm import gtk import gtk.glade import gnome.ui import method
from constants import * from GroupSet import Package from method import DepsCheckLoop, DepsCheckComps, UnresolvableDependencies from config import * from SummaryModel import SummaryModel, setup_summary_tree from Progress import * from ProgressDialog import * from size_string import size_string from InstallProgressDialog import * from UnresolvableDependenciesDialog import * from CompsCheckDialog import *
from rhpl.GenericError import * from rhpl.translate import _, N_, textdomain
class SinglePackageWindow: def __init__(self, files, fullmethod = None): if not files: GenericError(TYPE_ERROR, _("No Files Specified."), _("Please specify files to install as " "arguments.")).display() sys.exit (1) else: self.files = files
if fullmethod == None: self.fullmethod = method.RedHatCdromInstallMethod() else: self.fullmethod = fullmethod
self.method = method.IndividualInstallMethod() self.usingfulltree = 0 self.progress_dialog = None
self.ts = None
def do_package_check (self): # A sanity check step to make sure that everything is sane ts = rpm.TransactionSet("/") ts.setVSFlags(~(rpm.RPMVSF_NORSA|rpm.RPMVSF_NODSA)) ts.setFlags(~rpm.RPMTRANS_FLAG_NOMD5) for file in self.files: try: fd = os.open(file, os.O_RDONLY) except (OSError, IOError): del (ts) GenericError (TYPE_ERROR, _("Could Not Open Package"), _("The file \"%s\" could not be read. Make sure that you have the proper permissions on it") % file).display () sys.exit (0) h = ts.hdrFromFdno(fd) os.close (fd) if h is None: del (ts) GenericError (TYPE_ERROR, _("Could Not Open Package"), _("The file \"%s\" does not appear to be a valid RPM file.") % file).display () sys.exit (0)
# We always install source RPMS if h[rpm.RPMTAG_SOURCEPACKAGE] == 1: del (ts) GenericError (TYPE_ERROR, _("Source RPM"), _("The file \"%s\" is a source RPM which cannot " "be installed with system-config-packages.") %(file,)).display() sys.exit(0)
mi = ts.dbMatch('name', h[rpm.RPMTAG_NAME]) for n in mi: compare = rpm.versionCompare (h, n) if compare > 0: continue elif compare < 0: message = _("A newer version of \"%s\" is currently installed.") % h[rpm.RPMTAG_NAME] elif compare == 0: message = _("The package \"%s\" is currently installed.") % h[rpm.RPMTAG_NAME] del (ts) GenericError (TYPE_WARNING, _("Package already installed"), message).display () sys.exit (0)
# FIXME: Check to see if it has no dependencies here. del (ts) def do_initial_setup (self): if self.progress_dialog is None: self.progress_dialog = InstallProgressDialog (None) def delete_event (window, event, dialog): dialog.cancel () return True self.progress_dialog.get_dialog().connect ('delete_event', delete_event, self.progress_dialog) try: self.progress_dialog.get_dialog().show ()
self.progress_dialog.prepare_block (0.1, _("Finding Tree")) self.progress_dialog.update (1.0)
self.progress_dialog.prepare_block (0.1, _("Reading RPM Headers")) hdlist = self.method.readHeaders() self.progress_dialog.update (1.0)
self.progress_dialog.prepare_block (0.3, _("Processing Headers")) hdlist.mergeRpmDb() self.progress_dialog.update (1.0)
self.progress_dialog.prepare_block (0.1, _("Reading individual package headers")) for file in self.files: if not os.access(file, os.O_RDONLY): # FIXME: should this be a failure case? print >> sys.stderr, "Unable to open file: %s" %(file,) continue ts = rpm.TransactionSet() ts.setVSFlags(~(rpm.RPMVSF_NORSA|rpm.RPMVSF_NODSA)) ts.setFlags(~rpm.RPMTRANS_FLAG_NOMD5) ts.closeDB() fd = os.open(file, os.O_RDONLY) h = ts.hdrFromFdno(fd) os.close (fd)
if h[rpm.RPMTAG_SOURCEPACKAGE] == 1: # FIXME: should this be a failure case? print >> sys.stderr, "We don't install src.rpms: %s" %(file,) continue
p = hdlist.addHeader(h, self.method) p.select() p.setFilename(file) self.progress_dialog.update (1.0)
self.progress_dialog.prepare_block (0.4, _("Reading system state")) self.comps = self.method.readCompsViaMethod(hdlist, None) self.progress_dialog.update (1.0) except ProgressCanceled: sys.exit (0)
def do_deps_check(self): try: self.ts = self.method.setupTransaction(self.comps, self.progress_dialog) except CancelInstallation: sys.exit (0) except DepsCheckLoop: # FIXME if we ever add uninstall package support GenericError(TYPE_ERROR, _("Dependency Loop Found."), _("A dependency loop was found. This tool does not support uninstalling packages yet.")).display() sys.exit (1) except DepsCheckComps: dialog = CompsCheckDialog (sys.exc_value.failed_list, sys.exc_value.unremovable_list, self.progress_dialog.get_dialog ()) dialog.run () sys.exit (0) except UnresolvableDependencies: if self.usingfulltree == 1: dialog = UnresolvableDependenciesDialog (sys.exc_value.unresolvable_dependencies, self.progress_dialog.get_dialog ()) dialog.run () sys.exit (0) return else: # we weren't using the full tree, so change method to point # at the full tree and then rerun self.usingfulltree = 1 self.method = self.fullmethod self.progress_dialog.switch_mode(MODE_PROGRESS) self.progress_dialog.clear() self.run()
def do_summary(self): self.progress_dialog.info_from_comps (self.ts, self.comps.hdrlist) self.progress_dialog.switch_mode (MODE_INFO) if not self.progress_dialog.continue_install_test (): sys.exit (0)
def do_install(self): try: self.progress_dialog.switch_mode (MODE_INSTALL) self.method.installPackages(self.ts, self.comps, self.progress_dialog) self.progress_dialog.switch_mode (MODE_POST_INSTALL) except ProgressCanceled: sys.exit (0) def run (self): i = gtk.Invisible() i.selection_owner_set("_NAUTILUS_DISABLE_MOUNT_WINDOW")
self.do_package_check () self.do_initial_setup () self.do_deps_check () self.do_summary () self.do_install ()
def help(): sys.stderr.write("Usage: system-install-packages %s\n" %(default_args_help(),))
if __name__ == '__main__': locale.setlocale(locale.LC_ALL,"") signal.signal (signal.SIGINT, signal.SIG_DFL)
if os.geteuid() != 0: GenericError (TYPE_ERROR, _("Your account does not have permissions to run %s.") % "system-install-packages", _("Administrator level permissions are needed to run this program because it can install and remove system packages.")).display () sys.exit (1) try: (args, extra) = getopt.getopt(sys.argv[1:], default_short_args(), default_long_args()) except getopt.GetoptError, e: sys.stderr.write(str(e)) sys.stderr.write("\n") help() sys.exit(1) for (arg, val) in args: if (arg == '--help'): help() sys.exit(0)
mainmethod = get_method(args)
textdomain(PROGNAME) gtk.glade.bindtextdomain(PROGNAME, "/usr/share/locale") main_window = SinglePackageWindow (extra, mainmethod) main_window.run()
|