2012-12-29 11:06:44 -03:00
|
|
|
#! /usr/bin/python
|
|
|
|
# -*-coding:utf-8 -*-
|
|
|
|
|
|
|
|
from gi.repository import Gtk
|
|
|
|
|
|
|
|
import pyalpm
|
|
|
|
from os import geteuid
|
|
|
|
|
2013-01-06 15:10:13 -03:00
|
|
|
from pamac import config, transaction
|
2012-12-29 11:06:44 -03:00
|
|
|
|
|
|
|
interface = Gtk.Builder()
|
2013-01-06 15:10:13 -03:00
|
|
|
interface.add_from_file('/usr/share/pamac/gui/updater.glade')
|
|
|
|
interface.add_from_file('/usr/share/pamac/gui/dialogs.glade')
|
|
|
|
|
|
|
|
UpdateWindow = interface.get_object("UpdateWindow")
|
2012-12-29 11:06:44 -03:00
|
|
|
|
2012-12-31 11:41:51 -03:00
|
|
|
ConfDialog = interface.get_object('ConfDialog')
|
|
|
|
transaction_add = interface.get_object('transaction_add')
|
2012-12-29 11:06:44 -03:00
|
|
|
top_label = interface.get_object('top_label')
|
2012-12-31 11:41:51 -03:00
|
|
|
bottom_label = interface.get_object('bottom_label')
|
|
|
|
update_listore = interface.get_object('update_list')
|
|
|
|
update_label = interface.get_object('update_label')
|
2012-12-29 11:06:44 -03:00
|
|
|
|
|
|
|
def have_updates():
|
|
|
|
available_updates = transaction.get_updates()
|
|
|
|
update_listore.clear()
|
2012-12-31 11:41:51 -03:00
|
|
|
update_label.set_justify(Gtk.Justification.CENTER)
|
2012-12-29 11:06:44 -03:00
|
|
|
if not available_updates:
|
|
|
|
update_listore.append(["", ""])
|
2012-12-31 11:41:51 -03:00
|
|
|
update_label.set_markup("<big><b>No update available</b></big>")
|
2012-12-29 11:06:44 -03:00
|
|
|
return False
|
|
|
|
else:
|
|
|
|
for pkg in available_updates:
|
|
|
|
pkgname = pkg.name
|
|
|
|
newversion = transaction.get_new_version_available(pkgname)
|
|
|
|
pkgname = pkg.name+" "+newversion
|
|
|
|
update_listore.append([pkgname, transaction.format_size(pkg.size)])
|
2012-12-31 11:41:51 -03:00
|
|
|
update_label.set_markup("<big><b>Available updates</b></big>")
|
2012-12-29 11:06:44 -03:00
|
|
|
return True
|
|
|
|
|
2012-12-31 11:41:51 -03:00
|
|
|
def set_transaction_add():
|
|
|
|
transaction_add.clear()
|
|
|
|
if transaction.to_remove:
|
|
|
|
transaction_add.append(['To remove:', transaction.to_remove[0].name])
|
|
|
|
i = 1
|
|
|
|
while i < len(transaction.to_remove):
|
|
|
|
transaction_add.append([' ', transaction.to_remove[i].name])
|
|
|
|
i += 1
|
|
|
|
bottom_label.set_markup('')
|
|
|
|
if transaction.to_add:
|
|
|
|
installed_name = []
|
|
|
|
for pkg_object in config.handle.get_localdb().pkgcache:
|
|
|
|
installed_name.append(pkg_object.name)
|
|
|
|
to_add_name = []
|
|
|
|
for pkg_object in transaction.to_add:
|
|
|
|
to_add_name.append(pkg_object.name)
|
|
|
|
transaction.to_update = sorted(set(installed_name).intersection(to_add_name))
|
|
|
|
to_remove_from_add_name = sorted(set(transaction.to_update).intersection(to_add_name))
|
|
|
|
for name in to_remove_from_add_name:
|
|
|
|
to_add_name.remove(name)
|
|
|
|
if to_add_name:
|
|
|
|
transaction_add.append(['To install:', to_add_name[0]])
|
|
|
|
i = 1
|
|
|
|
while i < len(to_add_name):
|
|
|
|
transaction_add.append([' ', to_add_name[i]])
|
|
|
|
i += 1
|
|
|
|
bottom_label.set_markup('')
|
|
|
|
#bottom_label.set_markup('<b>Total Download size: </b>'+format_size(totaldlcb))
|
|
|
|
top_label.set_markup('<big><b>Additionnal Transaction(s)</b></big>')
|
|
|
|
|
|
|
|
def do_sysupgrade():
|
|
|
|
"""Upgrade a system like pacman -Su"""
|
|
|
|
if transaction.t_lock is False:
|
|
|
|
if transaction.do_syncfirst is True:
|
2013-01-06 15:10:13 -03:00
|
|
|
transaction.t = transaction.init_transaction(recurse = True)
|
|
|
|
for pkg in transaction.list_first:
|
2012-12-31 11:41:51 -03:00
|
|
|
transaction.t.add_pkg(pkg)
|
|
|
|
transaction.to_remove = transaction.t.to_remove
|
|
|
|
transaction.to_add = transaction.t.to_add
|
|
|
|
set_transaction_add()
|
2013-01-06 15:10:13 -03:00
|
|
|
if len(transaction_add) != 0:
|
|
|
|
ConfDialog.show_all()
|
|
|
|
else:
|
|
|
|
transaction.t_finalize(transaction.t)
|
|
|
|
transaction.do_syncfirst = False
|
|
|
|
transaction.list_first = []
|
2012-12-31 11:41:51 -03:00
|
|
|
else:
|
|
|
|
try:
|
2013-01-06 15:10:13 -03:00
|
|
|
transaction.t = transaction.init_transaction()
|
2012-12-31 11:41:51 -03:00
|
|
|
transaction.t.sysupgrade(downgrade=False)
|
|
|
|
except pyalpm.error:
|
|
|
|
ErrorDialog.format_secondary_text(traceback.format_exc())
|
|
|
|
response = ErrorDialog.run()
|
|
|
|
if response:
|
|
|
|
ErrorDialog.hide()
|
|
|
|
transaction.t.release()
|
|
|
|
transaction.t_lock = False
|
|
|
|
transaction.check_conflicts()
|
|
|
|
transaction.to_add = transaction.t.to_add
|
|
|
|
transaction.to_remove = []
|
|
|
|
for pkg in transaction.conflict_to_remove.values():
|
|
|
|
transaction.to_remove.append(pkg)
|
|
|
|
if len(transaction.to_add) + len(transaction.to_remove) == 0:
|
|
|
|
transaction.t.release()
|
|
|
|
transaction.t_lock = False
|
|
|
|
print("Nothing to update")
|
|
|
|
else:
|
|
|
|
transaction.t.release()
|
2013-01-06 15:10:13 -03:00
|
|
|
transaction.t = transaction.init_transaction(noconflicts = True, nodeps = True)
|
2012-12-31 11:41:51 -03:00
|
|
|
for pkg in transaction.to_add:
|
|
|
|
transaction.t.add_pkg(pkg)
|
|
|
|
for pkg in transaction.conflict_to_remove.values():
|
|
|
|
transaction.t.remove_pkg(pkg)
|
|
|
|
transaction.to_remove = transaction.t.to_remove
|
|
|
|
transaction.to_add = transaction.t.to_add
|
|
|
|
set_transaction_add()
|
2013-01-06 15:10:13 -03:00
|
|
|
if len(transaction_add) != 0:
|
2012-12-31 11:41:51 -03:00
|
|
|
ConfDialog.show_all()
|
|
|
|
else:
|
2013-01-06 15:10:13 -03:00
|
|
|
transaction.t_finalize(transaction.t)
|
2012-12-31 11:41:51 -03:00
|
|
|
|
2012-12-29 11:06:44 -03:00
|
|
|
class Handler:
|
|
|
|
def on_UpdateWindow_delete_event(self, *arg):
|
2013-01-06 15:10:13 -03:00
|
|
|
if __name__ == "__main__":
|
|
|
|
Gtk.main_quit()
|
|
|
|
else:
|
|
|
|
UpdateWindow.hide()
|
2012-12-29 11:06:44 -03:00
|
|
|
|
|
|
|
def on_QuitButton_clicked(self, *arg):
|
2013-01-06 15:10:13 -03:00
|
|
|
if __name__ == "__main__":
|
|
|
|
Gtk.main_quit()
|
|
|
|
else:
|
|
|
|
UpdateWindow.hide()
|
2012-12-29 11:06:44 -03:00
|
|
|
|
|
|
|
def on_ApplyButton_clicked(self, *arg):
|
2012-12-31 11:41:51 -03:00
|
|
|
do_sysupgrade()
|
2012-12-29 11:06:44 -03:00
|
|
|
have_updates()
|
|
|
|
|
|
|
|
def on_RefreshButton_clicked(self, *arg):
|
|
|
|
transaction.do_refresh()
|
|
|
|
have_updates()
|
|
|
|
|
2012-12-31 11:41:51 -03:00
|
|
|
def on_TransCancelButton_clicked(self, *arg):
|
|
|
|
ConfDialog.hide()
|
|
|
|
transaction.t_lock = False
|
|
|
|
transaction.t.release()
|
|
|
|
|
|
|
|
def on_TransValidButton_clicked(self, *arg):
|
|
|
|
ConfDialog.hide()
|
|
|
|
transaction.t_finalize(t)
|
|
|
|
|
2012-12-29 11:06:44 -03:00
|
|
|
def main():
|
|
|
|
have_updates()
|
|
|
|
interface.connect_signals(Handler())
|
|
|
|
UpdateWindow.show_all()
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
if geteuid() == 0:
|
2013-01-06 15:10:13 -03:00
|
|
|
transaction.progress_label.set_text('Refreshing...')
|
|
|
|
transaction.progress_bar.pulse()
|
|
|
|
transaction.action_icon.set_from_file('/usr/share/pamac/icons/24x24/status/refresh-cache.png')
|
|
|
|
transaction.ProgressWindow.show_all()
|
2012-12-29 11:06:44 -03:00
|
|
|
transaction.do_refresh()
|
2013-01-06 15:10:13 -03:00
|
|
|
transaction.ProgressWindow.hide()
|
2012-12-29 11:06:44 -03:00
|
|
|
main()
|
2013-01-06 15:10:13 -03:00
|
|
|
Gtk.main()
|