diff --git a/config.py b/config.py
index 20725ab..0cde596 100644
--- a/config.py
+++ b/config.py
@@ -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
diff --git a/gui/dialogs.glade b/gui/dialogs.glade
index 5b84285..ba18a41 100644
--- a/gui/dialogs.glade
+++ b/gui/dialogs.glade
@@ -1,6 +1,111 @@
+
False
5
@@ -81,4 +186,12 @@
+
+
+
+
+
+
+
+
diff --git a/gui/pamac.glade b/gui/pamac.glade
index d4a4a91..4584363 100644
--- a/gui/pamac.glade
+++ b/gui/pamac.glade
@@ -1,115 +1,6 @@
-
- 250
- 150
- False
- True
- True
- 5
-
- center-on-parent
- 200
- 100
- dialog
- True
- other
- ok-cancel
- <b>Transaction summary</b>
- True
-
-
- 240
- 140
- False
- True
- True
- vertical
-
-
- True
- True
- True
- end
-
-
- False
- True
- end
- 0
-
-
-
-
- 200
- 120
- True
- True
- True
- True
- in
-
-
- True
- False
- True
- transaction_desc
- False
- False
- False
-
-
-
-
-
- column
-
-
- 0
- 600
-
-
- 0
-
-
-
-
-
-
- column
-
-
-
- 1
-
-
-
-
-
-
-
-
- True
- True
- 2
-
-
-
-
- True
- False
- label
-
-
- False
- True
- 4
-
-
-
-
-
@@ -504,12 +395,4 @@
-
-
-
-
-
-
-
-
diff --git a/gui/pamac_update.glade b/gui/pamac_update.glade
index 367bf39..351d63a 100644
--- a/gui/pamac_update.glade
+++ b/gui/pamac_update.glade
@@ -1,11 +1,11 @@
-
+
False
-
+ Update Manager
center
-
+
False
@@ -15,22 +15,23 @@
2
- False
+ True
+ True
5
end
-
- gtk-refresh
+
+ gtk-apply
True
True
True
True
-
+
False
True
- 0
+ 1
@@ -42,21 +43,6 @@
True
-
- False
- True
- 1
-
-
-
-
- gtk-apply
- True
- True
- True
- True
-
-
False
True
@@ -89,10 +75,9 @@
390
490
True
- True
+ False
True
True
- in
True
diff --git a/pamac.py b/pamac.py
index a8c1460..0c1ddd6 100755
--- a/pamac.py
+++ b/pamac.py
@@ -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('Total Download size: '+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()
diff --git a/pamac_update.py b/pamac_update.py
index 00bffaa..0b98301 100755
--- a/pamac_update.py
+++ b/pamac_update.py
@@ -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("Available updates")
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()
diff --git a/transaction.py b/transaction.py
index 45dfac0..4febc06 100755
--- a/transaction.py
+++ b/transaction.py
@@ -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('Total Download size: '+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