working update manager

This commit is contained in:
guinux 2012-12-15 17:27:36 +01:00
parent 6aaa0494a1
commit 1a65d11a37
7 changed files with 272 additions and 220 deletions

View File

@ -10,6 +10,7 @@ import collections
import warnings
import pyalpm
from transaction import ErrorDialog
class InvalidSyntax(Warning):
def __init__(self, filename, problem, arg):
@ -111,6 +112,10 @@ def cb_log(level, line):
if not (level & _logmask):
return
if level & pyalpm.LOG_ERROR:
ErrorDialog.format_secondary_text(line)
response = ErrorDialog.run()
if response:
ErrorDialog.hide()
line = "ERROR: " + line
elif level & pyalpm.LOG_WARNING:
line = "WARNING: " + line

View File

@ -1,6 +1,111 @@
<?xml version="1.0" encoding="UTF-8"?>
<interface>
<!-- interface-requires gtk+ 3.0 -->
<object class="GtkMessageDialog" id="ConfDialog">
<property name="width_request">250</property>
<property name="height_request">150</property>
<property name="can_focus">False</property>
<property name="hexpand">True</property>
<property name="vexpand">True</property>
<property name="border_width">5</property>
<property name="title" translatable="yes"> </property>
<property name="window_position">center-on-parent</property>
<property name="default_width">200</property>
<property name="default_height">100</property>
<property name="type_hint">dialog</property>
<property name="skip_taskbar_hint">True</property>
<property name="message_type">other</property>
<property name="buttons">ok-cancel</property>
<property name="text" translatable="yes">&lt;b&gt;Transaction summary&lt;/b&gt;</property>
<property name="use_markup">True</property>
<child internal-child="vbox">
<object class="GtkBox" id="messagedialog-vbox3">
<property name="can_focus">False</property>
<property name="hexpand">True</property>
<property name="vexpand">True</property>
<property name="orientation">vertical</property>
<child internal-child="action_area">
<object class="GtkButtonBox" id="messagedialog-action_area3">
<property name="can_focus">False</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="pack_type">end</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkScrolledWindow" id="scrolledwindow4">
<property name="width_request">200</property>
<property name="height_request">120</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="hexpand">True</property>
<property name="vexpand">True</property>
<property name="shadow_type">in</property>
<child>
<object class="GtkTreeView" id="treeview4">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="vexpand">True</property>
<property name="model">transaction_desc</property>
<property name="headers_visible">False</property>
<property name="headers_clickable">False</property>
<property name="enable_search">False</property>
<property name="search_column">0</property>
<child internal-child="selection">
<object class="GtkTreeSelection" id="treeview-selection"/>
</child>
<child>
<object class="GtkTreeViewColumn" id="_action">
<property name="title" translatable="yes">column</property>
<child>
<object class="GtkCellRendererText" id="cellrenderertext5">
<property name="yalign">0</property>
<property name="weight">600</property>
</object>
<attributes>
<attribute name="text">0</attribute>
</attributes>
</child>
</object>
</child>
<child>
<object class="GtkTreeViewColumn" id="_packages">
<property name="title" translatable="yes">column</property>
<child>
<object class="GtkCellRendererText" id="cellrenderertext6"/>
<attributes>
<attribute name="text">1</attribute>
</attributes>
</child>
</object>
</child>
</object>
</child>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">2</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="down_label">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">label</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">4</property>
</packing>
</child>
</object>
</child>
</object>
<object class="GtkMessageDialog" id="ErrorDialog">
<property name="can_focus">False</property>
<property name="border_width">5</property>
@ -81,4 +186,12 @@
</object>
</child>
</object>
<object class="GtkListStore" id="transaction_desc">
<columns>
<!-- column-name action -->
<column type="gchararray"/>
<!-- column-name packages -->
<column type="gchararray"/>
</columns>
</object>
</interface>

View File

@ -1,115 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<interface>
<!-- interface-requires gtk+ 3.0 -->
<object class="GtkMessageDialog" id="ConfDialog">
<property name="width_request">250</property>
<property name="height_request">150</property>
<property name="can_focus">False</property>
<property name="hexpand">True</property>
<property name="vexpand">True</property>
<property name="border_width">5</property>
<property name="title" translatable="yes"> </property>
<property name="window_position">center-on-parent</property>
<property name="default_width">200</property>
<property name="default_height">100</property>
<property name="type_hint">dialog</property>
<property name="skip_taskbar_hint">True</property>
<property name="message_type">other</property>
<property name="buttons">ok-cancel</property>
<property name="text" translatable="yes">&lt;b&gt;Transaction summary&lt;/b&gt;</property>
<property name="use_markup">True</property>
<child internal-child="vbox">
<object class="GtkBox" id="messagedialog-vbox3">
<property name="width_request">240</property>
<property name="height_request">140</property>
<property name="can_focus">False</property>
<property name="hexpand">True</property>
<property name="vexpand">True</property>
<property name="orientation">vertical</property>
<child internal-child="action_area">
<object class="GtkButtonBox" id="messagedialog-action_area3">
<property name="can_focus">True</property>
<property name="has_focus">True</property>
<property name="is_focus">True</property>
<property name="layout_style">end</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="pack_type">end</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkScrolledWindow" id="scrolledwindow4">
<property name="width_request">200</property>
<property name="height_request">120</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="hexpand">True</property>
<property name="vexpand">True</property>
<property name="shadow_type">in</property>
<child>
<object class="GtkTreeView" id="treeview4">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="vexpand">True</property>
<property name="model">transaction_desc</property>
<property name="headers_visible">False</property>
<property name="headers_clickable">False</property>
<property name="enable_search">False</property>
<child internal-child="selection">
<object class="GtkTreeSelection" id="treeview-selection1"/>
</child>
<child>
<object class="GtkTreeViewColumn" id="_action">
<property name="title" translatable="yes">column</property>
<child>
<object class="GtkCellRendererText" id="cellrenderertext5">
<property name="yalign">0</property>
<property name="weight">600</property>
</object>
<attributes>
<attribute name="text">0</attribute>
</attributes>
</child>
</object>
</child>
<child>
<object class="GtkTreeViewColumn" id="_packages">
<property name="title" translatable="yes">column</property>
<child>
<object class="GtkCellRendererText" id="cellrenderertext6"/>
<attributes>
<attribute name="text">1</attribute>
</attributes>
</child>
</object>
</child>
</object>
</child>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">2</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="down_label">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">label</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">4</property>
</packing>
</child>
</object>
</child>
</object>
<object class="GtkListStore" id="groups_list">
<columns>
<!-- column-name name -->
@ -504,12 +395,4 @@
</row>
</data>
</object>
<object class="GtkListStore" id="transaction_desc">
<columns>
<!-- column-name action -->
<column type="gchararray"/>
<!-- column-name packages -->
<column type="gchararray"/>
</columns>
</object>
</interface>

View File

@ -1,11 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<interface>
<!-- interface-requires gtk+ 3.0 -->
<object class="GtkWindow" id="MainWindow">
<object class="GtkWindow" id="UpdateWindow">
<property name="can_focus">False</property>
<property name="title" translatable="yes"> </property>
<property name="title" translatable="yes">Update Manager</property>
<property name="window_position">center</property>
<signal name="delete-event" handler="on_MainWindow_delete_event" swapped="no"/>
<signal name="delete-event" handler="on_UpdateWindow_delete_event" swapped="no"/>
<child>
<object class="GtkBox" id="box1">
<property name="can_focus">False</property>
@ -15,22 +15,23 @@
<property name="spacing">2</property>
<child>
<object class="GtkButtonBox" id="buttonbox1">
<property name="can_focus">False</property>
<property name="can_focus">True</property>
<property name="has_focus">True</property>
<property name="spacing">5</property>
<property name="layout_style">end</property>
<child>
<object class="GtkButton" id="RefreshButton">
<property name="label">gtk-refresh</property>
<object class="GtkButton" id="ApplyButton">
<property name="label">gtk-apply</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="use_stock">True</property>
<signal name="clicked" handler="on_RefreshButton_clicked" swapped="no"/>
<signal name="clicked" handler="on_ApplyButton_clicked" swapped="no"/>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
<property name="position">1</property>
</packing>
</child>
<child>
@ -42,21 +43,6 @@
<property name="use_stock">True</property>
<signal name="clicked" handler="on_QuitButton_clicked" swapped="no"/>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
<child>
<object class="GtkButton" id="ApplyButton">
<property name="label">gtk-apply</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="use_stock">True</property>
<signal name="clicked" handler="on_ApplyButton_clicked" swapped="no"/>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
@ -89,10 +75,9 @@
<property name="width_request">390</property>
<property name="height_request">490</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="can_focus">False</property>
<property name="hexpand">True</property>
<property name="vexpand">True</property>
<property name="shadow_type">in</property>
<child>
<object class="GtkTreeView" id="treeview1">
<property name="visible">True</property>

View File

@ -18,19 +18,13 @@ interface.add_from_file('gui/dialogs.glade')
packages_list = interface.get_object('packages_list')
groups_list = interface.get_object('groups_list')
transaction_desc = interface.get_object('transaction_desc')
package_desc = interface.get_object('package_desc')
conf_label = interface.get_object('conf_label')
toggle = interface.get_object('cellrenderertoggle1')
search_entry = interface.get_object('search_entry')
tree2 = interface.get_object('treeview2_selection')
tree1 = interface.get_object('treeview1_selection')
installed_column = interface.get_object('installed_column')
name_column = interface.get_object('name_column')
ConfDialog = interface.get_object('ConfDialog')
ErrorDialog = interface.get_object('ErrorDialog')
down_label = interface.get_object('down_label')
installed_column.set_sort_column_id(1)
name_column.set_sort_column_id(0)
@ -204,19 +198,17 @@ class Handler:
global t
global transaction_type
global transaction_dict
global transaction_desc
if not geteuid() == 0:
ErrorDialog.format_secondary_text("You need to be root to run packages transactions")
response = ErrorDialog.run()
transaction.ErrorDialog.format_secondary_text("You need to be root to run packages transactions")
response = transaction.ErrorDialog.run()
if response:
ErrorDialog.hide()
transaction.ErrorDialog.hide()
elif not transaction_dict:
ErrorDialog.format_secondary_text("No package is selected")
response = ErrorDialog.run()
transaction.ErrorDialog.format_secondary_text("No package is selected")
response = transaction.ErrorDialog.run()
if response:
ErrorDialog.hide()
transaction.ErrorDialog.hide()
else:
transaction_desc.clear()
t = transaction.init_transaction(config.handle)
if transaction_type is "install":
for pkg in transaction_dict.values():
@ -227,47 +219,24 @@ class Handler:
try:
t.prepare()
except pyalpm.error:
ErrorDialog.format_secondary_text(traceback.format_exc())
response = ErrorDialog.run()
transaction.ErrorDialog.format_secondary_text(traceback.format_exc())
response = transaction.ErrorDialog.run()
if response:
ErrorDialog.hide()
transaction.ErrorDialog.hide()
t.release()
transaction.to_remove = t.to_remove
transaction.to_add = t.to_add
if transaction.to_remove:
transaction_desc.append(['To remove:', transaction.to_remove[0].name])
i = 1
while i < len(transaction.to_remove):
transaction_desc.append([' ', transaction.to_remove[i].name])
i += 1
down_label.set_markup('')
if transaction.to_add:
transaction_desc.append(['To install:', transaction.to_add[0].name])
i = 1
dsize = transaction.to_add[0].size
while i < len(transaction.to_add):
transaction_desc.append([' ', transaction.to_add[i].name])
dsize += transaction.to_add[i].download_size
i += 1
down_label.set_markup('<b>Total Download size: </b>'+transaction.format_size(dsize))
response = ConfDialog.run()
transaction.set_transaction_desc('normal')
response = transaction.ConfDialog.run()
if response == Gtk.ResponseType.OK:
ConfDialog.hide()
try:
t.commit()
except pyalpm.error:
ErrorDialog.format_secondary_text(traceback.format_exc())
response = ErrorDialog.run()
if response:
ErrorDialog.hide()
t.release()
transaction.t_finalize(t)
transaction_dict.clear()
transaction_type = None
set_packages_list()
transaction.ProgressWindow.hide()
if response == Gtk.ResponseType.CANCEL or Gtk.ResponseType.CLOSE or Gtk.ResponseType.DELETE_EVENT:
transaction.ProgressWindow.hide()
ConfDialog.hide()
transaction.ConfDialog.hide()
t.release()
def on_EraseButton_clicked(self, *arg):
@ -360,9 +329,10 @@ class Handler:
packages_list[line][1] = not packages_list[line][1]
packages_list[line][2] = True
#if __name__ == "__main__":
transaction.do_refresh()
interface.connect_signals(Handler())
MainWindow = interface.get_object("MainWindow")
MainWindow.show_all()
Gtk.main()
if __name__ == "__main__":
if geteuid() == 0:
transaction.do_refresh()
interface.connect_signals(Handler())
MainWindow = interface.get_object("MainWindow")
MainWindow.show_all()
Gtk.main()

View File

@ -6,7 +6,6 @@ from gi.repository import Gtk, GdkPixbuf, Gdk
import pyalpm
from time import strftime, localtime
from os import geteuid
import sys
import config
import transaction
@ -19,6 +18,7 @@ top_label = interface.get_object('top_label')
def have_updates():
available_updates = transaction.get_updates()
update_listore.clear()
if not available_updates:
update_listore.append(["", ""])
return False
@ -31,14 +31,15 @@ def have_updates():
return True
class Handler:
def on_MainWindow_delete_event(self, *arg):
def on_UpdateWindow_delete_event(self, *arg):
Gtk.main_quit()
def on_QuitButton_clicked(self, *arg):
Gtk.main_quit()
def on_ApplyButton_clicked(self, *arg):
print("Apply")
transaction.do_sysupgrade()
have_updates()
def on_RefreshButton_clicked(self, *arg):
transaction.do_refresh()
@ -52,9 +53,11 @@ def main():
else:
top_label.set_markup("<big><b>Available updates</b></big>")
interface.connect_signals(Handler())
MainWindow = interface.get_object("MainWindow")
MainWindow.show_all()
UpdateWindow = interface.get_object("UpdateWindow")
UpdateWindow.show_all()
Gtk.main()
if __name__ == "__main__":
if geteuid() == 0:
transaction.do_refresh()
main()

View File

@ -4,8 +4,7 @@
from gi.repository import Gtk
import pyalpm
import math
import sys
import traceback
import config
interface = Gtk.Builder()
@ -14,9 +13,16 @@ interface.add_from_file('gui/dialogs.glade')
ProgressWindow = interface.get_object('ProgressWindow')
progress_bar = interface.get_object('progressbar2')
progress_label = interface.get_object('progresslabel2')
ErrorDialog = interface.get_object('ErrorDialog')
ConfDialog = interface.get_object('ConfDialog')
transaction_desc = interface.get_object('transaction_desc')
down_label = interface.get_object('down_label')
to_remove = None
to_add = None
to_update = None
do_syncfirst = False
list_first = []
def init_transaction(handle):
"Transaction initialization"
@ -54,23 +60,77 @@ def do_refresh():
def do_sysupgrade():
"""Upgrade a system like pacman -Su"""
global to_remove
global to_add
global to_update
t = init_transaction(config.handle)
t.sysupgrade(downgrade=False)
if len(t.to_add) + len(t.to_remove) == 0:
print("Nothing to do")
t.release()
return 0
if do_syncfirst is True:
for pkg in list_first:
t.add_pkg(pkg)
else:
ok = finalize(t)
return (0 if ok else 1)
try:
t.sysupgrade(downgrade=False)
except pyalpm.error:
ErrorDialog.format_secondary_text(traceback.format_exc())
response = ErrorDialog.run()
if response:
ErrorDialog.hide()
t.release()
try:
t.prepare()
except pyalpm.error:
ErrorDialog.format_secondary_text(traceback.format_exc())
response = ErrorDialog.run()
if response:
ErrorDialog.hide()
t.release()
to_remove = t.to_remove
to_add = t.to_add
if len(to_add) + len(to_remove) == 0:
t.release()
else:
set_transaction_desc('update')
if len(transaction_desc) != 0:
response = ConfDialog.run()
if response == Gtk.ResponseType.OK:
t_finalize(t)
if response == Gtk.ResponseType.CANCEL or Gtk.ResponseType.CLOSE or Gtk.ResponseType.DELETE_EVENT:
ProgressWindow.hide()
ConfDialog.hide()
t.release()
else:
t_finalize(t)
t.release()
def t_finalize(t):
ConfDialog.hide()
try:
t.commit()
except pyalpm.error:
ErrorDialog.format_secondary_text(traceback.format_exc())
response = ErrorDialog.run()
if response:
ErrorDialog.hide()
ProgressWindow.hide()
def get_updates():
"""Return a list of package objects in local db which can be updated"""
installed_pkglist = config.handle.get_localdb().pkgcache
global do_syncfirst
global list_first
if config.syncfirst:
for name in config.syncfirst:
pkg = config.handle.get_localdb().get_pkg(name)
candidate = pyalpm.sync_newversion(pkg, config.handle.get_syncdbs())
if candidate:
list_first.append(candidate)
if list_first:
do_syncfirst = True
return list_first
result = []
installed_pkglist = config.handle.get_localdb().pkgcache
for pkg in installed_pkglist:
candidate = pyalpm.sync_newversion(pkg, config.handle.get_syncdbs())
if candidate is not None:
if candidate:
result.append(candidate)
return result
@ -90,6 +150,48 @@ def format_size(size):
size_string = '%.2f MiB' % (KiB_size / 1024)
return size_string
def set_transaction_desc(mode):
global transaction_desc
global down_label
global to_add
global to_remove
global to_update
transaction_desc.clear()
if to_remove:
transaction_desc.append(['To remove:', to_remove[0].name])
i = 1
while i < len(to_remove):
transaction_desc.append([' ', to_remove[i].name])
i += 1
down_label.set_markup('')
if to_add:
if mode == 'update':
installed_name = []
for pkg_object in config.handle.get_localdb().pkgcache:
installed_name.append(pkg_object.name)
to_add_name = []
for pkg_object in to_add:
to_add_name.append(pkg_object.name)
to_update = sorted(set(installed_name).intersection(to_add_name))
to_remove_from_add_name = sorted(set(to_update).intersection(to_add_name))
for name in to_remove_from_add_name:
to_add_name.remove(name)
if to_add_name:
transaction_desc.append(['To install:', to_add_name[0]])
i = 1
while i < len(to_add_name):
transaction_desc.append([' ', to_add_name[i]])
i += 1
if mode == 'normal':
if to_update:
transaction_desc.append(['To update:', to_update[0]])
i = 1
while i < len(to_update):
transaction_desc.append([' ', to_update[i]])
i += 1
down_label.set_markup('')
#down_label.set_markup('<b>Total Download size: </b>'+format_size(total_size))
# Callbacks
event_text = ' '
def cb_event(ID, event, tupel):
@ -136,11 +238,10 @@ def cb_dl(_target, _transferred, total):
progress_bar.set_text(_target)
progress_bar.set_fraction(fraction)
else:
progress_label.set_text('Downloading...')
progress_label.set_text('Refreshing...')
progress_bar.set_text(_target)
progress_bar.pulse()
def cb_progress(_target, _percent, n, i):
while Gtk.events_pending():
Gtk.main_iteration()
@ -148,14 +249,6 @@ def cb_progress(_target, _percent, n, i):
progress_bar.set_fraction(_percent/100)
progress_bar.set_text(target)
if __name__ == "__main__":
do_refresh()
available_updates = get_updates()
if not available_updates:
print("\nNo update available")
else:
for pkg in available_updates:
pkgname = pkg.name
oldversion = pkg.version
newversion = get_new_version_available(pkgname)
print("\n{} {} can be updated to {}".format(pkgname, oldversion, newversion))
True