|
Server : Apache/2.2.2 (Fedora) System : Linux App1.pathumtani.go.th 2.6.20-1.2320.fc5smp #1 SMP Tue Jun 12 19:40:16 EDT 2007 i686 User : apache ( 48) PHP Version : 5.2.9 Disable Function : NONE Directory : /usr/sbin/ |
Upload File : |
#!/usr/bin/python -tt
#
# Copyright 2005 Red Hat, Inc.
#
# Jeremy Katz <katzj@redhat.com>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 2 only
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Library General Public License for more details.
#
# 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
import os, sys, fcntl
from optparse import OptionParser
try:
import gtk
import gtk.glade
import gobject
except Exception, e:
print >> sys.stderr, "Unable to import modules. Maybe you're not running under X?"
sys.exit(1)
from rhpl.exception import installExceptionHandler
from rhpl.translate import _, N_, textdomain, utf8
from yum.constants import *
from yum.packages import YumInstalledPackage
import repomd.packageSack
from pirut import *
from pirut.constants import *
from pirut.Errors import *
I18N_DOMAIN = "pirut"
if os.path.exists("data/PackageManager.glade"):
gladefn = "data/PackageManager.glade"
else:
gladefn = PIRUTUI + "PackageManager.glade"
# lame main loop runner... this should probably just be where we need it
def _runGtkMain(*args):
while gtk.events_pending():
gtk.main_iteration()
class PackageManager(GraphicalYumBase):
def __init__(self, config):
GraphicalYumBase.__init__(self, False, config)
self.setupLogging()
self.xml = gtk.glade.XML(gladefn, domain=I18N_DOMAIN)
self.mainwin = self.xml.get_widget("PackageManagerWindow")
self.mainwin.set_icon_from_file(PIRUTPIX + "pirut.png")
self._connectSignals()
self.mainwin.connect("delete_event", self.quit)
self._showPackageType = SHOW_ALL
self.progressbar = self.xml.get_widget("ProgressBar")
self.statusbar = self.xml.get_widget ("StatusBar")
def _busyCursor(self):
self.mainwin.window.set_cursor(gdk.Cursor(gdk.WATCH))
self.mainwin.set_sensitive(False)
_runGtkMain()
def _normalCursor(self):
self.mainwin.window.set_cursor(None)
self.mainwin.set_sensitive(True)
_runGtkMain()
def _connectSignals(self):
sigs = { "on_PackageManagerWindow_destroy": self.quit,
"on_quit_activate": self.quit,
"on_repositories_activate": self._repoConfig,
"on_about_activate": self._about,
"on_search_activate": self._showSearch,
"on_browse_activate": self._showBrowse,
"on_list_activate": self._showList,
"on_apply_activate": self._apply,
"on_browseButton_clicked": self._showBrowse,
"on_searchButton_clicked": self._showSearch,
"on_listButton_clicked": self._showList,
"on_applyButton_clicked": self._apply }
self.xml.signal_autoconnect(sigs)
def _modeChange(self, selection):
(model, i) = selection.get_selected()
if i:
mode = model.get_value(i, 0)
func = model.get_value(i, 2)
apply(func, ())
def __destroyCurrent(self):
mf = self.xml.get_widget("mainFrame")
child = mf.get_child()
if child:
mf.remove(child)
child.destroy()
return mf
def _showSearch(self, *args):
mf = self.__destroyCurrent()
x = gtk.glade.XML(self.xml.relative_file("PackageSearch.glade"),
root="searchBox", domain=I18N_DOMAIN)
w = x.get_widget("searchBox")
plist = PirutPackageList(self)
plist.connect("changed", self._searchPackageSelected,
x.get_widget("detailsTextView").get_buffer())
plist.doneAdding() # won't be populating with enough for time to matter
w.pack_start(plist, True, True)
b = x.get_widget("searchButton")
e = x.get_widget("searchEntry")
sb = x.get_widget("stopSearchButton")
b.connect("clicked", self._searchClicked, (e, plist, b, sb))
e.connect("activate", self._searchClicked, (e, plist, b, sb))
sb.connect("clicked", self._stopSearch, (b, sb))
self.searching = False
mf.add(w)
e.grab_focus()
def _searchPackageSelected(self, plist, po, buffer):
if po:
desc = po.returnSimple('description')
desc = desc.replace("\n\n", "\x00")
desc = desc.replace("\n", " ")
desc = desc.replace("&", "&")
desc = desc.replace("\x00", "\n\n")
desc = utf8(desc)
else:
desc = ""
buffer.set_text(desc)
def _stopSearch(self, widget, (search, stop)):
self.searching = False
self.progressbar.set_fraction(0)
self.progressbar.hide()
self.statusbar.pop(0)
search.show()
stop.hide()
_runGtkMain()
def _searchClicked(self, widget, (entry, plist, search, stop)):
t = entry.get_text().strip()
fields = ['name', 'summary', 'description']
plist.clear()
self.searching = True
search.hide()
stop.show()
self.progressbar.show()
self.statusbar.push(0, N_("Searching for '%s'") % (t))
_runGtkMain()
for (po, res) in self.searchGenerator(fields, [t]):
_runGtkMain()
if not self.searching:
break
self.progressbar.pulse()
if po.repoid == "installed":
type = SHOW_INSTALLED
else:
type = SHOW_AVAIL
if type != SHOW_INSTALLED and self.simpleDBInstalled(po.returnSimple('name')):
continue
plist.addPackage(po, type)
self._stopSearch(stop, (search, stop)) # it's done
def _showListProf(self, *args):
fn = "prof.0"
import hotshot, hotshot.stats
prof = hotshot.Profile(fn)
rc = prof.runcall(self.__showList)
prof.close()
stats = hotshot.stats.load(fn)
stats.strip_dirs()
stats.sort_stats('time', 'calls')
stats.print_stats(20)
return rc
def _showList(self, *args):
plist = PirutPackageList(self)
mf = self.__destroyCurrent()
mf.add(plist)
self._busyCursor()
pbar = PirutProgress(_("Reading software information"), self.mainwin)
pbar.show()
_runGtkMain()
# look through the available packages...
pos = self.pkgSack.returnNewestByNameArch()
num = 0
for po in pos:
num += 1
if self.simpleDBInstalled(po.returnSimple('name')):
continue
plist.addPackage(po, SHOW_AVAIL)
pbar.set_fraction(num * 0.5 / len(pos))
_runGtkMain()
# and then the rpmdb
hdrs = self.rpmdb.getHdrList()
num = 0
for hdr in hdrs:
num += 1
po = YumInstalledPackage(hdr)
plist.addPackage(po, SHOW_INSTALLED)
pbar.set_fraction(num * 0.45/len(hdrs) + 0.5)
_runGtkMain()
plist.doneAdding()
pbar.destroy()
self._normalCursor()
plist.grab_focus()
def _showBrowse(self, *args):
grpsel = PirutGroupSelector(self, self.xml.relative_file)
mf = self.__destroyCurrent()
mf.add(grpsel.vbox)
grpsel.doRefresh()
def _apply(self, *args):
if len(self.tsInfo) == 0:
d = gtk.MessageDialog(self.mainwin, gtk.DIALOG_MODAL,
gtk.MESSAGE_ERROR, gtk.BUTTONS_OK,
_("No software selected for installation "
"or removal."))
d.run()
d.destroy()
return
self.tsInfo.makelists()
d = PirutDetailsDialog(self.mainwin, gtk.MESSAGE_QUESTION,
[('gtk-cancel', gtk.RESPONSE_CANCEL),
(_("Continue"), gtk.RESPONSE_OK, 'gtk-ok')],
_("Package selections"),
_("You have selected the following software "
"installations and removals."))
b = gtk.TextBuffer()
tag = b.create_tag('bold')
tag.set_property('weight', pango.WEIGHT_BOLD)
tag = b.create_tag('indented')
tag.set_property('left-margin', 10)
types=[(self.tsInfo.installed,_("Installing:")),
(self.tsInfo.updated, _("Updating:")),
(self.tsInfo.removed, _("Removing:"))]
for (lst, strng) in types:
if len(lst) > 0:
i = b.get_end_iter()
b.insert_with_tags_by_name(i, "%s\n" %(strng,), "bold")
for txmbr in lst:
i = b.get_end_iter()
(n,a,e,v,r) = txmbr.pkgtup
b.insert_with_tags_by_name(i, "%s-%s-%s\n" % (n,v,r),
"indented")
d.set_details(buffer = b)
d.expand_details()
rc = d.run()
d.destroy()
if rc == gtk.RESPONSE_CANCEL:
return
try:
self.applyChanges(self.mainwin)
except PirutError:
return
d = gtk.MessageDialog(self.mainwin, gtk.DIALOG_MODAL,
gtk.MESSAGE_INFO, gtk.BUTTONS_OK,
_("Software installation successfully completed."))
d.show_all()
d.run()
d.destroy()
self.quit()
def run(self):
_runGtkMain()
self.doRefresh()
self.mainwin.show()
self._showBrowse()
gtk.main()
def doRefresh(self):
pbar = PirutProgressCallback(_("Retrieving software information"),
self.mainwin, self.log)
pbar.show()
self._busyCursor()
try:
self.reposSetup(pbar)
except yum.Errors.LockError:
pbar.destroy()
self._normalCursor()
d = gtk.MessageDialog(self.mainwin, gtk.DIALOG_MODAL,
gtk.MESSAGE_ERROR, gtk.BUTTONS_OK,
_("Another application is running which "
"is accessing software information."))
d.show_all()
d.run()
d.destroy()
sys.exit(1)
except PirutDownloadError, e:
pbar.destroy()
self._normalCursor()
d = gtk.MessageDialog(self.mainwin, gtk.DIALOG_MODAL,
gtk.MESSAGE_ERROR, gtk.BUTTONS_OK,
_("Unable to retrieve software information"))
d.format_secondary_text(_("Unable to retrieve software "
"information. This could be caused by "
"not having a network connection "
"available."))
d.show_all()
d.run()
d.destroy()
sys.exit(1)
self._normalCursor()
pbar.destroy()
def _repoConfig(self, *args):
d = gtk.MessageDialog(self.mainwin, gtk.DIALOG_MODAL,
gtk.MESSAGE_INFO, gtk.BUTTONS_OK,
"Repository configuration not yet implemented")
d.run()
d.destroy()
def _about(self, *args):
d = self.xml.get_widget("aboutDialog")
d.show_all()
d.run()
d.hide()
def quit(self, *args):
if 0 and len(self.tsInfo) > 0:
d = gtk.MessageDialog(self.mainwin, gtk.DIALOG_MODAL,
gtk.MESSAGE_QUESTION,
message_format =
_("Software selected and not installed. "
"Would you like to finish installing or "
"quit anyway, losing all package "
"selections?"))
d.add_button(_("_Don't quit"), gtk.RESPONSE_CANCEL)
d.add_button(_("_Quit anyway"), gtk.RESPONSE_OK)
rc = d.run()
d.destroy()
if rc == gtk.RESPONSE_OK:
GraphicalYumBase.quit(self)
else:
return
GraphicalYumBase.quit(self)
def main():
textdomain(I18N_DOMAIN)
gtk.glade.bindtextdomain(I18N_DOMAIN, "/usr/share/locale")
parser = OptionParser()
parser.add_option("-c", "--config", type="string",
dest="config", default="/etc/yum.conf",
help="Config file to use (default: /etc/yum.conf)")
(options,args) = parser.parse_args()
try:
pm = PackageManager(options.config)
except PirutError, e:
startupError(e)
pm.run()
if __name__ == "__main__":
installExceptionHandler("Software Manager", "")
main()