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
|
2013-02-06 12:09:43 -03:00
|
|
|
from collections import OrderedDict
|
2013-01-06 15:10:13 -03:00
|
|
|
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
|
|
|
|
2013-02-10 11:59:53 -03:00
|
|
|
t_lock = False
|
|
|
|
to_remove = []
|
|
|
|
to_add = []
|
|
|
|
to_provide = []
|
|
|
|
to_update = []
|
|
|
|
handle = None
|
|
|
|
syncpkgs = OrderedDict()
|
|
|
|
localpkgs = OrderedDict()
|
|
|
|
|
2013-01-20 13:38:33 -03:00
|
|
|
interface = Gtk.Builder()
|
|
|
|
|
2013-02-10 11:59:53 -03:00
|
|
|
interface.add_from_file('/usr/share/pamac/gui/dialogs.glade')
|
2013-01-20 13:38:33 -03:00
|
|
|
ErrorDialog = interface.get_object('ErrorDialog')
|
|
|
|
WarningDialog = interface.get_object('WarningDialog')
|
2013-03-15 13:15:34 -03:00
|
|
|
#QuestionDialog = interface.get_object('QuestionDialog')
|
|
|
|
InfoDialog = interface.get_object('InfoDialog')
|
2013-01-06 15:10:13 -03:00
|
|
|
|
2013-01-23 11:12:11 -03:00
|
|
|
def get_handle():
|
|
|
|
global handle
|
2013-03-25 13:51:20 -03:00
|
|
|
handle = config.handle()
|
2013-02-22 12:43:52 -03:00
|
|
|
print('get handle')
|
|
|
|
|
|
|
|
def update_db():
|
|
|
|
get_handle()
|
2013-02-06 12:09:43 -03:00
|
|
|
global syncpkgs
|
|
|
|
global localpkgs
|
|
|
|
syncpkgs = OrderedDict()
|
|
|
|
localpkgs = OrderedDict()
|
|
|
|
for repo in handle.get_syncdbs():
|
|
|
|
for pkg in repo.pkgcache:
|
|
|
|
if not pkg.name in syncpkgs.keys():
|
|
|
|
syncpkgs[pkg.name] = pkg
|
|
|
|
for pkg in handle.get_localdb().pkgcache:
|
|
|
|
if not pkg.name in localpkgs.keys():
|
|
|
|
localpkgs[pkg.name] = pkg
|
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')
|
2013-03-15 13:15:34 -03:00
|
|
|
Interrupt = proxy.get_dbus_method('Interrupt','org.manjaro.pamac')
|
2013-01-06 15:10:13 -03:00
|
|
|
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
|
|
|
|
|
|
|
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 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 get_updates():
|
|
|
|
"""Return a list of package objects in local db which can be updated"""
|
2013-02-06 12:09:43 -03:00
|
|
|
do_syncfirst = False
|
|
|
|
list_first = []
|
2013-02-22 12:43:52 -03:00
|
|
|
#update_db()
|
2013-01-06 15:10:13 -03:00
|
|
|
if config.syncfirst:
|
|
|
|
for name in config.syncfirst:
|
2013-02-22 12:43:52 -03:00
|
|
|
if name in localpkgs.keys():
|
|
|
|
candidate = pyalpm.sync_newversion(localpkgs[name], handle.get_syncdbs())
|
2013-02-03 11:58:33 -03:00
|
|
|
if candidate:
|
2013-03-01 15:11:55 -03:00
|
|
|
list_first.append(candidate)
|
2013-01-06 15:10:13 -03:00
|
|
|
if list_first:
|
|
|
|
do_syncfirst = True
|
2013-02-06 12:09:43 -03:00
|
|
|
return do_syncfirst, list_first
|
2013-01-06 15:10:13 -03:00
|
|
|
result = []
|
2013-02-23 13:02:53 -03:00
|
|
|
for pkg in localpkgs.values():
|
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:
|
2013-03-01 15:11:55 -03:00
|
|
|
result.append(candidate)
|
2013-02-06 12:09:43 -03:00
|
|
|
return do_syncfirst, result
|