|
|
|
@ -4,84 +4,96 @@
|
|
|
|
import dbus
|
|
|
|
import dbus
|
|
|
|
import dbus.service
|
|
|
|
import dbus.service
|
|
|
|
from dbus.mainloop.glib import DBusGMainLoop
|
|
|
|
from dbus.mainloop.glib import DBusGMainLoop
|
|
|
|
from gi.repository import GObject, Gtk
|
|
|
|
from gi.repository import GObject
|
|
|
|
|
|
|
|
|
|
|
|
import pyalpm
|
|
|
|
import pyalpm
|
|
|
|
import traceback
|
|
|
|
import traceback
|
|
|
|
from pamac import config, common
|
|
|
|
from pamac import config, common
|
|
|
|
|
|
|
|
|
|
|
|
loop = GObject.MainLoop()
|
|
|
|
class PamacDBusService(dbus.service.Object):
|
|
|
|
|
|
|
|
def __init__(self):
|
|
|
|
|
|
|
|
bus=dbus.SystemBus()
|
|
|
|
|
|
|
|
bus_name = dbus.service.BusName('org.manjaro.pamac', bus)
|
|
|
|
|
|
|
|
dbus.service.Object.__init__(self, bus_name, '/org/manjaro/pamac')
|
|
|
|
|
|
|
|
self.t = None
|
|
|
|
|
|
|
|
self.error = ''
|
|
|
|
|
|
|
|
self.warning = ''
|
|
|
|
|
|
|
|
self.action = ''
|
|
|
|
|
|
|
|
self.icon = ''
|
|
|
|
|
|
|
|
self.target = ''
|
|
|
|
|
|
|
|
self.percent = 0
|
|
|
|
|
|
|
|
self.total_size = 0
|
|
|
|
|
|
|
|
self.already_transferred = 0
|
|
|
|
|
|
|
|
|
|
|
|
t = None
|
|
|
|
@dbus.service.signal('org.manjaro.pamac')
|
|
|
|
error = ''
|
|
|
|
def EmitAction(self, action):
|
|
|
|
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
|
interface = Gtk.Builder()
|
|
|
|
@dbus.service.signal('org.manjaro.pamac')
|
|
|
|
interface.add_from_file('/usr/share/pamac/gui/dialogs.glade')
|
|
|
|
def EmitIcon(self, icon):
|
|
|
|
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
|
ProgressWindow = interface.get_object('ProgressWindow')
|
|
|
|
@dbus.service.signal('org.manjaro.pamac')
|
|
|
|
progress_bar = interface.get_object('progressbar2')
|
|
|
|
def EmitTarget(self, target):
|
|
|
|
progress_label = interface.get_object('progresslabel2')
|
|
|
|
pass
|
|
|
|
action_icon = interface.get_object('action_icon')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def cb_event(ID, event, tupel):
|
|
|
|
@dbus.service.signal('org.manjaro.pamac')
|
|
|
|
while Gtk.events_pending():
|
|
|
|
def EmitPercent(self, percent):
|
|
|
|
Gtk.main_iteration()
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def cb_event(self, ID, event, tupel):
|
|
|
|
if ID is 1:
|
|
|
|
if ID is 1:
|
|
|
|
progress_label.set_text('Checking dependencies')
|
|
|
|
self.action = 'Checking dependencies'
|
|
|
|
action_icon.set_from_file('/usr/share/pamac/icons/24x24/status/package-search.png')
|
|
|
|
self.icon = '/usr/share/pamac/icons/24x24/status/package-search.png'
|
|
|
|
elif ID is 3:
|
|
|
|
elif ID is 3:
|
|
|
|
progress_label.set_text('Checking file conflicts')
|
|
|
|
self.action = 'Checking file conflicts'
|
|
|
|
action_icon.set_from_file('/usr/share/pamac/icons/24x24/status/package-search.png')
|
|
|
|
self.icon = '/usr/share/pamac/icons/24x24/status/package-search.png'
|
|
|
|
elif ID is 5:
|
|
|
|
elif ID is 5:
|
|
|
|
progress_label.set_text('Resolving dependencies')
|
|
|
|
self.action = 'Resolving dependencies'
|
|
|
|
action_icon.set_from_file('/usr/share/pamac/icons/24x24/status/setup.png')
|
|
|
|
self.icon = '/usr/share/pamac/icons/24x24/status/setup.png'
|
|
|
|
elif ID is 7:
|
|
|
|
elif ID is 7:
|
|
|
|
progress_label.set_text('Checking inter conflicts')
|
|
|
|
self.action = 'Checking inter conflicts'
|
|
|
|
action_icon.set_from_file('/usr/share/pamac/icons/24x24/status/package-search.png')
|
|
|
|
self.icon = '/usr/share/pamac/icons/24x24/status/package-search.png'
|
|
|
|
elif ID is 9:
|
|
|
|
elif ID is 9:
|
|
|
|
progress_label.set_text('Installing packages')
|
|
|
|
self.action = 'Installing packages'
|
|
|
|
action_icon.set_from_file('/usr/share/pamac/icons/24x24/status/package-add.png')
|
|
|
|
self.icon = '/usr/share/pamac/icons/24x24/status/package-add.png'
|
|
|
|
elif ID is 11:
|
|
|
|
elif ID is 11:
|
|
|
|
progress_label.set_text('Removing packages')
|
|
|
|
self.action = 'Removing packages'
|
|
|
|
action_icon.set_from_file('/usr/share/pamac/icons/24x24/status/package-delete.png')
|
|
|
|
self.icon = '/usr/share/pamac/icons/24x24/status/package-delete.png'
|
|
|
|
elif ID is 13:
|
|
|
|
elif ID is 13:
|
|
|
|
progress_label.set_text('Upgrading packages')
|
|
|
|
self.action = 'Upgrading packages'
|
|
|
|
action_icon.set_from_file('/usr/share/pamac/icons/24x24/status/package-update.png')
|
|
|
|
self.icon = '/usr/share/pamac/icons/24x24/status/package-update.png'
|
|
|
|
elif ID is 15:
|
|
|
|
elif ID is 15:
|
|
|
|
progress_label.set_text('Checking integrity')
|
|
|
|
self.action = 'Checking integrity'
|
|
|
|
action_icon.set_from_file('/usr/share/pamac/icons/24x24/status/package-search.png')
|
|
|
|
self.icon = '/usr/share/pamac/icons/24x24/status/package-search.png'
|
|
|
|
|
|
|
|
self.already_transferred = 0
|
|
|
|
elif ID is 17:
|
|
|
|
elif ID is 17:
|
|
|
|
progress_label.set_text('Checking signatures')
|
|
|
|
self.action = 'Checking signatures'
|
|
|
|
action_icon.set_from_file('/usr/share/pamac/icons/24x24/status/package-search.png')
|
|
|
|
self.icon = '/usr/share/pamac/icons/24x24/status/package-search.png'
|
|
|
|
print('Checking signatures')
|
|
|
|
print('Checking signatures')
|
|
|
|
elif ID is 27:
|
|
|
|
elif ID is 27:
|
|
|
|
print('Downloading a file')
|
|
|
|
print('Downloading a file')
|
|
|
|
else :
|
|
|
|
else :
|
|
|
|
progress_label.set_text('')
|
|
|
|
self.action = ''
|
|
|
|
progress_bar.set_fraction(0.0)
|
|
|
|
self.EmitTarget('')
|
|
|
|
progress_bar.set_text('')
|
|
|
|
self.EmitPercent(str(0))
|
|
|
|
|
|
|
|
self.EmitAction(self.action)
|
|
|
|
|
|
|
|
self.EmitIcon(self.icon)
|
|
|
|
print(ID,event)
|
|
|
|
print(ID,event)
|
|
|
|
|
|
|
|
|
|
|
|
def cb_conv(*args):
|
|
|
|
def cb_conv(self, *args):
|
|
|
|
print("conversation", args)
|
|
|
|
print("conversation", args)
|
|
|
|
|
|
|
|
|
|
|
|
_logmask = pyalpm.LOG_ERROR | pyalpm.LOG_WARNING
|
|
|
|
def cb_log(self, level, line):
|
|
|
|
|
|
|
|
|
|
|
|
def cb_log(level, line):
|
|
|
|
|
|
|
|
#global t
|
|
|
|
#global t
|
|
|
|
|
|
|
|
_logmask = pyalpm.LOG_ERROR | pyalpm.LOG_WARNING
|
|
|
|
if not (level & _logmask):
|
|
|
|
if not (level & _logmask):
|
|
|
|
return
|
|
|
|
return
|
|
|
|
if level & pyalpm.LOG_ERROR:
|
|
|
|
if level & pyalpm.LOG_ERROR:
|
|
|
|
common.ErrorDialog.format_secondary_text("ERROR: "+line)
|
|
|
|
self.error = "ERROR: "+line
|
|
|
|
response = common.ErrorDialog.run()
|
|
|
|
|
|
|
|
if response:
|
|
|
|
|
|
|
|
common.ErrorDialog.hide()
|
|
|
|
|
|
|
|
#t.release()
|
|
|
|
#t.release()
|
|
|
|
elif level & pyalpm.LOG_WARNING:
|
|
|
|
elif level & pyalpm.LOG_WARNING:
|
|
|
|
common.WarningDialog.format_secondary_text("WARNING: "+line)
|
|
|
|
self.warning = "WARNING: "+line
|
|
|
|
response = common.WarningDialog.run()
|
|
|
|
|
|
|
|
if response:
|
|
|
|
|
|
|
|
common.WarningDialog.hide()
|
|
|
|
|
|
|
|
elif level & pyalpm.LOG_DEBUG:
|
|
|
|
elif level & pyalpm.LOG_DEBUG:
|
|
|
|
line = "DEBUG: " + line
|
|
|
|
line = "DEBUG: " + line
|
|
|
|
print(line)
|
|
|
|
print(line)
|
|
|
|
@ -89,48 +101,38 @@ def cb_log(level, line):
|
|
|
|
line = "FUNC: " + line
|
|
|
|
line = "FUNC: " + line
|
|
|
|
print(line)
|
|
|
|
print(line)
|
|
|
|
|
|
|
|
|
|
|
|
total_size = 0
|
|
|
|
def totaldlcb(self, _total_size):
|
|
|
|
def totaldlcb(_total_size):
|
|
|
|
self.total_size = _total_size
|
|
|
|
global total_size
|
|
|
|
|
|
|
|
total_size = _total_size
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
already_transferred = 0
|
|
|
|
def cb_dl(self, _target, _transferred, total):
|
|
|
|
def cb_dl(_target, _transferred, total):
|
|
|
|
if self.total_size > 0:
|
|
|
|
global already_transferred
|
|
|
|
fraction = (_transferred+self.already_transferred)/self.total_size
|
|
|
|
while Gtk.events_pending():
|
|
|
|
|
|
|
|
Gtk.main_iteration()
|
|
|
|
|
|
|
|
if total_size > 0:
|
|
|
|
|
|
|
|
fraction = (_transferred+already_transferred)/total_size
|
|
|
|
|
|
|
|
size = 0
|
|
|
|
size = 0
|
|
|
|
if (t.to_remove or t.to_add):
|
|
|
|
if (t.to_remove or t.to_add):
|
|
|
|
for pkg in t.to_remove+t.to_add:
|
|
|
|
for pkg in t.to_remove+t.to_add:
|
|
|
|
if pkg.name+'-'+pkg.version in _target:
|
|
|
|
if pkg.name+'-'+pkg.version in _target:
|
|
|
|
size = pkg.size
|
|
|
|
size = pkg.size
|
|
|
|
if _transferred == size:
|
|
|
|
if _transferred == size:
|
|
|
|
already_transferred += size
|
|
|
|
self.already_transferred += size
|
|
|
|
progress_label.set_text('Downloading '+common.format_size(total_size))
|
|
|
|
self.action = 'Downloading '+common.format_size(self.total_size)
|
|
|
|
progress_bar.set_text(_target)
|
|
|
|
self.target = _target
|
|
|
|
progress_bar.set_fraction(fraction)
|
|
|
|
self.percent = fraction
|
|
|
|
action_icon.set_from_file('/usr/share/pamac/icons/24x24/status/package-download.png')
|
|
|
|
self.icon = '/usr/share/pamac/icons/24x24/status/package-download.png'
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
progress_label.set_text('Refreshing...')
|
|
|
|
self.action = 'Refreshing...'
|
|
|
|
progress_bar.set_text(_target)
|
|
|
|
self.target = _target
|
|
|
|
progress_bar.pulse()
|
|
|
|
self.percent = 0
|
|
|
|
action_icon.set_from_file('/usr/share/pamac/icons/24x24/status/refresh-cache.png')
|
|
|
|
self.icon = '/usr/share/pamac/icons/24x24/status/refresh-cache.png'
|
|
|
|
|
|
|
|
self.EmitAction(self.action)
|
|
|
|
def cb_progress(_target, _percent, n, i):
|
|
|
|
self.EmitIcon(self.icon)
|
|
|
|
while Gtk.events_pending():
|
|
|
|
self.EmitTarget(self.target)
|
|
|
|
Gtk.main_iteration()
|
|
|
|
self.EmitPercent(str(self.percent))
|
|
|
|
target = _target+' ('+str(i)+'/'+str(n)+')'
|
|
|
|
|
|
|
|
progress_bar.set_fraction(_percent/100)
|
|
|
|
|
|
|
|
progress_bar.set_text(target)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def cb_progress(self, _target, _percent, n, i):
|
|
|
|
class PamacDBusService(dbus.service.Object):
|
|
|
|
self.target = _target+' ('+str(i)+'/'+str(n)+')'
|
|
|
|
def __init__(self):
|
|
|
|
self.percent = _percent/100
|
|
|
|
bus=dbus.SystemBus()
|
|
|
|
self.EmitTarget(self.target)
|
|
|
|
bus_name = dbus.service.BusName('org.manjaro.pamac', bus)
|
|
|
|
self.EmitPercent(str(self.percent))
|
|
|
|
dbus.service.Object.__init__(self, bus_name, '/org/manjaro/pamac')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def policykit_test(self, sender,connexion, action):
|
|
|
|
def policykit_test(self, sender,connexion, action):
|
|
|
|
bus = dbus.SystemBus()
|
|
|
|
bus = dbus.SystemBus()
|
|
|
|
@ -145,18 +147,40 @@ class PamacDBusService(dbus.service.Object):
|
|
|
|
(is_authorized,is_challenge,details) = policykit_authority.CheckAuthorization(Subject, action, {'': ''}, dbus.UInt32(1), '')
|
|
|
|
(is_authorized,is_challenge,details) = policykit_authority.CheckAuthorization(Subject, action, {'': ''}, dbus.UInt32(1), '')
|
|
|
|
return is_authorized
|
|
|
|
return is_authorized
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@dbus.service.method('org.manjaro.pamac', '', 's')
|
|
|
|
|
|
|
|
def Refresh(self):
|
|
|
|
|
|
|
|
global t
|
|
|
|
|
|
|
|
global error
|
|
|
|
|
|
|
|
error = ''
|
|
|
|
|
|
|
|
config.handle.dlcb = self.cb_dl
|
|
|
|
|
|
|
|
config.handle.totaldlcb = self.totaldlcb
|
|
|
|
|
|
|
|
config.handle.eventcb = self.cb_event
|
|
|
|
|
|
|
|
config.handle.questioncb = self.cb_conv
|
|
|
|
|
|
|
|
config.handle.progresscb = self.cb_progress
|
|
|
|
|
|
|
|
config.handle.logcb = self.cb_log
|
|
|
|
|
|
|
|
for db in config.handle.get_syncdbs():
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
|
|
|
t = config.handle.init_transaction()
|
|
|
|
|
|
|
|
db.update(force=True)
|
|
|
|
|
|
|
|
print('refresh')
|
|
|
|
|
|
|
|
t.release()
|
|
|
|
|
|
|
|
except pyalpm.error:
|
|
|
|
|
|
|
|
error = traceback.format_exc()
|
|
|
|
|
|
|
|
break
|
|
|
|
|
|
|
|
return error
|
|
|
|
|
|
|
|
|
|
|
|
@dbus.service.method('org.manjaro.pamac', 'a{sb}', 's', sender_keyword='sender', connection_keyword='connexion')
|
|
|
|
@dbus.service.method('org.manjaro.pamac', 'a{sb}', 's', sender_keyword='sender', connection_keyword='connexion')
|
|
|
|
def Init(self, options, sender=None, connexion=None):
|
|
|
|
def Init(self, options, sender=None, connexion=None):
|
|
|
|
global t
|
|
|
|
global t
|
|
|
|
global error
|
|
|
|
global error
|
|
|
|
if self.policykit_test(sender,connexion,'org.manjaro.pamac.init_release'):
|
|
|
|
if self.policykit_test(sender,connexion,'org.manjaro.pamac.init_release'):
|
|
|
|
error = ''
|
|
|
|
error = ''
|
|
|
|
config.handle.dlcb = cb_dl
|
|
|
|
config.handle.dlcb = self.cb_dl
|
|
|
|
config.handle.totaldlcb = totaldlcb
|
|
|
|
config.handle.totaldlcb = self.totaldlcb
|
|
|
|
config.handle.eventcb = cb_event
|
|
|
|
config.handle.eventcb = self.cb_event
|
|
|
|
config.handle.questioncb = cb_conv
|
|
|
|
config.handle.questioncb = self.cb_conv
|
|
|
|
config.handle.progresscb = cb_progress
|
|
|
|
config.handle.progresscb = self.cb_progress
|
|
|
|
config.handle.logcb = cb_log
|
|
|
|
config.handle.logcb = self.cb_log
|
|
|
|
try:
|
|
|
|
try:
|
|
|
|
t = config.handle.init_transaction(**options)
|
|
|
|
t = config.handle.init_transaction(**options)
|
|
|
|
print('Init:',t.flags)
|
|
|
|
print('Init:',t.flags)
|
|
|
|
@ -167,6 +191,18 @@ class PamacDBusService(dbus.service.Object):
|
|
|
|
else :
|
|
|
|
else :
|
|
|
|
return 'You are not authorized'
|
|
|
|
return 'You are not authorized'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@dbus.service.method('org.manjaro.pamac', '', 's')
|
|
|
|
|
|
|
|
def Sysupgrade(self):
|
|
|
|
|
|
|
|
global t
|
|
|
|
|
|
|
|
global error
|
|
|
|
|
|
|
|
error = ''
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
|
|
|
t.sysupgrade(downgrade=False)
|
|
|
|
|
|
|
|
except pyalpm.error:
|
|
|
|
|
|
|
|
error = traceback.format_exc()
|
|
|
|
|
|
|
|
finally:
|
|
|
|
|
|
|
|
return error
|
|
|
|
|
|
|
|
|
|
|
|
@dbus.service.method('org.manjaro.pamac', 's', 's')
|
|
|
|
@dbus.service.method('org.manjaro.pamac', 's', 's')
|
|
|
|
def Remove(self, pkgname):
|
|
|
|
def Remove(self, pkgname):
|
|
|
|
global t
|
|
|
|
global t
|
|
|
|
@ -227,18 +263,20 @@ class PamacDBusService(dbus.service.Object):
|
|
|
|
liste.append(pkg.name)
|
|
|
|
liste.append(pkg.name)
|
|
|
|
return liste
|
|
|
|
return liste
|
|
|
|
|
|
|
|
|
|
|
|
@dbus.service.method('org.manjaro.pamac', '', 's',sender_keyword='sender', connection_keyword='connexion')
|
|
|
|
@dbus.service.method('org.manjaro.pamac', '', 's', sender_keyword='sender', connection_keyword='connexion')#, async_callbacks=('success', 'nosuccess'))
|
|
|
|
def Commit(self, sender=None, connexion=None):
|
|
|
|
def Commit(self, sender=None, connexion=None):#success, nosuccess, sender=None, connexion=None):
|
|
|
|
global t
|
|
|
|
global t
|
|
|
|
global error
|
|
|
|
global error
|
|
|
|
|
|
|
|
error = ''
|
|
|
|
if self.policykit_test(sender,connexion,'org.manjaro.pamac.commit'):
|
|
|
|
if self.policykit_test(sender,connexion,'org.manjaro.pamac.commit'):
|
|
|
|
ProgressWindow.show_all()
|
|
|
|
|
|
|
|
while Gtk.events_pending():
|
|
|
|
|
|
|
|
Gtk.main_iteration()
|
|
|
|
|
|
|
|
try:
|
|
|
|
try:
|
|
|
|
t.commit()
|
|
|
|
t.commit()
|
|
|
|
|
|
|
|
#success('')
|
|
|
|
except pyalpm.error:
|
|
|
|
except pyalpm.error:
|
|
|
|
error = traceback.format_exc()
|
|
|
|
error = traceback.format_exc()
|
|
|
|
|
|
|
|
#nosuccess(error)
|
|
|
|
|
|
|
|
except dbus.exceptions.DBusException:
|
|
|
|
|
|
|
|
pass
|
|
|
|
finally:
|
|
|
|
finally:
|
|
|
|
return error
|
|
|
|
return error
|
|
|
|
else :
|
|
|
|
else :
|
|
|
|
@ -250,7 +288,6 @@ class PamacDBusService(dbus.service.Object):
|
|
|
|
global error
|
|
|
|
global error
|
|
|
|
if self.policykit_test(sender,connexion,'org.manjaro.pamac.init_release'):
|
|
|
|
if self.policykit_test(sender,connexion,'org.manjaro.pamac.init_release'):
|
|
|
|
error = ''
|
|
|
|
error = ''
|
|
|
|
ProgressWindow.hide()
|
|
|
|
|
|
|
|
try:
|
|
|
|
try:
|
|
|
|
t.release()
|
|
|
|
t.release()
|
|
|
|
except pyalpm.error:
|
|
|
|
except pyalpm.error:
|
|
|
|
@ -262,9 +299,9 @@ class PamacDBusService(dbus.service.Object):
|
|
|
|
|
|
|
|
|
|
|
|
@dbus.service.method('org.manjaro.pamac')
|
|
|
|
@dbus.service.method('org.manjaro.pamac')
|
|
|
|
def StopDaemon(self):
|
|
|
|
def StopDaemon(self):
|
|
|
|
loop.quit()
|
|
|
|
mainloop.quit()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
DBusGMainLoop(set_as_default=True)
|
|
|
|
DBusGMainLoop(set_as_default=True)
|
|
|
|
myservice = PamacDBusService()
|
|
|
|
myservice = PamacDBusService()
|
|
|
|
loop.run()
|
|
|
|
mainloop = GObject.MainLoop()
|
|
|
|
|
|
|
|
mainloop.run()
|
|
|
|
|