pamac-classic/pamac/main.py

1044 lines
37 KiB
Python
Raw Normal View History

2012-12-12 13:12:27 -03:00
#! /usr/bin/python
# -*-coding:utf-8 -*-
2012-12-12 13:12:27 -03:00
2013-01-16 15:09:52 -03:00
from gi.repository import Gtk
2013-03-25 13:51:20 -03:00
from gi.repository.GdkPixbuf import Pixbuf
2012-12-12 13:12:27 -03:00
import pyalpm
2013-03-01 15:11:55 -03:00
import dbus
2013-02-06 12:09:43 -03:00
from collections import OrderedDict
2012-12-12 13:12:27 -03:00
from time import strftime, localtime
2012-12-29 11:06:44 -03:00
2013-01-16 15:09:52 -03:00
from pamac import config, common, transaction
2012-12-12 13:12:27 -03:00
interface = Gtk.Builder()
2013-03-15 13:15:34 -03:00
#interface.add_from_file('/usr/share/pamac/gui/dialogs.glade')
#ErrorDialog = interface.get_object('ErrorDialog')
#WarningDialog = interface.get_object('WarningDialog')
#InfoDialog = interface.get_object('InfoDialog')
#QuestionDialog = interface.get_object('QuestionDialog')
2012-12-12 13:12:27 -03:00
2013-02-10 11:59:53 -03:00
interface.add_from_file('/usr/share/pamac/gui/manager.glade')
ManagerWindow = interface.get_object("ManagerWindow")
2013-03-28 10:59:23 -03:00
details_list = interface.get_object('details_list')
deps_list = interface.get_object('deps_list')
files_list = interface.get_object('files_list')
files_scrolledwindow = interface.get_object('files_scrolledwindow')
name_label = interface.get_object('name_label')
desc_label = interface.get_object('desc_label')
link_label = interface.get_object('link_label')
licenses_label = interface.get_object('licenses_label')
2012-12-12 13:12:27 -03:00
search_entry = interface.get_object('search_entry')
2013-03-25 13:51:20 -03:00
search_list = interface.get_object('search_list')
search_selection = interface.get_object('search_treeview_selection')
packages_list = interface.get_object('packages_list')
list_selection = interface.get_object('list_treeview_selection')
2012-12-12 13:12:27 -03:00
installed_column = interface.get_object('installed_column')
name_column = interface.get_object('name_column')
2013-03-25 13:51:20 -03:00
groups_list = interface.get_object('groups_list')
groups_selection = interface.get_object('groups_treeview_selection')
state_list = interface.get_object('state_list')
state_selection = interface.get_object('state_treeview_selection')
repos_list = interface.get_object('repos_list')
repos_selection = interface.get_object('repos_treeview_selection')
2012-12-31 11:41:51 -03:00
ConfDialog = interface.get_object('ConfDialog')
transaction_sum = interface.get_object('transaction_sum')
2013-02-10 11:59:53 -03:00
sum_top_label = interface.get_object('sum_top_label')
sum_bottom_label = interface.get_object('sum_bottom_label')
2013-01-27 14:15:34 -03:00
ChooseDialog = interface.get_object('ChooseDialog')
choose_list = interface.get_object('choose_list')
choose_label = interface.get_object('choose_label')
2013-03-01 15:11:55 -03:00
ProgressWindow = interface.get_object('ProgressWindow')
progress_bar = interface.get_object('progressbar2')
progress_label = interface.get_object('progresslabel2')
action_icon = interface.get_object('action_icon')
ProgressCancelButton = interface.get_object('ProgressCancelButton')
2012-12-31 11:41:51 -03:00
2013-02-10 11:59:53 -03:00
interface.add_from_file('/usr/share/pamac/gui/updater.glade')
UpdaterWindow = interface.get_object("UpdaterWindow")
update_listore = interface.get_object('update_list')
2013-03-26 07:02:17 -03:00
update_top_label = interface.get_object('update_top_label')
update_bottom_label = interface.get_object('update_bottom_label')
2013-02-10 11:59:53 -03:00
2013-03-01 15:11:55 -03:00
def action_signal_handler(action):
2013-03-02 11:27:52 -03:00
if action:
progress_label.set_text(action)
if ('Installing' in action) or ('Removing' in action) or ('Upgrading' in action) or ('Configuring' in action):
2013-03-15 13:15:34 -03:00
ProgressCancelButton.set_visible(False)
2013-03-25 13:51:20 -03:00
else:
ProgressCancelButton.set_visible(True)
2013-03-01 15:11:55 -03:00
def icon_signal_handler(icon):
action_icon.set_from_file(icon)
def target_signal_handler(target):
progress_bar.set_text(target)
def percent_signal_handler(percent):
if percent > 1:
2013-03-01 15:11:55 -03:00
progress_bar.pulse()
else:
progress_bar.set_fraction(percent)
2013-03-01 15:11:55 -03:00
bus = dbus.SystemBus()
bus.add_signal_receiver(action_signal_handler, dbus_interface = "org.manjaro.pamac", signal_name = "EmitAction")
bus.add_signal_receiver(icon_signal_handler, dbus_interface = "org.manjaro.pamac", signal_name = "EmitIcon")
bus.add_signal_receiver(target_signal_handler, dbus_interface = "org.manjaro.pamac", signal_name = "EmitTarget")
bus.add_signal_receiver(percent_signal_handler, dbus_interface = "org.manjaro.pamac", signal_name = "EmitPercent")
2013-03-25 13:51:20 -03:00
installed_icon = Pixbuf.new_from_file('/usr/share/pamac/icons/22x22/status/package-installed.png')
uninstalled_icon = Pixbuf.new_from_file('/usr/share/pamac/icons/22x22/status/package-available.png')
to_install_icon = Pixbuf.new_from_file('/usr/share/pamac/icons/22x22/status/package-add.png')
to_remove_icon = Pixbuf.new_from_file('/usr/share/pamac/icons/22x22/status/package-delete.png')
locked_icon = Pixbuf.new_from_file('/usr/share/pamac/icons/22x22/status/package-blocked.png')
search_icon = Pixbuf.new_from_file('/usr/share/pamac/icons/22x22/status/package-search.png')
2013-03-01 15:11:55 -03:00
pkg_name_list = []
pkg_object_dict = {}
pkg_installed_dict = {}
2013-03-25 13:51:20 -03:00
current_filter = (None, None)
2013-03-01 15:11:55 -03:00
transaction_type = None
transaction_dict = {}
mode = None
2013-03-25 13:51:20 -03:00
states = ['Installed', 'Uninstalled', 'Orphans', 'To install', 'To remove']
for state in states:
state_list.append([state])
2013-03-01 15:11:55 -03:00
2013-02-27 11:15:51 -03:00
def get_groups():
2013-03-26 07:02:17 -03:00
groups_list.clear()
2013-02-27 11:15:51 -03:00
tmp_list = []
for repo in transaction.handle.get_syncdbs():
for name, pkgs in repo.grpcache:
if not name in tmp_list:
tmp_list.append(name)
tmp_list = sorted(tmp_list)
for name in tmp_list:
groups_list.append([name])
2012-12-12 13:12:27 -03:00
2013-03-25 13:51:20 -03:00
def get_repos():
2013-03-26 07:02:17 -03:00
repos_list.clear()
2013-03-25 13:51:20 -03:00
for repo in transaction.handle.get_syncdbs():
repos_list.append([repo.name])
repos_list.append(['local'])
2012-12-12 13:12:27 -03:00
def set_list_dict_search(*patterns):
global pkg_name_list
global pkg_object_dict
global pkg_installed_dict
pkg_name_list = []
pkg_object_dict = {}
pkg_installed_dict = {}
2013-01-27 14:15:34 -03:00
for db in transaction.handle.get_syncdbs():
2012-12-12 13:12:27 -03:00
for pkg_object in db.search(*patterns):
if not pkg_object.name in pkg_name_list:
pkg_name_list.append(pkg_object.name)
pkg_object_dict[pkg_object.name] = pkg_object
pkg_installed_dict[pkg_object.name] = False
2013-01-27 14:15:34 -03:00
for pkg_object in transaction.handle.get_localdb().search(*patterns):
2012-12-12 13:12:27 -03:00
if not pkg_object.name in pkg_name_list:
pkg_name_list.append(pkg_object.name)
pkg_installed_dict[pkg_object.name] = True
pkg_object_dict[pkg_object.name] = pkg_object
pkg_name_list = sorted(pkg_name_list)
2013-03-25 13:51:20 -03:00
if pkg_name_list:
joined = ''
for term in patterns:
joined += term
already_in_list = False
if len(search_list) != 0:
for line in search_list:
if joined == line[0]:
already_in_list = True
if not already_in_list:
search_list.append([joined])
2012-12-12 13:12:27 -03:00
def set_list_dict_group(group):
global pkg_name_list
global pkg_object_dict
global pkg_installed_dict
pkg_name_list = []
pkg_object_dict = {}
pkg_installed_dict = {}
2013-01-27 14:15:34 -03:00
for db in transaction.handle.get_syncdbs():
2012-12-12 13:12:27 -03:00
grp = db.read_grp(group)
if grp is not None:
name, pkg_list = grp
for pkg_object in pkg_list:
if not pkg_object.name in pkg_name_list:
pkg_name_list.append(pkg_object.name)
pkg_object_dict[pkg_object.name] = pkg_object
pkg_installed_dict[pkg_object.name] = False
2013-01-13 12:37:17 -03:00
db = config.pacman_conf.initialize_alpm().get_localdb()
2012-12-12 13:12:27 -03:00
grp = db.read_grp(group)
if grp is not None:
name, pkg_list = grp
for pkg_object in pkg_list:
if not pkg_object.name in pkg_name_list:
pkg_name_list.append(pkg_object.name)
pkg_installed_dict[pkg_object.name] = True
pkg_object_dict[pkg_object.name] = pkg_object
pkg_name_list = sorted(pkg_name_list)
2013-03-25 13:51:20 -03:00
def set_list_dict_installed():
global pkg_name_list
global pkg_object_dict
global pkg_installed_dict
pkg_name_list = []
pkg_object_dict = {}
pkg_installed_dict = {}
for pkg_object in transaction.localpkgs.values():
if not pkg_object.name in pkg_name_list:
pkg_name_list.append(pkg_object.name)
pkg_installed_dict[pkg_object.name] = True
pkg_object_dict[pkg_object.name] = pkg_object
def set_list_dict_uninstalled():
global pkg_name_list
global pkg_object_dict
global pkg_installed_dict
pkg_name_list = []
pkg_object_dict = {}
pkg_installed_dict = {}
for pkg_object in transaction.syncpkgs.values():
if not pkg_object.name in transaction.localpkgs.keys():
if not pkg_object.name in pkg_name_list:
pkg_name_list.append(pkg_object.name)
pkg_installed_dict[pkg_object.name] = False
pkg_object_dict[pkg_object.name] = pkg_object
pkg_name_list = sorted(pkg_name_list)
2013-03-25 13:51:20 -03:00
def set_list_dict_local():
global pkg_name_list
global pkg_object_dict
global pkg_installed_dict
pkg_name_list = []
pkg_object_dict = {}
pkg_installed_dict = {}
for pkg_object in transaction.localpkgs.values():
if (not pkg_object.name in pkg_name_list) and (not pkg_object.name in transaction.syncpkgs.keys()):
pkg_name_list.append(pkg_object.name)
pkg_installed_dict[pkg_object.name] = True
pkg_object_dict[pkg_object.name] = pkg_object
def set_list_dict_orphans():
global pkg_name_list
global pkg_object_dict
global pkg_installed_dict
pkg_name_list = []
pkg_object_dict = {}
pkg_installed_dict = {}
for pkg_object in transaction.localpkgs.values():
if (pkg_object.reason == 1) and (not pkg_object.compute_requiredby()):
pkg_name_list.append(pkg_object.name)
pkg_installed_dict[pkg_object.name] = True
pkg_object_dict[pkg_object.name] = pkg_object
def set_list_dict_to_install():
global pkg_name_list
global pkg_object_dict
global pkg_installed_dict
pkg_name_list = []
pkg_object_dict = {}
pkg_installed_dict = {}
if transaction_type == "install":
for pkg_object in transaction_dict.values():
if not pkg_object.name in pkg_name_list:
pkg_name_list.append(pkg_object.name)
pkg_installed_dict[pkg_object.name] = False
pkg_object_dict[pkg_object.name] = pkg_object
pkg_name_list = sorted(pkg_name_list)
2013-03-25 13:51:20 -03:00
def set_list_dict_to_remove():
global pkg_name_list
global pkg_object_dict
global pkg_installed_dict
pkg_name_list = []
pkg_object_dict = {}
pkg_installed_dict = {}
if transaction_type == "remove":
for pkg_object in transaction_dict.values():
if not pkg_object.name in pkg_name_list:
pkg_name_list.append(pkg_object.name)
pkg_installed_dict[pkg_object.name] = True
pkg_object_dict[pkg_object.name] = pkg_object
pkg_name_list = sorted(pkg_name_list)
2013-03-25 13:51:20 -03:00
def set_list_dict_repos(repo):
global pkg_name_list
global pkg_object_dict
global pkg_installed_dict
pkg_name_list = []
pkg_object_dict = {}
pkg_installed_dict = {}
for db in transaction.handle.get_syncdbs():
if db.name == repo:
for pkg_object in db.pkgcache:
if not pkg_object.name in pkg_name_list:
pkg_name_list.append(pkg_object.name)
if pkg_object.name in transaction.localpkgs.keys():
pkg_installed_dict[pkg_object.name] = True
pkg_object_dict[pkg_object.name] = transaction.localpkgs[pkg_object.name]
else:
pkg_installed_dict[pkg_object.name] = False
pkg_object_dict[pkg_object.name] = pkg_object
2012-12-12 13:12:27 -03:00
def refresh_packages_list():
packages_list.clear()
if not pkg_name_list:
2013-03-26 07:02:17 -03:00
packages_list.append(["No package found", False, False, False, search_icon, '', 0])
2012-12-12 13:12:27 -03:00
else:
for name in pkg_name_list:
if name in config.holdpkg:
2013-03-26 07:02:17 -03:00
packages_list.append([name, True, False, True, locked_icon, '', 0])
2012-12-12 13:12:27 -03:00
elif transaction_type is "install":
2013-03-26 07:02:17 -03:00
if transaction.localpkgs.__contains__(name):
packages_list.append([name, True, False, True, installed_icon, common.format_size(transaction.localpkgs[name].isize), transaction.localpkgs[name].isize])
2012-12-12 13:12:27 -03:00
elif name in transaction_dict.keys():
2013-03-26 10:26:16 -03:00
packages_list.append([name, False, True, True, to_install_icon, common.format_size(transaction.syncpkgs[name].isize), transaction.syncpkgs[name].isize])
2012-12-12 13:12:27 -03:00
else:
2013-03-26 10:26:16 -03:00
packages_list.append([name, False, True, False, uninstalled_icon, common.format_size(transaction.syncpkgs[name].isize), transaction.syncpkgs[name].isize])
2012-12-12 13:12:27 -03:00
elif transaction_type is "remove":
2013-03-26 07:02:17 -03:00
if not transaction.localpkgs.__contains__(name):
2013-03-26 10:26:16 -03:00
packages_list.append([name, False, False, False, uninstalled_icon, common.format_size(transaction.syncpkgs[name].isize), transaction.syncpkgs[name].isize])
2012-12-12 13:12:27 -03:00
elif name in transaction_dict.keys():
2013-03-26 07:02:17 -03:00
packages_list.append([name, True, True, False, to_remove_icon, common.format_size(transaction.localpkgs[name].isize), transaction.localpkgs[name].isize])
2012-12-12 13:12:27 -03:00
else:
2013-03-26 07:02:17 -03:00
packages_list.append([name, True, True, True, installed_icon, common.format_size(transaction.localpkgs[name].isize), transaction.localpkgs[name].isize])
elif transaction.localpkgs.__contains__(name):
packages_list.append([name, True, True, True, installed_icon, common.format_size(transaction.localpkgs[name].isize), transaction.localpkgs[name].isize])
2012-12-12 13:12:27 -03:00
else:
2013-03-26 10:26:16 -03:00
packages_list.append([name, False, True, False, uninstalled_icon, common.format_size(transaction.syncpkgs[name].isize), transaction.syncpkgs[name].isize])
2012-12-12 13:12:27 -03:00
def set_packages_list():
2013-03-25 13:51:20 -03:00
if current_filter[0] == 'search':
set_list_dict_search(*current_filter[1])
if current_filter[0] == 'group':
set_list_dict_group(current_filter[1])
if current_filter[0] == 'installed':
set_list_dict_installed()
if current_filter[0] == 'uninstalled':
set_list_dict_uninstalled()
if current_filter[0] == 'orphans':
set_list_dict_orphans()
if current_filter[0] == 'local':
set_list_dict_local()
if current_filter[0] == 'to_install':
set_list_dict_to_install()
if current_filter[0] == 'to_remove':
set_list_dict_to_remove()
if current_filter[0] == 'repo':
set_list_dict_repos(current_filter[1])
2012-12-12 13:12:27 -03:00
refresh_packages_list()
2013-03-28 10:59:23 -03:00
def set_infos_list(pkg):
name_label.set_markup('<big><b>{} {}</b></big>'.format(pkg.name, pkg.version))
desc_label.set_markup(pkg.desc)
# fix & in url
url = pkg.url.replace('&', '&amp;')
link_label.set_markup('<a href=\"{_url}\">{_url}</a>'.format(_url = url))
2013-03-28 10:59:23 -03:00
licenses_label.set_markup('Licenses: {}'.format(' '.join(pkg.licenses)))
def set_deps_list(pkg, style):
deps_list.clear()
if pkg.depends:
deps_list.append(['Depends On:', '\n'.join(pkg.depends)])
if pkg.optdepends:
deps_list.append(['Optional Deps:', '\n'.join(pkg.optdepends)])
2012-12-12 13:12:27 -03:00
if style == 'local':
2013-03-28 10:59:23 -03:00
if pkg.compute_requiredby():
deps_list.append(['Required By:', '\n'.join(pkg.compute_requiredby())])
if pkg.provides:
details_list.append(['Provides:', ' '.join(pkg.provides)])
if pkg.replaces:
details_list.append(['Replaces:', ' '.join(pkg.replaces)])
if pkg.conflicts:
details_list.append(['Conflicts With:', ' '.join(pkg.conflicts)])
def set_details_list(pkg, style):
details_list.clear()
2012-12-12 13:12:27 -03:00
if style == 'sync':
2013-03-28 10:59:23 -03:00
details_list.append(['Repository:', pkg.db.name])
if pkg.groups:
details_list.append(['Groups:', ' '.join(pkg.groups)])
if style == 'sync':
details_list.append(['Compressed Size:', common.format_size(pkg.size)])
details_list.append(['Download Size:', common.format_size(pkg.download_size)])
2013-03-26 10:26:16 -03:00
if style == 'local':
2013-03-28 10:59:23 -03:00
details_list.append(['Installed Size:', common.format_size(pkg.isize)])
details_list.append(['Packager:', pkg.packager])
details_list.append(['Architecture:', pkg.arch])
#details_list.append(['Build Date:', strftime("%a %d %b %Y %X %Z", localtime(pkg.builddate))])
2012-12-12 13:12:27 -03:00
if style == 'local':
2013-03-28 10:59:23 -03:00
details_list.append(['Install Date:', strftime("%a %d %b %Y %X %Z", localtime(pkg.installdate))])
2012-12-12 13:12:27 -03:00
if pkg.reason == pyalpm.PKG_REASON_EXPLICIT:
reason = 'Explicitly installed'
elif pkg.reason == pyalpm.PKG_REASON_DEPEND:
reason = 'Installed as a dependency for another package'
else:
reason = 'N/A'
2013-03-28 10:59:23 -03:00
details_list.append(['Install Reason:', reason])
2012-12-12 13:12:27 -03:00
if style == 'sync':
2013-03-28 10:59:23 -03:00
#details_list.append(['Install Script:', 'Yes' if pkg.has_scriptlet else 'No'])
#details_list.append(['MD5 Sum:', pkg.md5sum])
#details_list.append(['SHA256 Sum:', pkg.sha256sum])
details_list.append(['Signatures:', 'Yes' if pkg.base64_sig else 'No'])
2012-12-12 13:12:27 -03:00
if style == 'local':
2013-03-28 10:59:23 -03:00
if len(pkg.backup) != 0:
#details_list.append(['Backup files:', '\n'.join(["%s %s" % (md5, file) for (file, md5) in pkg.backup])])
details_list.append(['Backup files:', '\n'.join(["%s" % (file) for (file, md5) in pkg.backup])])
def set_files_list(pkg):
files_list.clear()
if len(pkg.files) != 0:
for file in pkg.files:
files_list.append(['/'+file[0]])
2012-12-12 13:12:27 -03:00
2012-12-31 11:41:51 -03:00
def set_transaction_sum():
transaction_sum.clear()
2013-03-28 10:59:23 -03:00
sum_top_label.set_markup('<big><b>Transaction Summary</b></big>')
2013-01-20 13:38:33 -03:00
if transaction.to_remove:
2013-02-27 11:15:51 -03:00
transaction.to_remove = sorted(transaction.to_remove)
2013-01-20 13:38:33 -03:00
transaction_sum.append(['To remove:', transaction.to_remove[0]])
2012-12-31 11:41:51 -03:00
i = 1
2013-01-20 13:38:33 -03:00
while i < len(transaction.to_remove):
transaction_sum.append([' ', transaction.to_remove[i]])
2012-12-31 11:41:51 -03:00
i += 1
2013-02-10 11:59:53 -03:00
sum_bottom_label.set_markup('')
2013-01-20 13:38:33 -03:00
if transaction.to_add:
2013-02-27 11:15:51 -03:00
transaction.to_add = sorted(transaction.to_add)
2013-03-28 10:59:23 -03:00
dsize = 0
for name in transaction.to_add:
dsize += transaction.syncpkgs[name].download_size
sum_bottom_label.set_markup('<b>Total download size: </b>'+common.format_size(dsize))
installed = []
2013-01-16 15:09:52 -03:00
for pkg_object in config.pacman_conf.initialize_alpm().get_localdb().pkgcache:
installed.append(pkg_object.name)
2013-01-20 13:38:33 -03:00
transaction.to_update = sorted(set(installed).intersection(transaction.to_add))
to_remove_from_add = sorted(set(transaction.to_update).intersection(transaction.to_add))
for name in to_remove_from_add:
2013-01-20 13:38:33 -03:00
transaction.to_add.remove(name)
if transaction.to_add:
transaction_sum.append(['To install:', transaction.to_add[0]])
2012-12-31 11:41:51 -03:00
i = 1
2013-01-20 13:38:33 -03:00
while i < len(transaction.to_add):
transaction_sum.append([' ', transaction.to_add[i]])
2012-12-31 11:41:51 -03:00
i += 1
2013-02-10 11:59:53 -03:00
if mode == 'manager':
if transaction.to_update:
transaction_sum.append(['To update:', transaction.to_update[0]])
i = 1
while i < len(transaction.to_update):
transaction_sum.append([' ', transaction.to_update[i]])
i += 1
2012-12-31 11:41:51 -03:00
2013-01-20 13:38:33 -03:00
def handle_error(error):
global transaction_type
global transaction_dict
2013-03-15 13:15:34 -03:00
ProgressWindow.hide()
2013-03-18 07:07:58 -03:00
#while Gtk.events_pending():
# Gtk.main_iteration()
2013-02-10 11:59:53 -03:00
if error:
2013-03-05 06:52:27 -03:00
if not 'DBus.Error.NoReply' in str(error):
print('error:', error)
2013-02-27 11:15:51 -03:00
transaction.ErrorDialog.format_secondary_text(error)
2013-02-10 11:59:53 -03:00
response = transaction.ErrorDialog.run()
if response:
transaction.ErrorDialog.hide()
2013-01-20 13:38:33 -03:00
transaction.t_lock = False
2013-03-15 13:15:34 -03:00
transaction.Release()
2013-02-10 11:59:53 -03:00
if mode == 'manager':
transaction.to_add = []
transaction.to_remove = []
transaction_dict.clear()
transaction_type = None
2013-03-26 10:26:16 -03:00
transaction.get_handle()
2013-02-22 12:43:52 -03:00
transaction.update_db()
set_packages_list()
2013-02-10 11:59:53 -03:00
if mode == 'updater':
have_updates()
2013-01-20 13:38:33 -03:00
def handle_reply(reply):
global transaction_type
global transaction_dict
2013-03-15 13:15:34 -03:00
ProgressWindow.hide()
2013-03-18 07:07:58 -03:00
#while Gtk.events_pending():
# Gtk.main_iteration()
2013-02-10 11:59:53 -03:00
if reply:
2013-03-15 13:15:34 -03:00
transaction.InfoDialog.format_secondary_text(reply)
response = transaction.InfoDialog.run()
2013-01-23 11:12:11 -03:00
if response:
2013-03-15 13:15:34 -03:00
transaction.InfoDialog.hide()
2013-01-20 13:38:33 -03:00
transaction.t_lock = False
2013-03-05 06:52:27 -03:00
try:
transaction.Release()
except:
pass
2013-01-20 13:38:33 -03:00
transaction.to_add = []
transaction.to_remove = []
transaction_dict.clear()
2013-03-26 10:26:16 -03:00
transaction.get_handle()
2013-02-22 12:43:52 -03:00
transaction.update_db()
if (transaction_type == "install") or (transaction_type == "remove"):
transaction_type = None
set_packages_list()
else:
transaction_type = None
2013-02-10 11:59:53 -03:00
if have_updates():
if mode == 'manager':
do_sysupgrade()
2013-03-15 13:15:34 -03:00
bus.add_signal_receiver(handle_reply, dbus_interface = "org.manjaro.pamac", signal_name = "EmitTransactionDone")
bus.add_signal_receiver(handle_error, dbus_interface = "org.manjaro.pamac", signal_name = "EmitTransactionError")
def do_refresh():
"""Sync databases like pacman -Sy"""
if transaction.t_lock is False:
transaction.t_lock = True
2013-03-01 15:11:55 -03:00
progress_label.set_text('Refreshing...')
action_icon.set_from_file('/usr/share/pamac/icons/24x24/status/refresh-cache.png')
2013-03-18 07:07:58 -03:00
progress_bar.set_text('')
progress_bar.set_fraction(0)
2013-03-01 15:11:55 -03:00
ProgressWindow.show_all()
while Gtk.events_pending():
Gtk.main_iteration()
2013-03-18 07:07:58 -03:00
transaction.Refresh()#reply_handler = handle_reply, error_handler = handle_error, timeout = 2000*1000)
2013-02-10 11:59:53 -03:00
def have_updates():
do_syncfirst, updates = transaction.get_updates()
update_listore.clear()
2013-03-26 07:02:17 -03:00
update_top_label.set_justify(Gtk.Justification.CENTER)
2013-02-10 11:59:53 -03:00
if not updates:
2013-03-26 07:02:17 -03:00
update_listore.append(['', ''])
update_bottom_label.set_markup('')
2013-03-28 10:59:23 -03:00
update_top_label.set_markup('<big><b>No available update </b></big>')
2013-02-10 11:59:53 -03:00
return False
else:
2013-03-26 07:02:17 -03:00
dsize = 0
2013-02-10 11:59:53 -03:00
for pkg in updates:
pkgname = pkg.name+" "+pkg.version
update_listore.append([pkgname, common.format_size(pkg.size)])
2013-03-26 07:02:17 -03:00
dsize += pkg.download_size
2013-03-28 10:59:23 -03:00
update_bottom_label.set_markup('<b>Total download size: </b>'+common.format_size(dsize))
update_top_label.set_markup('<big><b>{} available updates</b></big>'.format(len(updates)))
2013-02-10 11:59:53 -03:00
return True
def do_sysupgrade():
global transaction_type
"""Upgrade a system like pacman -Su"""
if transaction.t_lock is False:
transaction_type = "update"
2013-02-06 12:09:43 -03:00
do_syncfirst, updates = transaction.get_updates()
if updates:
transaction.to_add = []
transaction.to_remove = []
2013-02-10 11:59:53 -03:00
if do_syncfirst:
2013-03-18 07:07:58 -03:00
check_conflicts('normal', updates)
2013-02-10 11:59:53 -03:00
for pkg in updates:
transaction.to_add.append(pkg.name)
2013-02-11 11:45:24 -03:00
if transaction.init_transaction(recurse = True, needed = True):
2013-02-06 12:09:43 -03:00
for pkgname in transaction.to_add:
transaction.Add(pkgname)
for pkgname in transaction.to_remove:
transaction.Remove(pkgname)
error = transaction.Prepare()
if error:
handle_error(error)
else:
transaction.get_to_remove()
transaction.get_to_add()
set_transaction_sum()
2013-02-10 11:59:53 -03:00
if mode == 'updater':
if len(transaction.to_add) + len(transaction.to_remove) != 0:
ConfDialog.show_all()
else:
finalize()
if mode == 'manager':
ConfDialog.show_all()
else:
2013-03-18 07:07:58 -03:00
check_conflicts('updating', updates)
2013-02-10 11:59:53 -03:00
if transaction.init_transaction(noconflicts = True):
error = transaction.Sysupgrade()
if error:
handle_error(error)
else:
for pkgname in transaction.to_add:
transaction.Add(pkgname)
for pkgname in transaction.to_remove:
transaction.Remove(pkgname)
error = transaction.Prepare()
if error:
handle_error(error)
else:
transaction.get_to_remove()
transaction.get_to_add()
set_transaction_sum()
if mode == 'updater':
if len(transaction.to_add) + len(transaction.to_remove) != 0:
ConfDialog.show_all()
else:
finalize()
if mode == 'manager':
ConfDialog.show_all()
def finalize():
2013-03-01 15:11:55 -03:00
progress_label.set_text('Preparing...')
action_icon.set_from_file('/usr/share/pamac/icons/24x24/status/setup.png')
progress_bar.set_text('')
2013-03-18 07:07:58 -03:00
progress_bar.set_fraction(0)
2013-03-01 15:11:55 -03:00
ProgressWindow.show_all()
2013-02-10 11:59:53 -03:00
while Gtk.events_pending():
Gtk.main_iteration()
try:
transaction.Commit()#reply_handler = handle_reply, error_handler = handle_error, timeout = 2000*1000)
except dbus.exceptions.DBusException as e:
handle_error(str(e))
2013-01-20 13:38:33 -03:00
2013-03-18 07:07:58 -03:00
def check_conflicts(mode, pkg_list):
2013-02-06 12:09:43 -03:00
depends = [pkg_list]
warning = ''
2013-02-27 11:15:51 -03:00
error = ''
2013-02-06 12:09:43 -03:00
pkgs = transaction.handle.get_localdb().search('linux3')
installed_linux = []
2013-03-20 06:03:22 -03:00
for item in pkgs:
if len(item.name) == 7:
installed_linux.append(item.name)
2013-02-06 12:09:43 -03:00
for to_install in transaction.to_add:
if 'linux3' in to_install:
if len(to_install) == 7:
installed_linux.append(to_install)
i = 0
while depends[i]:
depends.append([])
for pkg in depends[i]:
if 'linux3' in pkg.name:
for _pkg in transaction.localpkgs.values():
for depend in _pkg.depends:
if '-modules' in depend:
for __pkg in transaction.syncpkgs.values():
if not __pkg.name in transaction.localpkgs.keys():
for name in __pkg.provides:
for linux in installed_linux:
if linux in __pkg.name:
if common.format_pkg_name(depend) == common.format_pkg_name(name):
if not __pkg.name in transaction.to_add:
print(i,'module',__pkg)
depends[i+1].append(__pkg)
transaction.to_add.append(__pkg.name)
2013-02-06 12:09:43 -03:00
for depend in pkg.depends:
provide = pyalpm.find_satisfier(transaction.localpkgs.values(), depend)
if provide:
print(i,'local',provide)
if provide.name != common.format_pkg_name(depend):
if ('-modules' in depend) or ('linux' in depend):
for _pkg in transaction.syncpkgs.values():
if not _pkg.name in transaction.localpkgs.keys():
for name in _pkg.provides:
2013-02-06 12:09:43 -03:00
for linux in installed_linux:
if linux in _pkg.name:
2013-02-06 12:09:43 -03:00
if common.format_pkg_name(depend) == common.format_pkg_name(name):
if not _pkg.name in transaction.to_add:
depends[i+1].append(_pkg)
transaction.to_add.append(_pkg.name)
2013-02-06 12:09:43 -03:00
else:
provide = pyalpm.find_satisfier(transaction.syncpkgs.values(), depend)
if provide:
print(i,'sync',provide)
if provide.name != common.format_pkg_name(depend):
if ('-modules' in depend) or ('linux' in depend):
for _pkg in transaction.syncpkgs.values():
if not _pkg.name in transaction.localpkgs.keys():
for name in _pkg.provides:
2013-02-06 12:09:43 -03:00
for linux in installed_linux:
if linux in _pkg.name:
2013-02-06 12:09:43 -03:00
if common.format_pkg_name(depend) == common.format_pkg_name(name):
if not _pkg.name in transaction.to_add:
depends[i+1].append(_pkg)
transaction.to_add.append(_pkg.name)
else:
2013-02-27 11:15:51 -03:00
already_provided = False
for pkgname in transaction.to_add:
_pkg = transaction.syncpkgs[pkgname]
provide = pyalpm.find_satisfier([_pkg], depend)
if provide:
already_provided = True
if not already_provided:
to_add_to_depends = choose_provides(depend)
for _pkg in to_add_to_depends:
if not _pkg.name in transaction.to_add:
depends[i+1].append(_pkg)
transaction.to_add.append(_pkg.name)
2013-02-06 12:09:43 -03:00
else:
depends[i+1].append(provide)
2013-03-18 07:07:58 -03:00
if mode == 'updating':
for replace in pkg.replaces:
provide = pyalpm.find_satisfier(transaction.localpkgs.values(), replace)
if provide:
if provide.name != pkg.name:
if not provide.name in transaction.to_remove:
transaction.to_remove.append(provide.name)
if warning:
warning += '\n'
warning += provide.name+' will be replaced by '+pkg.name
2013-02-06 12:09:43 -03:00
for conflict in pkg.conflicts:
provide = pyalpm.find_satisfier(transaction.localpkgs.values(), conflict)
if provide:
if provide.name != pkg.name:
2013-03-25 13:51:20 -03:00
if transaction.syncpkgs.__contains__(provide.name):
new_provide = pyalpm.find_satisfier([transaction.syncpkgs[provide.name]], conflict)
if new_provide:
required = pkg.compute_requiredby()
if required:
str_required = ''
for item in required:
if str_required:
str_required += ', '
str_required += item
if error:
error += '\n'
error += '{} conflicts with {} but cannot be removed because it is needed by {}'.format(provide.name, pkg.name, str_required)
elif not provide.name in transaction.to_remove:
transaction.to_remove.append(provide.name)
if warning:
warning += '\n'
warning += pkg.name+' conflicts with '+provide.name
2013-02-06 12:09:43 -03:00
provide = pyalpm.find_satisfier(depends[0], conflict)
if provide:
if not common.format_pkg_name(conflict) == pkg.name:
if not common.format_pkg_name(conflict) in transaction.to_remove:
if pkg.name in transaction.to_add and common.format_pkg_name(conflict) in transaction.to_add:
transaction.to_add.remove(common.format_pkg_name(conflict))
transaction.to_add.remove(pkg.name)
if warning:
2013-03-18 07:07:58 -03:00
warning += '\n'
warning += pkg.name+' conflicts with '+common.format_pkg_name(conflict)+'\nNone of them will be installed'
2013-02-06 12:09:43 -03:00
i += 1
for pkg in transaction.localpkgs.values():
for conflict in pkg.conflicts:
provide = pyalpm.find_satisfier(depends[0], conflict)
if provide:
if provide.name != pkg.name:
2013-03-25 13:51:20 -03:00
if transaction.syncpkgs.__contains__(pkg.name):
new_provide = pyalpm.find_satisfier([transaction.syncpkgs[pkg.name]], conflict)
if new_provide:
required = pkg.compute_requiredby()
if required:
str_required = ''
for item in required:
if str_required:
str_required += ', '
str_required += item
if error:
error += '\n'
error += '{} conflicts with {} but cannot be removed because it is needed by {}'.format(provide.name, pkg.name, str_required)
elif not provide.name in transaction.to_remove:
transaction.to_remove.append(pkg.name)
if warning:
warning += '\n'
warning += provide.name+' conflicts with '+pkg.name
2013-03-18 07:07:58 -03:00
if mode == 'updating':
for pkg in transaction.syncpkgs.values():
for replace in pkg.replaces:
provide = pyalpm.find_satisfier(transaction.localpkgs.values(), replace)
if provide:
if not common.format_pkg_name(replace) in transaction.syncpkgs.keys():
if provide.name != pkg.name:
if not pkg.name in transaction.localpkgs.keys():
if common.format_pkg_name(replace) in transaction.localpkgs.keys():
if not provide.name in transaction.to_remove:
transaction.to_remove.append(provide.name)
if warning:
warning += '\n'
warning += provide.name+' will be replaced by '+pkg.name
if not pkg.name in transaction.to_add:
transaction.to_add.append(pkg.name)
print('check result:', 'to add:', transaction.to_add, 'to remove:', transaction.to_remove)
2013-02-06 12:09:43 -03:00
if warning:
transaction.WarningDialog.format_secondary_text(warning)
response = transaction.WarningDialog.run()
if response:
transaction.WarningDialog.hide()
2013-02-27 11:15:51 -03:00
if error:
handle_error(error)
2013-02-06 12:09:43 -03:00
def choose_provides(name):
provides = OrderedDict()
already_add = []
for pkg in transaction.syncpkgs.values():
for provide in pkg.provides:
if common.format_pkg_name(name) == common.format_pkg_name(provide):
if not pkg.name in provides.keys():
provides[pkg.name] = pkg
if provides:
choose_label.set_markup('<b>{} is provided by {} packages.\nPlease choose the one(s) you want to install:</b>'.format(name,str(len(provides.keys()))))
choose_list.clear()
for name in provides.keys():
if transaction.handle.get_localdb().get_pkg(name):
choose_list.append([True, name])
else:
2013-02-06 12:09:43 -03:00
choose_list.append([False, name])
ChooseDialog.run()
return [provides[pkgname] for pkgname in transaction.to_provide]
2013-02-11 11:45:24 -03:00
else:
return []
2013-01-27 14:15:34 -03:00
2012-12-12 13:12:27 -03:00
class Handler:
2013-02-10 11:59:53 -03:00
#Manager Handlers
def on_ManagerWindow_delete_event(self, *arg):
2013-01-23 11:12:11 -03:00
transaction.StopDaemon()
2013-02-10 11:59:53 -03:00
common.rm_pid_file()
Gtk.main_quit()
2012-12-12 13:12:27 -03:00
2013-02-10 11:59:53 -03:00
def on_Manager_QuitButton_clicked(self, *arg):
2013-01-23 11:12:11 -03:00
transaction.StopDaemon()
2013-02-10 11:59:53 -03:00
common.rm_pid_file()
Gtk.main_quit()
2012-12-12 13:12:27 -03:00
2013-02-10 11:59:53 -03:00
def on_Manager_ValidButton_clicked(self, *arg):
if not transaction_dict:
2012-12-15 13:27:36 -03:00
transaction.ErrorDialog.format_secondary_text("No package is selected")
2013-01-20 13:38:33 -03:00
response = transaction.ErrorDialog.run()
2012-12-12 13:12:27 -03:00
if response:
2012-12-15 13:27:36 -03:00
transaction.ErrorDialog.hide()
else:
if transaction.t_lock is True:
2012-12-31 11:41:51 -03:00
print('Transaction locked')
else:
if transaction_type is "remove":
2013-02-11 11:45:24 -03:00
if transaction.init_transaction(cascade = True, recurse = True):
2013-01-16 15:09:52 -03:00
for pkgname in transaction_dict.keys():
transaction.Remove(pkgname)
error = transaction.Prepare()
if error:
handle_error(error)
else:
transaction.get_to_remove()
transaction.get_to_add()
set_transaction_sum()
ConfDialog.show_all()
2012-12-29 11:06:44 -03:00
if transaction_type is "install":
2013-02-06 12:09:43 -03:00
transaction.to_add = []
for pkgname in transaction_dict.keys():
transaction.to_add.append(pkgname)
transaction.to_remove = []
2013-03-18 07:07:58 -03:00
check_conflicts('normal', transaction_dict.values())
2013-02-06 12:09:43 -03:00
if transaction.to_add:
2013-02-16 13:27:46 -03:00
if transaction.init_transaction(noconflicts = True):
2013-02-01 10:50:15 -03:00
for pkgname in transaction.to_add:
transaction.Add(pkgname)
for pkgname in transaction.to_remove:
transaction.Remove(pkgname)
error = transaction.Prepare()
if error:
handle_error(error)
else:
transaction.get_to_remove()
transaction.get_to_add()
set_transaction_sum()
ConfDialog.show_all()
else:
2013-02-06 12:09:43 -03:00
transaction.WarningDialog.format_secondary_text('Nothing to do')
response = transaction.WarningDialog.run()
if response:
transaction.WarningDialog.hide()
2013-02-01 10:50:15 -03:00
transaction.t_lock = False
2012-12-12 13:12:27 -03:00
2013-02-10 11:59:53 -03:00
def on_Manager_EraseButton_clicked(self, *arg):
2012-12-12 13:12:27 -03:00
global transaction_type
global transaction_dict
transaction_dict.clear()
2013-02-01 10:50:15 -03:00
if transaction_type:
transaction_type = None
refresh_packages_list()
2012-12-12 13:12:27 -03:00
2013-02-10 11:59:53 -03:00
def on_Manager_RefreshButton_clicked(self, *arg):
2013-02-06 12:09:43 -03:00
do_refresh()
2012-12-12 13:12:27 -03:00
2012-12-31 11:41:51 -03:00
def on_TransCancelButton_clicked(self, *arg):
2013-01-26 10:42:01 -03:00
global transaction_type
2013-03-01 15:11:55 -03:00
ProgressWindow.hide()
2012-12-31 11:41:51 -03:00
ConfDialog.hide()
transaction.t_lock = False
transaction.Release()
2013-01-26 10:42:01 -03:00
if transaction_type == "update":
transaction_type = None
2012-12-31 11:41:51 -03:00
def on_TransValidButton_clicked(self, *arg):
ConfDialog.hide()
2013-02-10 11:59:53 -03:00
finalize()
2012-12-31 11:41:51 -03:00
2012-12-12 13:12:27 -03:00
def on_search_entry_icon_press(self, *arg):
2013-03-25 13:51:20 -03:00
global current_filter
current_filter = ('search', search_entry.get_text().split())
2012-12-12 13:12:27 -03:00
set_packages_list()
def on_search_entry_activate(self, widget):
2013-03-25 13:51:20 -03:00
global current_filter
current_filter = ('search', search_entry.get_text().split())
2012-12-12 13:12:27 -03:00
set_packages_list()
2013-03-25 13:51:20 -03:00
def on_list_treeview_selection_changed(self, widget):
liste, line = list_selection.get_selected()
2012-12-12 13:12:27 -03:00
if line is not None:
if packages_list[line][0] in pkg_object_dict.keys():
pkg_object = pkg_object_dict[packages_list[line][0]]
if pkg_installed_dict[packages_list[line][0]] is True:
style = "local"
2013-03-28 10:59:23 -03:00
set_files_list(pkg_object)
files_scrolledwindow.set_visible(True)
2012-12-12 13:12:27 -03:00
else:
style = "sync"
2013-03-28 10:59:23 -03:00
files_scrolledwindow.set_visible(False)
set_infos_list(pkg_object)
set_deps_list(pkg_object, style)
set_details_list(pkg_object, style)
2012-12-12 13:12:27 -03:00
2013-03-25 13:51:20 -03:00
def on_search_treeview_selection_changed(self, widget):
global current_filter
liste, line = search_selection.get_selected()
if line is not None:
current_filter = ('search', search_list[line][0].split())
set_packages_list()
def on_groups_treeview_selection_changed(self, widget):
global current_filter
liste, line = groups_selection.get_selected()
2012-12-12 13:12:27 -03:00
if line is not None:
2013-03-25 13:51:20 -03:00
current_filter = ('group', groups_list[line][0])
set_packages_list()
def on_state_treeview_selection_changed(self, widget):
global current_filter
liste, line = state_selection.get_selected()
if line is not None:
if state_list[line][0] == 'Installed':
current_filter = ('installed', None)
if state_list[line][0] == 'Uninstalled':
current_filter = ('uninstalled', None)
if state_list[line][0] == 'Orphans':
current_filter = ('orphans', None)
if state_list[line][0] == 'To install':
current_filter = ('to_install', None)
if state_list[line][0] == 'To remove':
current_filter = ('to_remove', None)
set_packages_list()
def on_repos_treeview_selection_changed(self, widget):
global current_filter
liste, line = repos_selection.get_selected()
if line is not None:
if repos_list[line][0] == 'local':
current_filter = ('local', None)
else:
current_filter = ('repo', repos_list[line][0])
2012-12-12 13:12:27 -03:00
set_packages_list()
def on_cellrenderertoggle1_toggled(self, widget, line):
global transaction_type
global transaction_dict
global pkg_object_dict
if packages_list[line][0] in transaction_dict.keys():
2013-03-25 13:51:20 -03:00
if transaction_type == "remove":
packages_list[line][4] = installed_icon
if transaction_type == "install":
packages_list[line][4] = uninstalled_icon
2012-12-12 13:12:27 -03:00
transaction_dict.pop(packages_list[line][0])
if not transaction_dict:
transaction_type = None
lin = 0
while lin < len(packages_list):
if packages_list[lin][0] in config.holdpkg:
packages_list[lin][2] = False
else:
packages_list[lin][2] = True
lin += 1
else:
if packages_list[line][1] is True:
transaction_type = "remove"
transaction_dict[packages_list[line][0]] = pkg_object_dict[packages_list[line][0]]
2013-03-25 13:51:20 -03:00
packages_list[line][4] = to_remove_icon
2012-12-12 13:12:27 -03:00
lin = 0
while lin < len(packages_list):
if not packages_list[lin][0] in transaction_dict.keys():
if packages_list[lin][1] is False:
packages_list[lin][2] = False
lin += 1
if packages_list[line][1] is False:
transaction_type = "install"
transaction_dict[packages_list[line][0]] = pkg_object_dict[packages_list[line][0]]
2013-03-25 13:51:20 -03:00
packages_list[line][4] = to_install_icon
2012-12-12 13:12:27 -03:00
lin = 0
while lin < len(packages_list):
if not packages_list[lin][0] in transaction_dict.keys():
if packages_list[lin][1] is True:
packages_list[lin][2] = False
lin += 1
2013-03-25 13:51:20 -03:00
packages_list[line][3] = not packages_list[line][3]
2012-12-12 13:12:27 -03:00
packages_list[line][2] = True
2013-01-27 14:15:34 -03:00
def on_cellrenderertoggle2_toggled(self, widget, line):
choose_list[line][0] = not choose_list[line][0]
def on_ChooseButton_clicked(self, *arg):
ChooseDialog.hide()
line = 0
2013-02-06 12:09:43 -03:00
transaction.to_provide = []
2013-01-27 14:15:34 -03:00
while line < len(choose_list):
if choose_list[line][0] is True:
2013-02-06 12:09:43 -03:00
if not choose_list[line][1] in transaction.to_provide:
if not choose_list[line][1] in transaction.localpkgs.keys():
transaction.to_provide.append(choose_list[line][1])
if choose_list[line][0] is False:
2013-02-06 12:09:43 -03:00
if choose_list[line][1] in transaction.to_provide:
transaction.to_provide.remove(choose_list[line][1])
2013-01-27 14:15:34 -03:00
line += 1
2013-03-18 07:07:58 -03:00
#Updater Handlers
2013-02-10 11:59:53 -03:00
def on_UpdaterWindow_delete_event(self, *arg):
transaction.StopDaemon()
common.rm_pid_file()
Gtk.main_quit()
def on_Updater_QuitButton_clicked(self, *arg):
transaction.StopDaemon()
common.rm_pid_file()
Gtk.main_quit()
def on_Updater_ApplyButton_clicked(self, *arg):
do_sysupgrade()
def on_Updater_RefreshButton_clicked(self, *arg):
do_refresh()
2013-02-10 11:59:53 -03:00
def on_ProgressCancelButton_clicked(self, *arg):
2013-03-01 15:11:55 -03:00
print('cancelled')
2013-03-15 13:15:34 -03:00
error = transaction.Interrupt()
if error:
handle_error(error)
else:
handle_reply('')
2013-02-10 11:59:53 -03:00
def main(_mode):
if common.pid_file_exists():
transaction.ErrorDialog.format_secondary_text('Another instance of Pamac is running')
response = transaction.ErrorDialog.run()
if response:
transaction.ErrorDialog.hide()
else:
common.write_pid_file()
global mode
mode = _mode
interface.connect_signals(Handler())
do_refresh()
2013-03-26 10:26:16 -03:00
transaction.get_handle()
get_groups()
get_repos()
2013-02-10 11:59:53 -03:00
if mode == 'manager':
ManagerWindow.show_all()
if mode == 'updater':
2013-03-26 07:02:17 -03:00
update_top_label.set_markup('<big><b>Available updates</b></big>')
update_bottom_label.set_markup('')
2013-02-10 11:59:53 -03:00
UpdaterWindow.show_all()
while Gtk.events_pending():
Gtk.main_iteration()
Gtk.main()