2013-01-06 15:10:13 -03:00
|
|
|
#! /usr/bin/python
|
|
|
|
# -*-coding:utf-8-*-
|
|
|
|
|
2013-01-26 10:42:01 -03:00
|
|
|
from gi.repository import Gtk
|
2013-01-06 15:10:13 -03:00
|
|
|
|
|
|
|
import pyalpm
|
|
|
|
import dbus
|
2013-01-20 13:38:33 -03:00
|
|
|
from dbus.mainloop.glib import DBusGMainLoop
|
2013-01-06 15:10:13 -03:00
|
|
|
|
2013-01-30 14:37:41 -03:00
|
|
|
from pamac import config, common
|
2013-01-20 13:38:33 -03:00
|
|
|
|
|
|
|
interface = Gtk.Builder()
|
|
|
|
interface.add_from_file('/usr/share/pamac/gui/dialogs.glade')
|
|
|
|
|
|
|
|
ErrorDialog = interface.get_object('ErrorDialog')
|
|
|
|
WarningDialog = interface.get_object('WarningDialog')
|
2013-01-26 10:42:01 -03:00
|
|
|
QuestionDialog = interface.get_object('QuestionDialog')
|
2013-01-20 13:38:33 -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')
|
2013-01-23 11:12:11 -03:00
|
|
|
ProgressCancelButton = interface.get_object('ProgressCancelButton')
|
2013-01-06 15:10:13 -03:00
|
|
|
|
|
|
|
t_lock = False
|
|
|
|
do_syncfirst = False
|
|
|
|
list_first = []
|
2013-01-20 13:38:33 -03:00
|
|
|
to_remove = []
|
|
|
|
to_add = []
|
|
|
|
to_update = []
|
2013-01-23 11:12:11 -03:00
|
|
|
handle = None
|
|
|
|
|
|
|
|
def get_handle():
|
|
|
|
global handle
|
|
|
|
handle = config.pacman_conf.initialize_alpm()
|
2013-01-06 15:10:13 -03:00
|
|
|
|
2013-01-20 13:38:33 -03:00
|
|
|
DBusGMainLoop(set_as_default=True)
|
|
|
|
bus = dbus.SystemBus()
|
|
|
|
proxy = bus.get_object('org.manjaro.pamac','/org/manjaro/pamac', introspect=False)
|
|
|
|
Refresh = proxy.get_dbus_method('Refresh','org.manjaro.pamac')
|
2013-01-06 15:10:13 -03:00
|
|
|
Init = proxy.get_dbus_method('Init','org.manjaro.pamac')
|
2013-01-20 13:38:33 -03:00
|
|
|
Sysupgrade = proxy.get_dbus_method('Sysupgrade','org.manjaro.pamac')
|
2013-01-06 15:10:13 -03:00
|
|
|
Remove = proxy.get_dbus_method('Remove','org.manjaro.pamac')
|
|
|
|
Add = proxy.get_dbus_method('Add','org.manjaro.pamac')
|
|
|
|
Prepare = proxy.get_dbus_method('Prepare','org.manjaro.pamac')
|
|
|
|
To_Remove = proxy.get_dbus_method('To_Remove','org.manjaro.pamac')
|
|
|
|
To_Add = proxy.get_dbus_method('To_Add','org.manjaro.pamac')
|
|
|
|
Commit = proxy.get_dbus_method('Commit','org.manjaro.pamac')
|
|
|
|
Release = proxy.get_dbus_method('Release','org.manjaro.pamac')
|
2013-01-23 11:12:11 -03:00
|
|
|
StopDaemon = proxy.get_dbus_method('StopDaemon','org.manjaro.pamac')
|
2013-01-06 15:10:13 -03:00
|
|
|
|
2013-01-20 13:38:33 -03:00
|
|
|
def action_signal_handler(action):
|
|
|
|
progress_label.set_text(action)
|
2013-01-23 11:12:11 -03:00
|
|
|
#~ if 'Downloading' in action:
|
|
|
|
#~ print('cancel enabled')
|
|
|
|
#~ ProgressCancelButton.set_visible(True)
|
|
|
|
#~ else:
|
|
|
|
ProgressCancelButton.set_visible(False)
|
|
|
|
#~ print('cancel disabled')
|
2013-01-20 13:38:33 -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-01-26 10:42:01 -03:00
|
|
|
#~ if percent == '0':
|
|
|
|
#~ progress_bar.pulse()
|
|
|
|
#~ else:
|
|
|
|
progress_bar.set_fraction(float(percent))
|
2013-01-20 13:38:33 -03:00
|
|
|
|
|
|
|
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-01-06 15:10:13 -03:00
|
|
|
def init_transaction(**options):
|
|
|
|
"Transaction initialization"
|
|
|
|
global t_lock
|
2013-01-23 11:12:11 -03:00
|
|
|
error = Init(dbus.Dictionary(options, signature='sb'))
|
2013-01-06 15:10:13 -03:00
|
|
|
if not error:
|
|
|
|
t_lock = True
|
|
|
|
return True
|
|
|
|
else:
|
2013-01-26 10:42:01 -03:00
|
|
|
ErrorDialog.format_secondary_text('Init Error:\n'+str(error))
|
2013-01-20 13:38:33 -03:00
|
|
|
response = ErrorDialog.run()
|
2013-01-06 15:10:13 -03:00
|
|
|
if response:
|
2013-01-20 13:38:33 -03:00
|
|
|
ErrorDialog.hide()
|
2013-01-06 15:10:13 -03:00
|
|
|
return False
|
|
|
|
|
|
|
|
def check_conflicts():
|
2013-01-20 13:38:33 -03:00
|
|
|
global to_add
|
|
|
|
global to_remove
|
2013-01-06 15:10:13 -03:00
|
|
|
to_check = []
|
2013-01-26 12:10:11 -03:00
|
|
|
installed_pkg_name = []
|
|
|
|
syncdbs_pkg_name = []
|
2013-01-06 15:10:13 -03:00
|
|
|
warning = ''
|
2013-01-20 13:38:33 -03:00
|
|
|
for pkgname in to_add:
|
2013-01-23 11:12:11 -03:00
|
|
|
for repo in handle.get_syncdbs():
|
2013-01-06 15:10:13 -03:00
|
|
|
pkg = repo.get_pkg(pkgname)
|
|
|
|
if pkg:
|
|
|
|
to_check.append(pkg)
|
|
|
|
break
|
2013-01-26 12:10:11 -03:00
|
|
|
for installed_pkg in handle.get_localdb().pkgcache:
|
|
|
|
installed_pkg_name.append(installed_pkg.name)
|
2013-01-06 15:10:13 -03:00
|
|
|
for target in to_check:
|
2013-01-26 12:59:29 -03:00
|
|
|
for name in target.replaces:
|
2013-02-02 10:02:18 -03:00
|
|
|
if name in installed_pkg_name:
|
|
|
|
if not name in to_remove:
|
|
|
|
to_remove.append(name)
|
2013-01-26 10:42:01 -03:00
|
|
|
if warning:
|
|
|
|
warning = warning+'\n'
|
2013-01-26 12:59:29 -03:00
|
|
|
warning = warning+name+' will be replaced by '+target.name
|
|
|
|
for name in target.conflicts:
|
2013-02-01 10:50:15 -03:00
|
|
|
#if common.format_pkg_name(name) in to_add:
|
|
|
|
if name in to_add:
|
|
|
|
#to_add.remove(common.format_pkg_name(name))
|
|
|
|
to_add.remove(name)
|
2013-01-26 12:59:29 -03:00
|
|
|
to_add.remove(target.name)
|
|
|
|
if warning:
|
|
|
|
warning = warning+'\n'
|
|
|
|
warning = warning+name+' conflicts with '+target.name+'\nNone of them will be installed'
|
2013-02-02 10:02:18 -03:00
|
|
|
if name in installed_pkg_name:
|
|
|
|
if not name in to_remove:
|
|
|
|
to_remove.append(name)
|
2013-01-26 12:59:29 -03:00
|
|
|
if warning:
|
|
|
|
warning = warning+'\n'
|
|
|
|
warning = warning+name+' conflicts with '+target.name
|
2013-01-23 11:12:11 -03:00
|
|
|
for installed_pkg in handle.get_localdb().pkgcache:
|
2013-01-27 14:15:34 -03:00
|
|
|
for name in installed_pkg.conflicts:
|
2013-02-02 10:02:18 -03:00
|
|
|
if name == target.name:
|
|
|
|
if not name in to_remove:
|
2013-01-27 14:15:34 -03:00
|
|
|
to_remove.append(installed_pkg.name)
|
|
|
|
if warning:
|
|
|
|
warning = warning+'\n'
|
|
|
|
warning = warning+installed_pkg.name+' conflicts with '+target.name
|
2013-01-23 12:51:27 -03:00
|
|
|
for repo in handle.get_syncdbs():
|
|
|
|
for pkg in repo.pkgcache:
|
2013-01-26 12:59:29 -03:00
|
|
|
for name in pkg.replaces:
|
2013-02-02 10:02:18 -03:00
|
|
|
if name in installed_pkg_name:
|
|
|
|
if not name in to_remove:
|
|
|
|
to_remove.append(name)
|
2013-01-26 12:59:29 -03:00
|
|
|
if warning:
|
|
|
|
warning = warning+'\n'
|
2013-02-02 10:02:18 -03:00
|
|
|
warning = warning+name+' will be replaced by '+pkg.name
|
2013-01-26 12:59:29 -03:00
|
|
|
if not pkg.name in to_add:
|
|
|
|
to_add.append(pkg.name)
|
2013-01-06 15:10:13 -03:00
|
|
|
if warning:
|
2013-01-20 13:38:33 -03:00
|
|
|
WarningDialog.format_secondary_text(warning)
|
|
|
|
response = WarningDialog.run()
|
2013-01-06 15:10:13 -03:00
|
|
|
if response:
|
2013-01-20 13:38:33 -03:00
|
|
|
WarningDialog.hide()
|
2013-01-06 15:10:13 -03:00
|
|
|
|
|
|
|
def get_to_remove():
|
2013-01-20 13:38:33 -03:00
|
|
|
global to_remove
|
|
|
|
to_remove = To_Remove()
|
2013-01-06 15:10:13 -03:00
|
|
|
|
|
|
|
def get_to_add():
|
2013-01-20 13:38:33 -03:00
|
|
|
global to_add
|
|
|
|
to_add = To_Add()
|
2013-01-06 15:10:13 -03:00
|
|
|
|
|
|
|
def do_refresh():
|
|
|
|
"""Sync databases like pacman -Sy"""
|
|
|
|
global t_lock
|
2013-01-26 10:42:01 -03:00
|
|
|
get_handle()
|
2013-01-20 13:38:33 -03:00
|
|
|
if t_lock is False:
|
|
|
|
t_lock = True
|
2013-01-26 10:42:01 -03:00
|
|
|
progress_label.set_text('Refreshing...')
|
|
|
|
action_icon.set_from_file('/usr/share/pamac/icons/24x24/status/refresh-cache.png')
|
2013-01-23 11:12:11 -03:00
|
|
|
ProgressWindow.show_all()
|
2013-01-26 10:42:01 -03:00
|
|
|
while Gtk.events_pending():
|
|
|
|
Gtk.main_iteration()
|
|
|
|
Refresh(reply_handler = handle_reply, error_handler = handle_error, timeout = 2000*1000)
|
|
|
|
|
|
|
|
def handle_error(error):
|
|
|
|
global t_lock
|
|
|
|
if not 'DBus.Error.NoReply' in str(error):
|
|
|
|
transaction.ErrorDialog.format_secondary_text('Refresh Error:\n'+str(error))
|
|
|
|
response = transaction.ErrorDialog.run()
|
|
|
|
if response:
|
|
|
|
transaction.ErrorDialog.hide()
|
|
|
|
t_lock = False
|
|
|
|
Release()
|
|
|
|
ProgressWindow.hide()
|
|
|
|
|
|
|
|
def handle_reply(reply):
|
|
|
|
global t_lock
|
|
|
|
t_lock = False
|
2013-02-01 10:50:15 -03:00
|
|
|
Release()
|
2013-01-26 10:42:01 -03:00
|
|
|
ProgressWindow.hide()
|
2013-01-06 15:10:13 -03:00
|
|
|
|
|
|
|
def get_updates():
|
|
|
|
"""Return a list of package objects in local db which can be updated"""
|
|
|
|
global do_syncfirst
|
|
|
|
global list_first
|
2013-01-23 11:12:11 -03:00
|
|
|
get_handle()
|
2013-01-06 15:10:13 -03:00
|
|
|
if config.syncfirst:
|
|
|
|
for name in config.syncfirst:
|
2013-01-23 11:12:11 -03:00
|
|
|
pkg = handle.get_localdb().get_pkg(name)
|
|
|
|
candidate = pyalpm.sync_newversion(pkg, handle.get_syncdbs())
|
2013-01-06 15:10:13 -03:00
|
|
|
if candidate:
|
|
|
|
list_first.append(candidate)
|
|
|
|
if list_first:
|
|
|
|
do_syncfirst = True
|
|
|
|
return list_first
|
|
|
|
result = []
|
2013-01-23 11:12:11 -03:00
|
|
|
installed_pkglist = handle.get_localdb().pkgcache
|
2013-01-06 15:10:13 -03:00
|
|
|
for pkg in installed_pkglist:
|
2013-01-23 11:12:11 -03:00
|
|
|
candidate = pyalpm.sync_newversion(pkg, handle.get_syncdbs())
|
2013-01-06 15:10:13 -03:00
|
|
|
if candidate:
|
|
|
|
result.append(candidate)
|
|
|
|
return result
|
|
|
|
|
|
|
|
def get_new_version_available(pkgname):
|
2013-01-23 11:12:11 -03:00
|
|
|
for repo in handle.get_syncdbs():
|
2013-01-06 15:10:13 -03:00
|
|
|
pkg = repo.get_pkg(pkgname)
|
|
|
|
if pkg is not None:
|
|
|
|
return pkg.version
|
|
|
|
break
|