2013-04-07 09:16:23 -03:00
#! /usr/bin/python3
2013-03-31 14:31:33 -03:00
# -*- coding:utf-8 -*-
2012-12-12 13:12:27 -03:00
2013-04-17 09:41:10 -03:00
from gi . repository import Gtk , Gdk
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
2013-03-31 14:31:33 -03:00
# i18n
import gettext
import locale
locale . bindtextdomain ( ' pamac ' , ' /usr/share/locale ' )
gettext . bindtextdomain ( ' pamac ' , ' /usr/share/locale ' )
gettext . textdomain ( ' pamac ' )
_ = gettext . gettext
2012-12-12 13:12:27 -03:00
interface = Gtk . Builder ( )
2013-03-31 14:31:33 -03:00
interface . set_translation_domain ( ' pamac ' )
2013-01-06 15:10:13 -03:00
2013-04-10 11:20:54 -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 ' )
2013-03-15 13:15:34 -03:00
#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 ' )
2013-02-01 09:41:36 -03:00
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 )
2013-03-31 14:31:33 -03:00
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 ) :
2013-03-29 11:49:47 -03:00
if percent > 1 :
2013-03-01 15:11:55 -03:00
progress_bar . pulse ( )
else :
2013-03-29 11:49:47 -03:00
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-04-17 09:41:10 -03:00
pkg_name_list = set ( )
2013-03-25 13:51:20 -03:00
current_filter = ( None , None )
2013-03-01 15:11:55 -03:00
mode = None
2013-03-31 14:31:33 -03:00
states = [ _ ( ' Installed ' ) , _ ( ' Uninstalled ' ) , _ ( ' Orphans ' ) , _ ( ' To install ' ) , _ ( ' To remove ' ) ]
2013-03-25 13:51:20 -03:00
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 ] )
2013-03-31 14:31:33 -03:00
repos_list . append ( [ _ ( ' local ' ) ] )
2013-03-25 13:51:20 -03:00
2012-12-12 13:12:27 -03:00
def set_list_dict_search ( * patterns ) :
global pkg_name_list
2013-04-17 09:41:10 -03:00
pkg_name_list . clear ( )
2013-01-27 14:15:34 -03:00
for db in transaction . handle . get_syncdbs ( ) :
2013-04-12 10:33:39 -03:00
for pkg in db . search ( * patterns ) :
2013-04-17 09:41:10 -03:00
pkg_name_list . add ( pkg . name )
2013-04-12 10:33:39 -03:00
for pkg in transaction . handle . get_localdb ( ) . search ( * patterns ) :
2013-04-17 09:41:10 -03:00
pkg_name_list . add ( pkg . name )
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
2013-04-17 09:41:10 -03:00
pkg_name_list . clear ( )
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
2013-04-12 10:33:39 -03:00
for pkg in pkg_list :
2013-04-17 09:41:10 -03:00
pkg_name_list . add ( pkg . name )
2013-04-10 11:20:54 -03:00
db = transaction . handle . get_localdb ( )
2012-12-12 13:12:27 -03:00
grp = db . read_grp ( group )
if grp is not None :
name , pkg_list = grp
2013-04-12 10:33:39 -03:00
for pkg in pkg_list :
2013-04-17 09:41:10 -03:00
pkg_name_list . add ( pkg . name )
2012-12-12 13:12:27 -03:00
2013-03-25 13:51:20 -03:00
def set_list_dict_installed ( ) :
global pkg_name_list
2013-04-17 09:41:10 -03:00
pkg_name_list . clear ( )
pkg_name_list = set ( transaction . localpkgs . keys ( ) )
2013-03-25 13:51:20 -03:00
def set_list_dict_uninstalled ( ) :
global pkg_name_list
2013-04-17 09:41:10 -03:00
pkg_name_list . clear ( )
pkg_name_list = set ( transaction . syncpkgs . keys ( ) ) . difference ( set ( transaction . localpkgs . keys ( ) ) )
2013-03-25 13:51:20 -03:00
def set_list_dict_local ( ) :
global pkg_name_list
2013-04-17 09:41:10 -03:00
pkg_name_list . clear ( )
pkg_name_list = set ( transaction . localpkgs . keys ( ) ) . difference ( set ( transaction . syncpkgs . keys ( ) ) )
2013-03-25 13:51:20 -03:00
def set_list_dict_orphans ( ) :
global pkg_name_list
2013-04-17 09:41:10 -03:00
pkg_name_list . clear ( )
2013-04-12 10:33:39 -03:00
for pkg in transaction . localpkgs . values ( ) :
if pkg . reason == 1 :
2013-04-17 09:41:10 -03:00
required = set ( pkg . compute_requiredby ( ) )
required & = set ( transaction . localpkgs . keys ( ) )
if not required :
pkg_name_list . add ( pkg . name )
2013-03-25 13:51:20 -03:00
def set_list_dict_to_install ( ) :
global pkg_name_list
2013-04-17 09:41:10 -03:00
pkg_name_list . clear ( )
pkg_name_list = transaction . to_add . copy ( )
2013-03-25 13:51:20 -03:00
def set_list_dict_to_remove ( ) :
global pkg_name_list
2013-04-17 09:41:10 -03:00
pkg_name_list . clear ( )
pkg_name_list = transaction . to_remove . copy ( )
2013-03-25 13:51:20 -03:00
def set_list_dict_repos ( repo ) :
global pkg_name_list
2013-04-17 09:41:10 -03:00
pkg_name_list . clear ( )
2013-03-25 13:51:20 -03:00
for db in transaction . handle . get_syncdbs ( ) :
if db . name == repo :
2013-04-12 10:33:39 -03:00
for pkg in db . pkgcache :
2013-04-17 09:41:10 -03:00
pkg_name_list . add ( pkg . name )
2013-03-25 13:51:20 -03:00
2012-12-12 13:12:27 -03:00
def refresh_packages_list ( ) :
2013-04-17 09:41:10 -03:00
if current_filter [ 0 ] :
ManagerWindow . get_root_window ( ) . set_cursor ( Gdk . Cursor ( Gdk . CursorType . WATCH ) )
while Gtk . events_pending ( ) :
Gtk . main_iteration ( )
packages_list . clear ( )
if not pkg_name_list :
packages_list . append ( [ _ ( ' No package found ' ) , False , False , False , search_icon , ' ' , 0 ] )
else :
#installed = set(transaction.localpkgs.keys()) - transaction.to_remove
#uninstalled = (set(transaction.syncpkgs.keys()) - installed) - transaction.to_add
#to_lock = installed & set(config.holdpkg)
name_list = sorted ( pkg_name_list )
for name in name_list :
if name in config . holdpkg :
packages_list . append ( [ name , True , False , True , locked_icon , ' ' , 0 ] )
elif name in transaction . to_add :
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 ] )
2013-04-17 09:41:10 -03:00
elif name in transaction . to_remove :
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 ] )
2013-04-17 09:41:10 -03:00
elif name in transaction . localpkgs . keys ( ) :
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 ] )
2013-04-17 09:41:10 -03:00
#elif name in uninstalled:
else :
packages_list . append ( [ name , False , True , False , uninstalled_icon , common . format_size ( transaction . syncpkgs [ name ] . isize ) , transaction . syncpkgs [ name ] . isize ] )
ManagerWindow . get_root_window ( ) . set_cursor ( Gdk . Cursor ( Gdk . CursorType . ARROW ) )
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 ] )
2013-04-17 09:41:10 -03:00
elif current_filter [ 0 ] == ' group ' :
2013-03-25 13:51:20 -03:00
set_list_dict_group ( current_filter [ 1 ] )
2013-04-17 09:41:10 -03:00
elif current_filter [ 0 ] == ' installed ' :
2013-03-25 13:51:20 -03:00
set_list_dict_installed ( )
2013-04-17 09:41:10 -03:00
elif current_filter [ 0 ] == ' uninstalled ' :
2013-03-25 13:51:20 -03:00
set_list_dict_uninstalled ( )
2013-04-17 09:41:10 -03:00
elif current_filter [ 0 ] == ' orphans ' :
2013-03-25 13:51:20 -03:00
set_list_dict_orphans ( )
2013-04-17 09:41:10 -03:00
elif current_filter [ 0 ] == ' local ' :
2013-03-25 13:51:20 -03:00
set_list_dict_local ( )
2013-04-17 09:41:10 -03:00
elif current_filter [ 0 ] == ' to_install ' :
2013-03-25 13:51:20 -03:00
set_list_dict_to_install ( )
2013-04-17 09:41:10 -03:00
elif current_filter [ 0 ] == ' to_remove ' :
2013-03-25 13:51:20 -03:00
set_list_dict_to_remove ( )
2013-04-17 09:41:10 -03:00
elif current_filter [ 0 ] == ' repo ' :
2013-03-25 13:51:20 -03:00
set_list_dict_repos ( current_filter [ 1 ] )
2013-04-17 09:41:10 -03:00
if current_filter [ 0 ] :
refresh_packages_list ( )
2012-12-12 13:12:27 -03:00
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 ) )
2013-04-17 09:41:10 -03:00
# fix &,-,>,< in desc
2013-04-13 09:01:50 -03:00
desc = pkg . desc . replace ( ' & ' , ' & ' )
2013-04-17 09:41:10 -03:00
desc = desc . replace ( ' <-> ' , ' / ' )
2013-04-13 09:01:50 -03:00
desc_label . set_markup ( desc )
2013-03-30 06:03:15 -03:00
# fix & in url
url = pkg . url . replace ( ' & ' , ' & ' )
link_label . set_markup ( ' <a href= \" {_url} \" > {_url} </a> ' . format ( _url = url ) )
2013-04-01 05:08:03 -03:00
licenses_label . set_markup ( _ ( ' Licenses ' ) + ' : {} ' . format ( ' ' . join ( pkg . licenses ) ) )
2013-03-28 10:59:23 -03:00
def set_deps_list ( pkg , style ) :
deps_list . clear ( )
if pkg . depends :
2013-04-01 05:08:03 -03:00
deps_list . append ( [ _ ( ' Depends On ' ) + ' : ' , ' \n ' . join ( pkg . depends ) ] )
2013-03-28 10:59:23 -03:00
if pkg . optdepends :
2013-04-01 05:08:03 -03:00
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 ( ) :
2013-03-31 14:31:33 -03:00
deps_list . append ( [ _ ( ' Required By ' ) + ' : ' , ' \n ' . join ( pkg . compute_requiredby ( ) ) ] )
2013-03-28 10:59:23 -03:00
if pkg . provides :
2013-04-07 09:16:23 -03:00
deps_list . append ( [ _ ( ' Provides ' ) + ' : ' , ' \n ' . join ( pkg . provides ) ] )
2013-03-28 10:59:23 -03:00
if pkg . replaces :
2013-04-07 09:16:23 -03:00
deps_list . append ( [ _ ( ' Replaces ' ) + ' : ' , ' \n ' . join ( pkg . replaces ) ] )
2013-03-28 10:59:23 -03:00
if pkg . conflicts :
2013-04-07 09:16:23 -03:00
deps_list . append ( [ _ ( ' Conflicts With ' ) + ' : ' , ' \n ' . join ( pkg . conflicts ) ] )
2013-03-28 10:59:23 -03:00
def set_details_list ( pkg , style ) :
details_list . clear ( )
2012-12-12 13:12:27 -03:00
if style == ' sync ' :
2013-03-31 14:31:33 -03:00
details_list . append ( [ _ ( ' Repository ' ) + ' : ' , pkg . db . name ] )
2013-03-28 10:59:23 -03:00
if pkg . groups :
2013-03-31 14:31:33 -03:00
details_list . append ( [ _ ( ' Groups ' ) + ' : ' , ' ' . join ( pkg . groups ) ] )
2013-03-28 10:59:23 -03:00
if style == ' sync ' :
2013-03-31 14:31:33 -03:00
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-31 14:31:33 -03:00
details_list . append ( [ _ ( ' Installed Size ' ) + ' : ' , common . format_size ( pkg . isize ) ] )
details_list . append ( [ _ ( ' Packager ' ) + ' : ' , pkg . packager ] )
2013-04-17 09:41:10 -03:00
details_list . append ( [ _ ( ' Architecture ' ) + ' : ' , pkg . arch ] )
2013-03-31 14:31:33 -03:00
#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-31 14:31:33 -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 :
2013-03-31 14:31:33 -03:00
reason = _ ( ' Explicitly installed ' )
2012-12-12 13:12:27 -03:00
elif pkg . reason == pyalpm . PKG_REASON_DEPEND :
2013-03-31 14:31:33 -03:00
reason = _ ( ' Installed as a dependency for another package ' )
2012-12-12 13:12:27 -03:00
else :
2013-03-31 14:31:33 -03:00
reason = _ ( ' Unknown ' )
details_list . append ( [ _ ( ' Install Reason ' ) + ' : ' , reason ] )
2012-12-12 13:12:27 -03:00
if style == ' sync ' :
2013-03-31 14:31:33 -03:00
#details_list.append([_('Install Script')':', 'Yes' if pkg.has_scriptlet else 'No'])
2013-03-28 10:59:23 -03:00
#details_list.append(['MD5 Sum:', pkg.md5sum])
#details_list.append(['SHA256 Sum:', pkg.sha256sum])
2013-03-31 14:31:33 -03:00
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 :
2013-03-31 14:31:33 -03:00
#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 ] ) ] )
2013-03-28 10:59:23 -03:00
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-31 14:31:33 -03:00
sum_top_label . set_markup ( _ ( ' <big><b>Transaction Summary</b></big> ' ) )
2013-04-17 09:41:10 -03:00
if mode == ' manager ' :
if transaction . to_update :
to_update = sorted ( transaction . to_update )
transaction_sum . append ( [ _ ( ' To update ' ) + ' : ' , to_update [ 0 ] ] )
i = 1
while i < len ( to_update ) :
transaction_sum . append ( [ ' ' , to_update [ i ] ] )
i + = 1
2013-01-20 13:38:33 -03:00
if transaction . to_add :
2013-04-17 09:41:10 -03:00
transaction . to_add - = transaction . to_update
to_add = sorted ( transaction . to_add )
if to_add :
transaction_sum . append ( [ _ ( ' To install ' ) + ' : ' , to_add [ 0 ] ] )
i = 1
while i < len ( to_add ) :
transaction_sum . append ( [ ' ' , to_add [ i ] ] )
i + = 1
if transaction . to_add or transaction . to_update :
2013-03-28 10:59:23 -03:00
dsize = 0
2013-04-17 09:41:10 -03:00
for name in transaction . to_add | transaction . to_update :
2013-03-28 10:59:23 -03:00
dsize + = transaction . syncpkgs [ name ] . download_size
2013-03-31 14:31:33 -03:00
sum_bottom_label . set_markup ( _ ( ' <b>Total download size: </b> ' ) + common . format_size ( dsize ) )
2013-04-17 09:41:10 -03:00
if transaction . to_remove :
to_remove = sorted ( transaction . to_remove )
transaction_sum . append ( [ _ ( ' To remove ' ) + ' : ' , to_remove [ 0 ] ] )
i = 1
while i < len ( to_remove ) :
transaction_sum . append ( [ ' ' , to_remove [ i ] ] )
i + = 1
sum_bottom_label . set_markup ( ' ' )
2012-12-31 11:41:51 -03:00
2013-01-20 13:38:33 -03:00
def handle_error ( error ) :
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-04-10 11:20:54 -03:00
ErrorDialog . format_secondary_text ( error )
response = ErrorDialog . run ( )
2013-02-10 11:59:53 -03:00
if response :
2013-04-10 11:20:54 -03:00
ErrorDialog . hide ( )
try :
transaction . Release ( )
except :
pass
2013-02-10 11:59:53 -03:00
if mode == ' manager ' :
2013-03-26 10:26:16 -03:00
transaction . get_handle ( )
2013-02-22 12:43:52 -03:00
transaction . update_db ( )
2013-04-17 09:41:10 -03:00
transaction . to_add . clear ( )
transaction . to_remove . clear ( )
transaction . to_update . clear ( )
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 ) :
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-04-10 11:20:54 -03:00
InfoDialog . format_secondary_text ( reply )
response = InfoDialog . run ( )
2013-01-23 11:12:11 -03:00
if response :
2013-04-10 11:20:54 -03:00
InfoDialog . hide ( )
2013-03-05 06:52:27 -03:00
try :
transaction . Release ( )
except :
pass
2013-03-26 10:26:16 -03:00
transaction . get_handle ( )
2013-02-22 12:43:52 -03:00
transaction . update_db ( )
2013-04-17 09:41:10 -03:00
if mode == ' manager ' :
transaction . to_add . clear ( )
transaction . to_remove . clear ( )
transaction . to_update . clear ( )
2013-03-30 06:03:15 -03:00
set_packages_list ( )
2013-02-10 11:59:53 -03:00
if have_updates ( ) :
if mode == ' manager ' :
do_sysupgrade ( )
2013-01-30 14:37:41 -03:00
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 " )
2013-01-30 14:37:41 -03:00
def do_refresh ( ) :
""" Sync databases like pacman -Sy """
2013-04-17 09:41:10 -03:00
progress_label . set_text ( _ ( ' Refreshing ' ) + ' ... ' )
action_icon . set_from_file ( ' /usr/share/pamac/icons/24x24/status/refresh-cache.png ' )
progress_bar . set_text ( ' ' )
progress_bar . set_fraction ( 0 )
ProgressWindow . show_all ( )
while Gtk . events_pending ( ) :
Gtk . main_iteration ( )
transaction . Refresh ( )
2013-01-30 14:37:41 -03:00
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-31 14:31:33 -03:00
update_top_label . set_markup ( _ ( ' <big><b>Your system is up-to-date</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-31 14:31:33 -03:00
update_bottom_label . set_markup ( _ ( ' <b>Total download size: </b> ' ) + common . format_size ( dsize ) )
if len ( updates ) == 1 :
update_top_label . set_markup ( _ ( ' <big><b>1 available update</b></big> ' ) )
else :
update_top_label . set_markup ( _ ( ' <big><b> {number} available updates</b></big> ' ) . format ( number = len ( updates ) ) )
2013-02-10 11:59:53 -03:00
return True
def do_sysupgrade ( ) :
2013-01-30 14:37:41 -03:00
""" Upgrade a system like pacman -Su """
2013-04-17 09:41:10 -03:00
do_syncfirst , updates = transaction . get_updates ( )
if updates :
transaction . to_add . clear ( )
transaction . to_remove . clear ( )
transaction . to_update = set ( [ pkg . name for pkg in updates ] )
check_conflicts ( )
init = False
error = ' '
if do_syncfirst :
init = transaction . init_transaction ( noconflicts = True , recurse = True )
else :
init = transaction . init_transaction ( noconflicts = True )
if init :
error = transaction . Sysupgrade ( )
if error :
handle_error ( error )
if init :
if not error :
for name in transaction . to_add | transaction . to_update :
transaction . Add ( name )
for name in transaction . to_remove :
transaction . Remove ( name )
error = transaction . Prepare ( )
if error :
handle_error ( error )
else :
transaction . get_to_remove ( )
transaction . get_to_add ( )
transaction . to_add - = transaction . to_update
set_transaction_sum ( )
if mode == ' updater ' :
if len ( transaction . to_add ) + len ( transaction . to_remove ) != 0 :
2013-02-10 11:59:53 -03:00
ConfDialog . show_all ( )
else :
2013-04-17 09:41:10 -03:00
finalize ( )
if mode == ' manager ' :
ConfDialog . show_all ( )
2013-02-10 11:59:53 -03:00
def finalize ( ) :
2013-04-17 09:41:10 -03:00
progress_label . set_text ( _ ( ' Preparing ' ) + ' ... ' )
action_icon . set_from_file ( ' /usr/share/pamac/icons/24x24/status/setup.png ' )
progress_bar . set_text ( ' ' )
progress_bar . set_fraction ( 0 )
ProgressWindow . show_all ( )
while Gtk . events_pending ( ) :
Gtk . main_iteration ( )
try :
transaction . Commit ( )
except dbus . exceptions . DBusException as e :
handle_error ( str ( e ) )
2013-01-20 13:38:33 -03:00
2013-04-17 09:41:10 -03:00
def check_conflicts ( ) :
print ( ' checking... ' )
ManagerWindow . get_root_window ( ) . set_cursor ( Gdk . Cursor ( Gdk . CursorType . WATCH ) )
while Gtk . events_pending ( ) :
Gtk . main_iteration ( )
to_check = [ transaction . syncpkgs [ name ] for name in transaction . to_add | transaction . to_update ]
already_checked = set ( pkg . name for pkg in to_check )
depends = [ to_check ]
2013-02-06 12:09:43 -03:00
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-04-17 09:41:10 -03:00
# get packages to remove
check_for_removal = transaction . to_remove . copy ( )
to_add_to_remove = set ( )
hold_requirement = { }
while check_for_removal :
for name in check_for_removal :
required = transaction . localpkgs [ name ] . compute_requiredby ( )
for requirement in required :
if requirement in config . holdpkg :
for hold in config . holdpkg :
if requirement == hold :
if error :
error + = ' \n '
error + = _ ( ' The transaction cannot be performed because it needs to remove {pkgname1} which is in HoldPkg ' ) . format ( pkgname1 = hold )
print ( _ ( ' The transaction cannot be performed because it needs to remove {pkgname1} which is in HoldPkg ' ) . format ( pkgname1 = hold ) )
else :
to_add_to_remove . add ( requirement )
to_add_to_remove & = set ( transaction . localpkgs . keys ( ) )
check_for_removal = to_add_to_remove . copy ( )
transaction . to_remove | = to_add_to_remove
to_add_to_remove . clear ( )
if error :
break
# get installed kernels
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 )
2013-04-17 09:41:10 -03:00
# check if new pkgs will replace installed ones
if transaction . to_update :
for pkg in transaction . syncpkgs . values ( ) :
for replace in pkg . replaces :
found_replace = pyalpm . find_satisfier ( transaction . localpkgs . values ( ) , replace )
if found_replace :
if not common . format_pkg_name ( replace ) in transaction . syncpkgs . keys ( ) :
if found_replace . name != pkg . name :
if not pkg . name in transaction . localpkgs . keys ( ) :
if common . format_pkg_name ( replace ) in transaction . localpkgs . keys ( ) :
if not found_replace . name in transaction . to_remove :
transaction . to_remove . add ( found_replace . name )
if warning :
warning + = ' \n '
warning + = _ ( ' {pkgname1} will be replaced by {pkgname2} ' ) . format ( pkgname1 = found_replace . name , pkgname2 = pkg . name )
print ( _ ( ' {pkgname1} will be replaced by {pkgname2} ' ) . format ( pkgname1 = found_replace . name , pkgname2 = pkg . name ) )
if not pkg . name in already_checked :
depends [ 0 ] . append ( pkg )
already_checked . add ( pkg . name )
transaction . to_add . add ( pkg . name )
# start loops to check pkgs
2013-02-06 12:09:43 -03:00
i = 0
while depends [ i ] :
2013-04-17 09:41:10 -03:00
# add a empty list for new pkgs to check next loop
2013-02-06 12:09:43 -03:00
depends . append ( [ ] )
2013-04-17 09:41:10 -03:00
# start to check one pkg
2013-02-06 12:09:43 -03:00
for pkg in depends [ i ] :
2013-04-17 09:41:10 -03:00
# check if the current pkg is a kernel and if so, check if a module is required to install
2013-02-25 13:39:43 -03:00
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 ( ) :
2013-04-17 09:41:10 -03:00
for provide in __pkg . provides :
2013-02-25 13:39:43 -03:00
for linux in installed_linux :
if linux in __pkg . name :
2013-04-17 09:41:10 -03:00
if common . format_pkg_name ( depend ) == common . format_pkg_name ( provide ) :
2013-02-25 13:39:43 -03:00
if not __pkg . name in transaction . to_add :
2013-04-17 09:41:10 -03:00
if not __pkg . name in already_checked :
depends [ i + 1 ] . append ( __pkg )
already_checked . add ( __pkg . name )
transaction . to_add . add ( __pkg . name )
# check pkg deps
2013-02-06 12:09:43 -03:00
for depend in pkg . depends :
2013-04-17 09:41:10 -03:00
# check if dep is already installed
2013-04-07 09:16:23 -03:00
found_depend = pyalpm . find_satisfier ( transaction . localpkgs . values ( ) , depend )
if found_depend :
2013-04-17 09:41:10 -03:00
# check if the dep is a kernel module to provide and if so, auto-select it
2013-04-07 09:16:23 -03:00
if found_depend . name != common . format_pkg_name ( depend ) :
2013-02-25 13:39:43 -03:00
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 :
2013-02-25 13:39:43 -03:00
if linux in _pkg . name :
2013-02-06 12:09:43 -03:00
if common . format_pkg_name ( depend ) == common . format_pkg_name ( name ) :
2013-02-25 13:39:43 -03:00
if not _pkg . name in transaction . to_add :
2013-04-17 09:41:10 -03:00
if not _pkg . name in already_checked :
depends [ i + 1 ] . append ( _pkg )
already_checked . add ( _pkg . name )
transaction . to_add . add ( _pkg . name )
else :
# add the dep in list to check its deps in next loop
if not found_depend . name in already_checked :
depends [ i + 1 ] . append ( found_depend )
already_checked . add ( found_depend . name )
2013-02-06 12:09:43 -03:00
else :
2013-04-17 09:41:10 -03:00
# found the dep in uninstalled pkgs
2013-04-07 09:16:23 -03:00
found_depend = pyalpm . find_satisfier ( transaction . syncpkgs . values ( ) , depend )
if found_depend :
2013-04-17 09:41:10 -03:00
# check if the dep is a kernel module to provide and if so, auto-select it
2013-04-07 09:16:23 -03:00
if found_depend . name != common . format_pkg_name ( depend ) :
2013-02-25 13:39:43 -03:00
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 :
2013-02-25 13:39:43 -03:00
if linux in _pkg . name :
2013-02-06 12:09:43 -03:00
if common . format_pkg_name ( depend ) == common . format_pkg_name ( name ) :
2013-02-25 13:39:43 -03:00
if not _pkg . name in transaction . to_add :
2013-04-17 09:41:10 -03:00
if not _pkg . name in already_checked :
depends [ i + 1 ] . append ( _pkg )
already_checked . add ( _pkg . name )
transaction . to_add . add ( _pkg . name )
2013-01-30 14:37:41 -03:00
else :
2013-04-17 09:41:10 -03:00
# so the dep is a virtual dep: check if it's already provides
2013-02-27 11:15:51 -03:00
already_provided = False
for pkgname in transaction . to_add :
_pkg = transaction . syncpkgs [ pkgname ]
2013-04-07 09:16:23 -03:00
found_depend = pyalpm . find_satisfier ( [ _pkg ] , depend )
if found_depend :
2013-02-27 11:15:51 -03:00
already_provided = True
2013-04-17 09:41:10 -03:00
# if not already provided, run ChooseDialog (via choose_provides)
2013-02-27 11:15:51 -03:00
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 :
2013-04-17 09:41:10 -03:00
if not _pkg . name in already_checked :
depends [ i + 1 ] . append ( _pkg )
already_checked . add ( _pkg . name )
transaction . to_add . add ( _pkg . name )
2013-02-06 12:09:43 -03:00
else :
2013-04-17 09:41:10 -03:00
# so the dep is not yet installed, add it in list to check its deps in next loop
if not found_depend . name in already_checked :
depends [ i + 1 ] . append ( found_depend )
already_checked . add ( found_depend . name )
# check if the pkg replaces installed ones
if transaction . to_update :
2013-03-18 07:07:58 -03:00
for replace in pkg . replaces :
2013-04-07 09:16:23 -03:00
found_replace = pyalpm . find_satisfier ( transaction . localpkgs . values ( ) , replace )
if found_replace :
if found_replace . name != pkg . name :
if not found_replace . name in transaction . to_remove :
2013-04-17 09:41:10 -03:00
transaction . to_remove . add ( found_replace . name )
2013-03-18 07:07:58 -03:00
if warning :
warning + = ' \n '
2013-04-07 09:16:23 -03:00
warning + = _ ( ' {pkgname1} will be replaced by {pkgname2} ' ) . format ( pkgname1 = found_replace . name , pkgname2 = pkg . name )
2013-04-17 09:41:10 -03:00
print ( _ ( ' {pkgname1} will be replaced by {pkgname2} ' ) . format ( pkgname1 = found_replace . name , pkgname2 = pkg . name ) )
# check pkg conflicts
2013-02-06 12:09:43 -03:00
for conflict in pkg . conflicts :
2013-04-17 09:41:10 -03:00
# check if the pkg conflicts with installed ones
2013-04-07 09:16:23 -03:00
found_conflict = pyalpm . find_satisfier ( transaction . localpkgs . values ( ) , conflict )
if found_conflict :
if found_conflict . name != pkg . name :
2013-04-17 09:41:10 -03:00
# if pkg provides the conflict no need to check if it can be safely removed
2013-04-07 09:16:23 -03:00
will_provide_conflict = pyalpm . find_satisfier ( [ pkg ] , conflict )
if will_provide_conflict :
if not found_conflict . name in transaction . to_remove :
2013-04-17 09:41:10 -03:00
transaction . to_remove . add ( found_conflict . name )
2013-04-07 09:16:23 -03:00
if warning :
warning + = ' \n '
warning + = _ ( ' {pkgname1} conflicts with {pkgname2} ' ) . format ( pkgname1 = pkg . name , pkgname2 = found_conflict . name )
2013-04-17 09:41:10 -03:00
print ( _ ( ' {pkgname1} conflicts with {pkgname2} ' ) . format ( pkgname1 = pkg . name , pkgname2 = found_conflict . name ) )
2013-04-07 09:16:23 -03:00
else :
2013-04-17 09:41:10 -03:00
# if the conflict will be updated, check the conflicts of the new one
if found_conflict . name in transaction . to_update :
2013-04-07 09:16:23 -03:00
new_found_conflict = pyalpm . find_satisfier ( [ transaction . syncpkgs [ found_conflict . name ] ] , conflict )
if new_found_conflict :
2013-04-17 09:41:10 -03:00
# check if the conflict can be safely removed
required = set ( pkg . compute_requiredby ( ) )
required & = set ( transaction . localpkgs . keys ( ) )
2013-04-07 09:16:23 -03:00
if required :
str_required = ' '
for item in required :
if str_required :
str_required + = ' , '
str_required + = item
if error :
error + = ' \n '
error + = _ ( ' {pkgname1} conflicts with {pkgname2} but cannot be removed because it is needed by {pkgname3} ' ) . format ( pkgname1 = found_conflict . name , pkgname2 = pkg . name , pkgname3 = str_required )
2013-04-17 09:41:10 -03:00
print ( _ ( ' {pkgname1} conflicts with {pkgname2} but cannot be removed because it is needed by {pkgname3} ' ) . format ( pkgname1 = found_conflict . name , pkgname2 = pkg . name , pkgname3 = str_required ) )
2013-04-07 09:16:23 -03:00
elif not found_conflict . name in transaction . to_remove :
2013-04-17 09:41:10 -03:00
transaction . to_remove . add ( found_conflict . name )
2013-04-07 09:16:23 -03:00
if warning :
warning + = ' \n '
warning + = _ ( ' {pkgname1} conflicts with {pkgname2} ' ) . format ( pkgname1 = pkg . name , pkgname2 = found_conflict . name )
2013-04-17 09:41:10 -03:00
print ( _ ( ' {pkgname1} conflicts with {pkgname2} ' ) . format ( pkgname1 = pkg . name , pkgname2 = found_conflict . name ) )
else :
# check if the conflict can be safely removed
required = set ( pkg . compute_requiredby ( ) )
required & = set ( transaction . localpkgs . keys ( ) )
if required :
str_required = ' '
for item in required :
if str_required :
str_required + = ' , '
str_required + = item
if error :
error + = ' \n '
error + = _ ( ' {pkgname1} conflicts with {pkgname2} but cannot be removed because it is needed by {pkgname3} ' ) . format ( pkgname1 = found_conflict . name , pkgname2 = pkg . name , pkgname3 = str_required )
print ( _ ( ' {pkgname1} conflicts with {pkgname2} but cannot be removed because it is needed by {pkgname3} ' ) . format ( pkgname1 = found_conflict . name , pkgname2 = pkg . name , pkgname3 = str_required ) )
elif not found_conflict . name in transaction . to_remove :
transaction . to_remove . add ( found_conflict . name )
if warning :
warning + = ' \n '
warning + = _ ( ' {pkgname1} conflicts with {pkgname2} ' ) . format ( pkgname1 = pkg . name , pkgname2 = found_conflict . name )
print ( _ ( ' {pkgname1} conflicts with {pkgname2} ' ) . format ( pkgname1 = pkg . name , pkgname2 = found_conflict . name ) )
# check if the pkg conflicts with the other ones to install
2013-04-07 09:16:23 -03:00
found_conflict = pyalpm . find_satisfier ( depends [ 0 ] , conflict )
if found_conflict :
2013-02-25 13:39:43 -03:00
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 :
2013-04-17 09:41:10 -03:00
transaction . to_add . discard ( common . format_pkg_name ( conflict ) )
transaction . to_add . discard ( pkg . name )
2013-02-25 13:39:43 -03:00
if warning :
2013-03-18 07:07:58 -03:00
warning + = ' \n '
2013-04-17 09:41:10 -03:00
warning + = _ ( ' {pkgname1} conflicts with {pkgname2} \n None of them will be installed ' ) . format ( pkgname1 = pkg . name , pkgname2 = common . format_pkg_name ( conflict ) )
print ( _ ( ' {pkgname1} conflicts with {pkgname2} \n None of them will be installed ' ) . format ( pkgname1 = pkg . name , pkgname2 = common . format_pkg_name ( conflict ) ) )
2013-02-06 12:09:43 -03:00
i + = 1
2013-04-17 09:41:10 -03:00
# end of the loop
# check if installed pkgs conflicts with the ones to install
to_check = [ transaction . syncpkgs [ name ] for name in transaction . to_add | transaction . to_update ]
2013-02-06 12:09:43 -03:00
for pkg in transaction . localpkgs . values ( ) :
for conflict in pkg . conflicts :
2013-04-17 09:41:10 -03:00
found_conflict = pyalpm . find_satisfier ( to_check , conflict )
2013-04-07 09:16:23 -03:00
if found_conflict :
if found_conflict . name != pkg . name :
2013-04-17 09:41:10 -03:00
# if pkg provides the conflict no need to check if it can be safely removed
2013-04-07 09:16:23 -03:00
will_provide_conflict = pyalpm . find_satisfier ( [ pkg ] , conflict )
if will_provide_conflict :
if not pkg . name in transaction . to_remove :
2013-04-17 09:41:10 -03:00
transaction . to_remove . add ( pkg . name )
2013-04-07 09:16:23 -03:00
if warning :
warning + = ' \n '
warning + = _ ( ' {pkgname1} conflicts with {pkgname2} ' ) . format ( pkgname1 = found_conflict . name , pkgname2 = pkg . name )
2013-04-17 09:41:10 -03:00
print ( _ ( ' {pkgname1} conflicts with {pkgname2} ' ) . format ( pkgname1 = found_conflict . name , pkgname2 = pkg . name ) )
2013-04-07 09:16:23 -03:00
else :
2013-04-17 09:41:10 -03:00
# if pkg will be updated, check the conflicts of this new one
if pkg . name in transaction . to_update :
for new_conflict in transaction . syncpkgs [ pkg . name ] . conflicts :
if new_conflict == conflict :
# check if the conflict can be safely removed
required = set ( pkg . compute_requiredby ( ) )
required & = set ( transaction . localpkgs . keys ( ) )
if required :
str_required = ' '
for item in required :
if str_required :
str_required + = ' , '
str_required + = item
if error :
error + = ' \n '
error + = _ ( ' {pkgname1} conflicts with {pkgname2} but cannot be removed because it is needed by {pkgname3} ' ) . format ( pkgname1 = pkg . name , pkgname2 = found_conflict . name , pkgname3 = str_required )
print ( _ ( ' {pkgname1} conflicts with {pkgname2} but cannot be removed because it is needed by {pkgname3} ' ) . format ( pkgname1 = pkg . name , pkgname2 = found_conflict . name , pkgname3 = str_required ) )
elif not pkg . name in transaction . to_remove :
transaction . to_remove . add ( pkg . name )
2013-03-18 07:07:58 -03:00
if warning :
warning + = ' \n '
2013-04-17 09:41:10 -03:00
warning + = _ ( ' {pkgname1} conflicts with {pkgname2} ' ) . format ( pkgname1 = found_conflict . name , pkgname2 = pkg . name )
print ( _ ( ' {pkgname1} conflicts with {pkgname2} ' ) . format ( pkgname1 = found_conflict . name , pkgname2 = pkg . name ) )
else :
# check if the conflict can be safely removed
required = set ( pkg . compute_requiredby ( ) )
required & = set ( transaction . localpkgs . keys ( ) )
if required :
str_required = ' '
for item in required :
if str_required :
str_required + = ' , '
str_required + = item
if error :
error + = ' \n '
error + = _ ( ' {pkgname1} conflicts with {pkgname2} but cannot be removed because it is needed by {pkgname3} ' ) . format ( pkgname1 = pkg . name , pkgname2 = found_conflict . name , pkgname3 = str_required )
print ( _ ( ' {pkgname1} conflicts with {pkgname2} but cannot be removed because it is needed by {pkgname3} ' ) . format ( pkgname1 = pkg . name , pkgname2 = found_conflict . name , pkgname3 = str_required ) )
elif not pkg . name in transaction . to_remove :
transaction . to_remove . add ( pkg . name )
if warning :
warning + = ' \n '
warning + = _ ( ' {pkgname1} conflicts with {pkgname2} ' ) . format ( pkgname1 = found_conflict . name , pkgname2 = pkg . name )
print ( _ ( ' {pkgname1} conflicts with {pkgname2} ' ) . format ( pkgname1 = found_conflict . name , pkgname2 = pkg . name ) )
# remove in to_remove the packages which are needed by the names in to_add to avoid conflicts:
wont_be_removed = set ( )
for pkg_list in depends :
for pkg in pkg_list :
wont_be_removed . add ( pkg . name )
ManagerWindow . get_root_window ( ) . set_cursor ( Gdk . Cursor ( Gdk . CursorType . ARROW ) )
print ( ' check result: ' )
print ( ' to add: ' , transaction . to_add if transaction . to_add else ' None ' )
print ( ' will not be removed: ' , transaction . to_remove & wont_be_removed if transaction . to_remove & wont_be_removed else ' None ' )
transaction . to_remove - = wont_be_removed
print ( ' to remove: ' , transaction . to_remove if transaction . to_remove else ' None ' )
print ( ' to update: ' , transaction . to_update if transaction . to_update else ' None ' )
2013-02-06 12:09:43 -03:00
if warning :
2013-04-10 11:20:54 -03:00
WarningDialog . format_secondary_text ( warning )
response = WarningDialog . run ( )
2013-02-06 12:09:43 -03:00
if response :
2013-04-10 11:20:54 -03:00
WarningDialog . hide ( )
2013-02-27 11:15:51 -03:00
if error :
2013-04-17 09:41:10 -03:00
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 :
2013-03-31 14:31:33 -03:00
choose_label . set_markup ( _ ( ' <b> {pkgname} is provided by {number} packages. \n Please choose the one(s) you want to install:</b> ' ) . format ( pkgname = name , number = str ( len ( provides . keys ( ) ) ) ) )
2013-02-06 12:09:43 -03:00
choose_list . clear ( )
for name in provides . keys ( ) :
if transaction . handle . get_localdb ( ) . get_pkg ( name ) :
choose_list . append ( [ True , name ] )
2013-01-30 14:37:41 -03:00
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 ) :
2013-04-17 09:41:10 -03:00
transaction . to_update . clear ( )
if transaction . to_add | transaction . to_remove :
check_conflicts ( )
if transaction . to_add | transaction . to_remove :
if transaction . init_transaction ( noconflicts = True ) :
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 ( )
transaction . to_update = transaction . to_add & set ( transaction . localpkgs . keys ( ) )
transaction . to_add - = transaction . to_update
set_transaction_sum ( )
ConfDialog . show_all ( )
2012-12-23 12:26:19 -03:00
else :
2013-04-17 09:41:10 -03:00
WarningDialog . format_secondary_text ( _ ( ' Nothing to do ' ) )
response = WarningDialog . run ( )
if response :
WarningDialog . hide ( )
refresh_packages_list ( )
2012-12-12 13:12:27 -03:00
2013-02-10 11:59:53 -03:00
def on_Manager_EraseButton_clicked ( self , * arg ) :
2013-04-17 09:41:10 -03:00
transaction . to_add . clear ( )
transaction . to_remove . clear ( )
transaction . to_update . clear ( )
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-03-01 15:11:55 -03:00
ProgressWindow . hide ( )
2012-12-31 11:41:51 -03:00
ConfDialog . hide ( )
2013-01-06 15:10:13 -03:00
transaction . Release ( )
2013-04-17 09:41:10 -03:00
refresh_packages_list ( )
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 ( )
2013-04-17 09:41:10 -03:00
if line :
if packages_list [ line ] [ 0 ] != _ ( ' No package found ' ) :
if transaction . localpkgs . __contains__ ( packages_list [ line ] [ 0 ] ) :
set_infos_list ( transaction . localpkgs [ packages_list [ line ] [ 0 ] ] )
set_deps_list ( transaction . localpkgs [ packages_list [ line ] [ 0 ] ] , " local " )
set_details_list ( transaction . localpkgs [ packages_list [ line ] [ 0 ] ] , " local " )
set_files_list ( transaction . localpkgs [ packages_list [ line ] [ 0 ] ] )
files_scrolledwindow . set_visible ( True )
else :
set_infos_list ( transaction . syncpkgs [ packages_list [ line ] [ 0 ] ] )
set_deps_list ( transaction . syncpkgs [ packages_list [ line ] [ 0 ] ] , " sync " )
set_details_list ( transaction . syncpkgs [ packages_list [ line ] [ 0 ] ] , " sync " )
files_scrolledwindow . set_visible ( False )
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 ( )
2013-04-17 09:41:10 -03:00
if line :
2013-03-25 13:51:20 -03:00
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 ( )
2013-04-17 09:41:10 -03:00
if line :
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 ( )
2013-04-17 09:41:10 -03:00
if line :
2013-03-31 14:31:33 -03:00
if state_list [ line ] [ 0 ] == _ ( ' Installed ' ) :
2013-03-25 13:51:20 -03:00
current_filter = ( ' installed ' , None )
2013-03-31 14:31:33 -03:00
if state_list [ line ] [ 0 ] == _ ( ' Uninstalled ' ) :
2013-03-25 13:51:20 -03:00
current_filter = ( ' uninstalled ' , None )
2013-03-31 14:31:33 -03:00
if state_list [ line ] [ 0 ] == _ ( ' Orphans ' ) :
2013-03-25 13:51:20 -03:00
current_filter = ( ' orphans ' , None )
2013-03-31 14:31:33 -03:00
if state_list [ line ] [ 0 ] == _ ( ' To install ' ) :
2013-03-25 13:51:20 -03:00
current_filter = ( ' to_install ' , None )
2013-03-31 14:31:33 -03:00
if state_list [ line ] [ 0 ] == _ ( ' To remove ' ) :
2013-03-25 13:51:20 -03:00
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 ( )
2013-04-17 09:41:10 -03:00
if line :
2013-03-31 14:31:33 -03:00
if repos_list [ line ] [ 0 ] == _ ( ' local ' ) :
2013-03-25 13:51:20 -03:00
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 ) :
2013-04-17 09:41:10 -03:00
if packages_list [ line ] [ 1 ] is True :
if packages_list [ line ] [ 0 ] in transaction . to_remove :
packages_list [ line ] [ 3 ] = True
2013-03-25 13:51:20 -03:00
packages_list [ line ] [ 4 ] = installed_icon
2013-04-17 09:41:10 -03:00
transaction . to_remove . discard ( packages_list [ line ] [ 0 ] )
else :
packages_list [ line ] [ 3 ] = False
2013-03-25 13:51:20 -03:00
packages_list [ line ] [ 4 ] = to_remove_icon
2013-04-17 09:41:10 -03:00
transaction . to_remove . add ( packages_list [ line ] [ 0 ] )
if packages_list [ line ] [ 1 ] is False :
if packages_list [ line ] [ 0 ] in transaction . to_add :
packages_list [ line ] [ 3 ] = False
packages_list [ line ] [ 4 ] = uninstalled_icon
transaction . to_add . discard ( packages_list [ line ] [ 0 ] )
else :
packages_list [ line ] [ 3 ] = True
2013-03-25 13:51:20 -03:00
packages_list [ line ] [ 4 ] = to_install_icon
2013-04-17 09:41:10 -03:00
transaction . to_add . add ( packages_list [ line ] [ 0 ] )
2012-12-12 13:12:27 -03:00
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-04-17 09:41:10 -03:00
transaction . to_provide . clear ( )
2013-01-27 14:15:34 -03:00
while line < len ( choose_list ) :
if choose_list [ line ] [ 0 ] is True :
2013-04-17 09:41:10 -03:00
if not choose_list [ line ] [ 1 ] in transaction . localpkgs . keys ( ) :
transaction . to_provide . add ( choose_list [ line ] [ 1 ] )
2013-01-30 14:37:41 -03:00
if choose_list [ line ] [ 0 ] is False :
2013-04-17 09:41:10 -03:00
transaction . to_provide . discard ( choose_list [ line ] [ 1 ] )
2013-01-27 14:15:34 -03:00
line + = 1
2013-04-17 09:41:10 -03:00
def on_ProgressCancelButton_clicked ( self , * arg ) :
print ( ' cancelled ' )
if not _ ( ' Refreshing ' ) in progress_label . get_text ( ) :
error = transaction . Interrupt ( )
if error :
handle_error ( error )
else :
handle_reply ( ' ' )
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-01-06 15:10:13 -03:00
2013-02-10 11:59:53 -03:00
def main ( _mode ) :
if common . pid_file_exists ( ) :
2013-04-10 11:20:54 -03:00
ErrorDialog . format_secondary_text ( _ ( ' Pamac is already running ' ) )
response = ErrorDialog . run ( )
2013-02-10 11:59:53 -03:00
if response :
2013-04-10 11:20:54 -03:00
ErrorDialog . hide ( )
2013-02-10 11:59:53 -03:00
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-31 14:31:33 -03:00
update_top_label . set_markup ( _ ( ' <big><b>Your system is up-to-date</b></big> ' ) )
2013-03-26 07:02:17 -03:00
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 ( )