parent
9095ef993c
commit
5982973656
@ -1,270 +0,0 @@
|
||||
#! /usr/bin/python
|
||||
# -*-coding:utf-8-*-
|
||||
|
||||
from gi.repository import Gtk
|
||||
|
||||
import pyalpm
|
||||
import traceback
|
||||
|
||||
from backend import config
|
||||
|
||||
interface = Gtk.Builder()
|
||||
interface.add_from_file('/usr/share/pamac/dialogs.glade')
|
||||
|
||||
ProgressWindow = interface.get_object('ProgressWindow')
|
||||
progress_bar = interface.get_object('progressbar2')
|
||||
progress_label = interface.get_object('progresslabel2')
|
||||
action_icon = interface.get_object('action_icon')
|
||||
ErrorDialog = interface.get_object('ErrorDialog')
|
||||
WarningDialog = interface.get_object('WarningDialog')
|
||||
QuestionDialog = interface.get_object('QuestionDialog')
|
||||
|
||||
t = None
|
||||
t_lock = False
|
||||
conflict_to_remove = None
|
||||
to_remove = None
|
||||
to_add = None
|
||||
to_update = None
|
||||
do_syncfirst = False
|
||||
list_first = []
|
||||
|
||||
def init_transaction(handle, **options):
|
||||
"Transaction initialization"
|
||||
global t_lock
|
||||
handle.dlcb = cb_dl
|
||||
handle.totaldlcb = totaldlcb
|
||||
handle.eventcb = cb_event
|
||||
handle.questioncb = cb_conv
|
||||
handle.progresscb = cb_progress
|
||||
handle.logcb = cb_log
|
||||
try:
|
||||
_t = handle.init_transaction(**options)
|
||||
print(_t.flags)
|
||||
t_lock = True
|
||||
return _t
|
||||
except pyalpm.error:
|
||||
ErrorDialog.format_secondary_text(traceback.format_exc())
|
||||
response = ErrorDialog.run()
|
||||
if response:
|
||||
ErrorDialog.hide()
|
||||
return False
|
||||
|
||||
def check_conflicts():
|
||||
global conflict_to_remove
|
||||
conflict_to_remove = {}
|
||||
warning = ''
|
||||
for target in t.to_add:
|
||||
if target.replaces:
|
||||
for name in target.replaces:
|
||||
pkg = config.handle.get_localdb().get_pkg(name)
|
||||
if pkg:
|
||||
if not pkg.name in conflict_to_remove.keys():
|
||||
conflict_to_remove[pkg.name] = pkg
|
||||
if warning:
|
||||
warning = warning+'\n'
|
||||
warning = warning+pkg.name+' will be replaced by '+target.name
|
||||
if target.conflicts:
|
||||
for name in target.conflicts:
|
||||
pkg = config.handle.get_localdb().get_pkg(name)
|
||||
if pkg:
|
||||
if not pkg.name in conflict_to_remove.keys():
|
||||
conflict_to_remove[pkg.name] = pkg
|
||||
for installed_pkg in config.handle.get_localdb().pkgcache:
|
||||
if installed_pkg.conflicts:
|
||||
for name in installed_pkg.conflicts:
|
||||
if name == target.name:
|
||||
if not name in conflict_to_remove.keys():
|
||||
conflict_to_remove[installed_pkg.name] = installed_pkg
|
||||
if warning:
|
||||
WarningDialog.format_secondary_text(warning)
|
||||
response = WarningDialog.run()
|
||||
if response:
|
||||
WarningDialog.hide()
|
||||
|
||||
def do_refresh():
|
||||
"""Sync databases like pacman -Sy"""
|
||||
global t
|
||||
global t_lock
|
||||
for db in config.handle.get_syncdbs():
|
||||
if t_lock is False:
|
||||
t = init_transaction(config.handle)
|
||||
try:
|
||||
db.update(force=False)
|
||||
t.release()
|
||||
t_lock = False
|
||||
except pyalpm.error:
|
||||
ErrorDialog.format_secondary_text(traceback.format_exc())
|
||||
response = ErrorDialog.run()
|
||||
if response:
|
||||
ErrorDialog.hide()
|
||||
t_lock = False
|
||||
break
|
||||
progress_label.set_text('')
|
||||
progress_bar.set_text('')
|
||||
|
||||
def t_finalize(t):
|
||||
ProgressWindow.show_all()
|
||||
try:
|
||||
t.prepare()
|
||||
except pyalpm.error:
|
||||
ErrorDialog.format_secondary_text(traceback.format_exc())
|
||||
response = ErrorDialog.run()
|
||||
if response:
|
||||
ErrorDialog.hide()
|
||||
try:
|
||||
t.commit()
|
||||
except pyalpm.error:
|
||||
ErrorDialog.format_secondary_text(traceback.format_exc())
|
||||
response = ErrorDialog.run()
|
||||
if response:
|
||||
ErrorDialog.hide()
|
||||
t_lock = False
|
||||
ProgressWindow.hide()
|
||||
t.release()
|
||||
|
||||
def get_updates():
|
||||
"""Return a list of package objects in local db which can be updated"""
|
||||
global do_syncfirst
|
||||
global list_first
|
||||
if config.syncfirst:
|
||||
for name in config.syncfirst:
|
||||
pkg = config.handle.get_localdb().get_pkg(name)
|
||||
candidate = pyalpm.sync_newversion(pkg, config.handle.get_syncdbs())
|
||||
if candidate:
|
||||
list_first.append(candidate)
|
||||
if list_first:
|
||||
do_syncfirst = True
|
||||
return list_first
|
||||
result = []
|
||||
installed_pkglist = config.handle.get_localdb().pkgcache
|
||||
for pkg in installed_pkglist:
|
||||
candidate = pyalpm.sync_newversion(pkg, config.handle.get_syncdbs())
|
||||
if candidate:
|
||||
result.append(candidate)
|
||||
return result
|
||||
|
||||
def get_new_version_available(pkgname):
|
||||
for repo in config.handle.get_syncdbs():
|
||||
pkg = repo.get_pkg(pkgname)
|
||||
if pkg is not None:
|
||||
return pkg.version
|
||||
break
|
||||
|
||||
def format_size(size):
|
||||
KiB_size = size / 1024
|
||||
if KiB_size < 1000:
|
||||
size_string = '%.1f KiB' % (KiB_size)
|
||||
return size_string
|
||||
else:
|
||||
size_string = '%.2f MiB' % (KiB_size / 1024)
|
||||
return size_string
|
||||
|
||||
|
||||
# Callbacks
|
||||
event_text = ' '
|
||||
def cb_event(ID, event, tupel):
|
||||
global event_text
|
||||
while Gtk.events_pending():
|
||||
Gtk.main_iteration()
|
||||
if ID is 1:
|
||||
progress_label.set_text('Checking dependencies')
|
||||
action_icon.set_from_file('/usr/share/icons/hicolor/24x24/status/package-search.png')
|
||||
elif ID is 3:
|
||||
progress_label.set_text('Checking file conflicts')
|
||||
action_icon.set_from_file('/usr/share/icons/hicolor/24x24/status/package-search.png')
|
||||
elif ID is 5:
|
||||
progress_label.set_text('Resolving dependencies')
|
||||
action_icon.set_from_file('/usr/share/icons/hicolor/24x24/status/setup.png')
|
||||
elif ID is 7:
|
||||
progress_label.set_text('Checking inter conflicts')
|
||||
action_icon.set_from_file('/usr/share/icons/hicolor/24x24/status/package-search.png')
|
||||
elif ID is 9:
|
||||
progress_label.set_text('Installing packages')
|
||||
action_icon.set_from_file('/usr/share/icons/hicolor/24x24/status/package-add.png')
|
||||
elif ID is 11:
|
||||
progress_label.set_text('Removing packages')
|
||||
action_icon.set_from_file('/usr/share/icons/hicolor/24x24/status/package-delete.png')
|
||||
elif ID is 13:
|
||||
progress_label.set_text('Upgrading packages')
|
||||
action_icon.set_from_file('/usr/share/icons/hicolor/24x24/status/package-update.png')
|
||||
elif ID is 15:
|
||||
progress_label.set_text('Checking integrity')
|
||||
action_icon.set_from_file('/usr/share/icons/hicolor/24x24/status/package-search.png')
|
||||
elif ID is 17:
|
||||
progress_label.set_text('Checking signatures')
|
||||
action_icon.set_from_file('/usr/share/icons/hicolor/24x24/status/package-search.png')
|
||||
print('Checking signatures')
|
||||
elif ID is 27:
|
||||
print('Downloading a file')
|
||||
else :
|
||||
progress_label.set_text('')
|
||||
progress_bar.set_fraction(0.0)
|
||||
progress_bar.set_text('')
|
||||
print(ID,event)
|
||||
|
||||
def cb_conv(*args):
|
||||
print("conversation", args)
|
||||
|
||||
_logmask = pyalpm.LOG_ERROR | pyalpm.LOG_WARNING
|
||||
|
||||
def cb_log(level, line):
|
||||
#global t
|
||||
if not (level & _logmask):
|
||||
return
|
||||
if level & pyalpm.LOG_ERROR:
|
||||
ErrorDialog.format_secondary_text("ERROR: "+line)
|
||||
response = ErrorDialog.run()
|
||||
if response:
|
||||
ErrorDialog.hide()
|
||||
#t.release()
|
||||
elif level & pyalpm.LOG_WARNING:
|
||||
WarningDialog.format_secondary_text("WARNING: "+line)
|
||||
response = WarningDialog.run()
|
||||
if response:
|
||||
WarningDialog.hide()
|
||||
elif level & pyalpm.LOG_DEBUG:
|
||||
line = "DEBUG: " + line
|
||||
print(line)
|
||||
elif level & pyalpm.LOG_FUNCTION:
|
||||
line = "FUNC: " + line
|
||||
print(line)
|
||||
|
||||
total_size = 0
|
||||
def totaldlcb(_total_size):
|
||||
global total_size
|
||||
total_size = _total_size
|
||||
|
||||
already_transferred = 0
|
||||
def cb_dl(_target, _transferred, total):
|
||||
global already_transferred
|
||||
while Gtk.events_pending():
|
||||
Gtk.main_iteration()
|
||||
if total_size > 0:
|
||||
fraction = (_transferred+already_transferred)/total_size
|
||||
size = 0
|
||||
if (to_remove or to_add):
|
||||
for pkg in to_remove+to_add:
|
||||
if pkg.name+'-'+pkg.version in _target:
|
||||
size = pkg.size
|
||||
if _transferred == size:
|
||||
already_transferred += size
|
||||
progress_label.set_text('Downloading '+format_size(total_size))
|
||||
progress_bar.set_text(_target)
|
||||
progress_bar.set_fraction(fraction)
|
||||
action_icon.set_from_file('/usr/share/icons/hicolor/24x24/status/package-download.png')
|
||||
else:
|
||||
progress_label.set_text('Refreshing...')
|
||||
progress_bar.set_text(_target)
|
||||
progress_bar.pulse()
|
||||
action_icon.set_from_file('/usr/share/icons/hicolor/24x24/status/refresh-cache.png')
|
||||
|
||||
def cb_progress(_target, _percent, n, i):
|
||||
while Gtk.events_pending():
|
||||
Gtk.main_iteration()
|
||||
target = _target+' ('+str(i)+'/'+str(n)+')'
|
||||
progress_bar.set_fraction(_percent/100)
|
||||
progress_bar.set_text(target)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
True
|
||||
@ -0,0 +1,19 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE busconfig PUBLIC "-//freedesktop//DTD D-BUS Bus Configuration 1.0//EN"
|
||||
"http://www.freedesktop.org/standards/dbus/1.0/busconfig.dtd">
|
||||
<busconfig>
|
||||
<type>system</type>
|
||||
<!-- Only root can own the service -->
|
||||
<policy user="root">
|
||||
<allow own="org.manjaro.pamac"/>
|
||||
</policy>
|
||||
|
||||
<!-- Allow anyone to invoke methods on the interfaces -->
|
||||
<policy context="default">
|
||||
<allow send_destination="org.manjaro.pamac"/>
|
||||
<allow send_interface="org.manjaro.pamac"/>
|
||||
<allow receive_interface="org.manjaro.pamac"/>
|
||||
<allow receive_sender="org.manjaro.pamac"/>
|
||||
</policy>
|
||||
</busconfig>
|
||||
|
||||
@ -0,0 +1,5 @@
|
||||
[D-BUS Service]
|
||||
Name=org.manjaro.pamac
|
||||
Exec=/usr/bin/start-pamac-daemon
|
||||
User=root
|
||||
|
||||
@ -0,0 +1,26 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE policyconfig PUBLIC
|
||||
"-//freedesktop//DTD PolicyKit Policy Configuration 1.0//EN"
|
||||
"http://www.freedesktop.org/standards/PolicyKit/1.0/policyconfig.dtd">
|
||||
<policyconfig>
|
||||
<vendor>Manjaro</vendor>
|
||||
<icon_name>pamac</icon_name>
|
||||
<action id="org.manjaro.pamac.commit">
|
||||
<message>Authentication is required to change alpm database</message>
|
||||
<message xml:lang="fr">L'authentification est nécessaire pour changer la base de données alpm</message>
|
||||
<defaults>
|
||||
<allow_any>no</allow_any>
|
||||
<allow_inactive>no</allow_inactive>
|
||||
<allow_active>auth_admin_keep</allow_active>
|
||||
</defaults>
|
||||
</action>
|
||||
|
||||
<action id="org.manjaro.pamac.init_release">
|
||||
<defaults>
|
||||
<allow_any>no</allow_any>
|
||||
<allow_inactive>no</allow_inactive>
|
||||
<allow_active>yes</allow_active>
|
||||
</defaults>
|
||||
</action>
|
||||
|
||||
</policyconfig>
|
||||
@ -0,0 +1,3 @@
|
||||
#! /bin/sh
|
||||
|
||||
exec /usr/lib/python3.3/site-packages/pamac/manager.py
|
||||
@ -1,16 +0,0 @@
|
||||
#! /usr/bin/python
|
||||
# -*-coding:utf-8 -*-
|
||||
|
||||
from os import geteuid
|
||||
|
||||
from backend import update, transaction
|
||||
|
||||
if __name__ == "__main__":
|
||||
if geteuid() == 0:
|
||||
transaction.progress_label.set_text('Refreshing...')
|
||||
transaction.progress_bar.pulse()
|
||||
transaction.action_icon.set_from_file('/usr/share/icons/hicolor/24x24/status/refresh-cache.png')
|
||||
transaction.ProgressWindow.show_all()
|
||||
transaction.do_refresh()
|
||||
transaction.ProgressWindow.hide()
|
||||
update.main()
|
||||
@ -0,0 +1,3 @@
|
||||
#! /bin/sh
|
||||
|
||||
exec /usr/lib/python3.3/site-packages/pamac/updater.py
|
||||
@ -0,0 +1,120 @@
|
||||
#! /usr/bin/python
|
||||
# -*-coding:utf-8-*-
|
||||
|
||||
from gi.repository import Gtk
|
||||
import pyalpm
|
||||
from pamac import config
|
||||
|
||||
|
||||
# Callbacks
|
||||
interface = Gtk.Builder()
|
||||
interface.add_from_file('/usr/share/pamac/gui/dialogs.glade')
|
||||
|
||||
ProgressWindow = interface.get_object('ProgressWindow')
|
||||
progress_bar = interface.get_object('progressbar2')
|
||||
progress_label = interface.get_object('progresslabel2')
|
||||
action_icon = interface.get_object('action_icon')
|
||||
|
||||
event_text = ' '
|
||||
def cb_event(ID, event, tupel):
|
||||
global event_text
|
||||
while Gtk.events_pending():
|
||||
Gtk.main_iteration()
|
||||
if ID is 1:
|
||||
progress_label.set_text('Checking dependencies')
|
||||
action_icon.set_from_file('/usr/share/pamac/icons/24x24/status/package-search.png')
|
||||
elif ID is 3:
|
||||
progress_label.set_text('Checking file conflicts')
|
||||
action_icon.set_from_file('/usr/share/pamac/icons/24x24/status/package-search.png')
|
||||
elif ID is 5:
|
||||
progress_label.set_text('Resolving dependencies')
|
||||
action_icon.set_from_file('/usr/share/pamac/icons/24x24/status/setup.png')
|
||||
elif ID is 7:
|
||||
progress_label.set_text('Checking inter conflicts')
|
||||
action_icon.set_from_file('/usr/share/pamac/icons/24x24/status/package-search.png')
|
||||
elif ID is 9:
|
||||
progress_label.set_text('Installing packages')
|
||||
action_icon.set_from_file('/usr/share/pamac/icons/24x24/status/package-add.png')
|
||||
elif ID is 11:
|
||||
progress_label.set_text('Removing packages')
|
||||
action_icon.set_from_file('/usr/share/pamac/icons/24x24/status/package-delete.png')
|
||||
elif ID is 13:
|
||||
progress_label.set_text('Upgrading packages')
|
||||
action_icon.set_from_file('/usr/share/pamac/icons/24x24/status/package-update.png')
|
||||
elif ID is 15:
|
||||
progress_label.set_text('Checking integrity')
|
||||
action_icon.set_from_file('/usr/share/pamac/icons/24x24/status/package-search.png')
|
||||
elif ID is 17:
|
||||
progress_label.set_text('Checking signatures')
|
||||
action_icon.set_from_file('/usr/share/pamac/icons/24x24/status/package-search.png')
|
||||
print('Checking signatures')
|
||||
elif ID is 27:
|
||||
print('Downloading a file')
|
||||
else :
|
||||
progress_label.set_text('')
|
||||
progress_bar.set_fraction(0.0)
|
||||
progress_bar.set_text('')
|
||||
print(ID,event)
|
||||
|
||||
def cb_conv(*args):
|
||||
print("conversation", args)
|
||||
|
||||
_logmask = pyalpm.LOG_ERROR | pyalpm.LOG_WARNING
|
||||
|
||||
def cb_log(level, line):
|
||||
#global t
|
||||
if not (level & _logmask):
|
||||
return
|
||||
if level & pyalpm.LOG_ERROR:
|
||||
ErrorDialog.format_secondary_text("ERROR: "+line)
|
||||
response = ErrorDialog.run()
|
||||
if response:
|
||||
ErrorDialog.hide()
|
||||
#t.release()
|
||||
elif level & pyalpm.LOG_WARNING:
|
||||
WarningDialog.format_secondary_text("WARNING: "+line)
|
||||
response = WarningDialog.run()
|
||||
if response:
|
||||
WarningDialog.hide()
|
||||
elif level & pyalpm.LOG_DEBUG:
|
||||
line = "DEBUG: " + line
|
||||
print(line)
|
||||
elif level & pyalpm.LOG_FUNCTION:
|
||||
line = "FUNC: " + line
|
||||
print(line)
|
||||
|
||||
total_size = 0
|
||||
def totaldlcb(_total_size):
|
||||
global total_size
|
||||
total_size = _total_size
|
||||
|
||||
already_transferred = 0
|
||||
def cb_dl(_target, _transferred, total):
|
||||
global already_transferred
|
||||
while Gtk.events_pending():
|
||||
Gtk.main_iteration()
|
||||
if total_size > 0:
|
||||
fraction = (_transferred+already_transferred)/total_size
|
||||
size = 0
|
||||
if (to_remove or to_add):
|
||||
for pkg in to_remove+to_add:
|
||||
if pkg.name+'-'+pkg.version in _target:
|
||||
size = pkg.size
|
||||
if _transferred == size:
|
||||
already_transferred += size
|
||||
progress_label.set_text('Downloading '+format_size(total_size))
|
||||
progress_bar.set_text(_target)
|
||||
progress_bar.set_fraction(fraction)
|
||||
action_icon.set_from_file('/usr/share/pamac/icons/24x24/status/package-download.png')
|
||||
else:
|
||||
progress_label.set_text('Refreshing...')
|
||||
progress_bar.set_text(_target)
|
||||
progress_bar.pulse()
|
||||
action_icon.set_from_file('/usr/share/pamac/icons/24x24/status/refresh-cache.png')
|
||||
|
||||
def cb_progress(_target, _percent, n, i):
|
||||
while Gtk.events_pending():
|
||||
Gtk.main_iteration()
|
||||
target = _target+' ('+str(i)+'/'+str(n)+')'
|
||||
progress_bar.set_fraction(_percent/100)
|
||||
progress_bar.set_text(target)
|
||||
@ -0,0 +1,161 @@
|
||||
#! /usr/bin/python
|
||||
# -*-coding:utf-8-*-
|
||||
|
||||
import dbus
|
||||
import dbus.service
|
||||
from dbus.mainloop.glib import DBusGMainLoop
|
||||
import os
|
||||
from gi.repository import GObject, Gtk
|
||||
|
||||
import pyalpm
|
||||
import traceback
|
||||
from pamac import config, callbacks
|
||||
|
||||
LANG = os.environ['LANG']
|
||||
|
||||
t = None
|
||||
error = ''
|
||||
|
||||
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')
|
||||
|
||||
def policykit_test(self,sender,connexion,action):
|
||||
bus = dbus.SystemBus()
|
||||
proxy_dbus = connexion.get_object('org.freedesktop.DBus','/org/freedesktop/DBus/Bus', False)
|
||||
dbus_info = dbus.Interface(proxy_dbus,'org.freedesktop.DBus')
|
||||
sender_pid = dbus_info.GetConnectionUnixProcessID(sender)
|
||||
proxy_policykit = bus.get_object('org.freedesktop.PolicyKit1','/org/freedesktop/PolicyKit1/Authority',False)
|
||||
policykit_authority = dbus.Interface(proxy_policykit,'org.freedesktop.PolicyKit1.Authority')
|
||||
|
||||
Subject = ('unix-process', {'pid': dbus.UInt32(sender_pid, variant_level=1),
|
||||
'start-time': dbus.UInt64(0, variant_level=1)})
|
||||
(is_authorized,is_challenge,details) = policykit_authority.CheckAuthorization(Subject, action, {'': ''}, dbus.UInt32(1), '')
|
||||
return is_authorized
|
||||
|
||||
@dbus.service.method('org.manjaro.pamac', 'a{sb}', 's', sender_keyword='sender', connection_keyword='connexion')
|
||||
def Init(self, options, sender=None, connexion=None):
|
||||
global t
|
||||
global error
|
||||
if self.policykit_test(sender,connexion,'org.manjaro.pamac.init_release'):
|
||||
error = ''
|
||||
try:
|
||||
config.handle.dlcb = callbacks.cb_dl
|
||||
config.handle.totaldlcb = callbacks.totaldlcb
|
||||
config.handle.eventcb = callbacks.cb_event
|
||||
config.handle.questioncb = callbacks.cb_conv
|
||||
config.handle.progresscb = callbacks.cb_progress
|
||||
config.handle.logcb = callbacks.cb_log
|
||||
t = config.handle.init_transaction(**options)
|
||||
print('Init:',t.flags)
|
||||
except pyalpm.error:
|
||||
error = traceback.format_exc()
|
||||
finally:
|
||||
return error
|
||||
else :
|
||||
return 'You are not authorized'
|
||||
|
||||
@dbus.service.method('org.manjaro.pamac', 's', 's', sender_keyword='sender', connection_keyword='connexion')
|
||||
def Remove(self, pkgname, sender=None, connexion=None):
|
||||
global t
|
||||
global error
|
||||
error = ''
|
||||
try:
|
||||
pkg = config.handle.get_localdb().get_pkg(pkgname)
|
||||
if pkg is not None:
|
||||
t.remove_pkg(pkg)
|
||||
except pyalpm.error:
|
||||
error = traceback.format_exc()
|
||||
finally:
|
||||
return error
|
||||
|
||||
@dbus.service.method('org.manjaro.pamac', 's', 's', sender_keyword='sender', connection_keyword='connexion')
|
||||
def Add(self, pkgname, sender=None, connexion=None):
|
||||
global t
|
||||
global error
|
||||
error = ''
|
||||
try:
|
||||
for repo in config.handle.get_syncdbs():
|
||||
pkg = repo.get_pkg(pkgname)
|
||||
if pkg:
|
||||
t.add_pkg(pkg)
|
||||
break
|
||||
except pyalpm.error:
|
||||
error = traceback.format_exc()
|
||||
finally:
|
||||
return error
|
||||
|
||||
@dbus.service.method('org.manjaro.pamac', '', 's', sender_keyword='sender', connection_keyword='connexion')
|
||||
def Prepare(self, sender=None, connexion=None):
|
||||
global t
|
||||
global error
|
||||
error = ''
|
||||
try:
|
||||
t.prepare()
|
||||
except pyalpm.error:
|
||||
error = traceback.format_exc()
|
||||
finally:
|
||||
print('to_add:',t.to_add)
|
||||
print('to_remove:',t.to_remove)
|
||||
return error
|
||||
|
||||
@dbus.service.method('org.manjaro.pamac', '', 'as', sender_keyword='sender', connection_keyword='connexion')
|
||||
def To_Remove(self, sender=None, connexion=None):
|
||||
global t
|
||||
liste = []
|
||||
for pkg in t.to_remove:
|
||||
liste.append(pkg.name)
|
||||
return liste
|
||||
|
||||
@dbus.service.method('org.manjaro.pamac', '', 'as', sender_keyword='sender', connection_keyword='connexion')
|
||||
def To_Add(self, sender=None, connexion=None):
|
||||
global t
|
||||
liste = []
|
||||
for pkg in t.to_add:
|
||||
liste.append(pkg.name)
|
||||
return liste
|
||||
|
||||
@dbus.service.method('org.manjaro.pamac', '', 's',sender_keyword='sender', connection_keyword='connexion')
|
||||
def Commit(self, sender=None, connexion=None):
|
||||
global t
|
||||
global error
|
||||
if self.policykit_test(sender,connexion,'org.manjaro.pamac.commit'):
|
||||
try:
|
||||
callbacks.ProgressWindow.show_all()
|
||||
while Gtk.events_pending():
|
||||
Gtk.main_iteration()
|
||||
t.commit()
|
||||
except pyalpm.error:
|
||||
error = traceback.format_exc()
|
||||
finally:
|
||||
return error
|
||||
else :
|
||||
return 'You are not authorized'
|
||||
|
||||
@dbus.service.method('org.manjaro.pamac', '', 's', sender_keyword='sender', connection_keyword='connexion')
|
||||
def Release(self, sender=None, connexion=None):
|
||||
global t
|
||||
global error
|
||||
if self.policykit_test(sender,connexion,'org.manjaro.pamac.init_release'):
|
||||
error = ''
|
||||
try:
|
||||
callbacks.ProgressWindow.hide()
|
||||
t.release()
|
||||
except pyalpm.error:
|
||||
error = traceback.format_exc()
|
||||
finally:
|
||||
return error
|
||||
else :
|
||||
return 'You are not authorized'
|
||||
|
||||
@dbus.service.method('org.manjaro.pamac',sender_keyword='sender', connection_keyword='connexion')
|
||||
def StopDaemon(self,sender=None, connexion=None):
|
||||
loop.quit()
|
||||
|
||||
|
||||
DBusGMainLoop(set_as_default=True)
|
||||
myservice = PamacDBusService()
|
||||
loop = GObject.MainLoop()
|
||||
loop.run()
|
||||
@ -0,0 +1,178 @@
|
||||
#! /usr/bin/python
|
||||
# -*-coding:utf-8-*-
|
||||
|
||||
from gi.repository import Gtk
|
||||
|
||||
import pyalpm
|
||||
import traceback
|
||||
import dbus
|
||||
|
||||
from pamac import config
|
||||
|
||||
interface = Gtk.Builder()
|
||||
interface.add_from_file('/usr/share/pamac/gui/dialogs.glade')
|
||||
|
||||
ErrorDialog = interface.get_object('ErrorDialog')
|
||||
WarningDialog = interface.get_object('WarningDialog')
|
||||
|
||||
t = None
|
||||
t_lock = False
|
||||
conflict_to_remove = None
|
||||
to_remove = None
|
||||
to_add = None
|
||||
to_update = None
|
||||
do_syncfirst = False
|
||||
list_first = []
|
||||
|
||||
proxy = dbus.SystemBus().get_object('org.manjaro.pamac','/org/manjaro/pamac')
|
||||
Init = proxy.get_dbus_method('Init','org.manjaro.pamac')
|
||||
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')
|
||||
|
||||
def init_transaction(**options):
|
||||
"Transaction initialization"
|
||||
global t_lock
|
||||
global proxy
|
||||
error = Init(options)
|
||||
print(error)
|
||||
if not error:
|
||||
t_lock = True
|
||||
return True
|
||||
else:
|
||||
ErrorDialog.format_secondary_text(error)
|
||||
response = ErrorDialog.run()
|
||||
if response:
|
||||
ErrorDialog.hide()
|
||||
return False
|
||||
|
||||
def check_conflicts():
|
||||
global conflict_to_remove
|
||||
global to_add
|
||||
global to_remove
|
||||
conflict_to_remove = {}
|
||||
to_check = []
|
||||
warning = ''
|
||||
for pkgname in to_add:
|
||||
for repo in config.handle.get_syncdbs():
|
||||
pkg = repo.get_pkg(pkgname)
|
||||
if pkg:
|
||||
to_check.append(pkg)
|
||||
break
|
||||
for target in to_check:
|
||||
if target.replaces:
|
||||
for name in target.replaces:
|
||||
pkg = config.handle.get_localdb().get_pkg(name)
|
||||
if pkg:
|
||||
if not pkg.name in to_remove:
|
||||
to_remove.append(pkg.name)
|
||||
if warning:
|
||||
warning = warning+'\n'
|
||||
warning = warning+pkg.name+' will be replaced by '+target.name
|
||||
if target.conflicts:
|
||||
for name in target.conflicts:
|
||||
pkg = config.handle.get_localdb().get_pkg(name)
|
||||
if pkg:
|
||||
if not pkg.name in to_remove:
|
||||
to_remove.append(pkg.name)
|
||||
for installed_pkg in config.handle.get_localdb().pkgcache:
|
||||
if installed_pkg.conflicts:
|
||||
for name in installed_pkg.conflicts:
|
||||
if name == target.name:
|
||||
if not name in to_remove:
|
||||
to_remove.append(installed_pkg.name)
|
||||
if warning:
|
||||
WarningDialog.format_secondary_text(warning)
|
||||
response = WarningDialog.run()
|
||||
if response:
|
||||
WarningDialog.hide()
|
||||
|
||||
def get_to_remove():
|
||||
global to_remove
|
||||
to_remove = To_Remove()
|
||||
|
||||
def get_to_add():
|
||||
global to_add
|
||||
to_add = To_Add()
|
||||
|
||||
def finalize():
|
||||
global t_lock
|
||||
while Gtk.events_pending():
|
||||
Gtk.main_iteration()
|
||||
error = Prepare()
|
||||
if error:
|
||||
ErrorDialog.format_secondary_text(error)
|
||||
response = ErrorDialog.run()
|
||||
if response:
|
||||
transaction.ErrorDialog.hide()
|
||||
error = Commit()
|
||||
if error:
|
||||
ErrorDialog.format_secondary_text(error)
|
||||
response = ErrorDialog.run()
|
||||
if response:
|
||||
transaction.ErrorDialog.hide()
|
||||
t_lock = False
|
||||
Release()
|
||||
|
||||
def do_refresh():
|
||||
"""Sync databases like pacman -Sy"""
|
||||
global t
|
||||
global t_lock
|
||||
for db in config.handle.get_syncdbs():
|
||||
if t_lock is False:
|
||||
t = init_transaction()
|
||||
try:
|
||||
db.update(force=False)
|
||||
t.release()
|
||||
t_lock = False
|
||||
except pyalpm.error:
|
||||
ErrorDialog.format_secondary_text(traceback.format_exc())
|
||||
response = ErrorDialog.run()
|
||||
if response:
|
||||
ErrorDialog.hide()
|
||||
t_lock = False
|
||||
break
|
||||
t_lock = False
|
||||
progress_label.set_text('')
|
||||
progress_bar.set_text('')
|
||||
|
||||
def get_updates():
|
||||
"""Return a list of package objects in local db which can be updated"""
|
||||
global do_syncfirst
|
||||
global list_first
|
||||
if config.syncfirst:
|
||||
for name in config.syncfirst:
|
||||
pkg = config.handle.get_localdb().get_pkg(name)
|
||||
candidate = pyalpm.sync_newversion(pkg, config.handle.get_syncdbs())
|
||||
if candidate:
|
||||
list_first.append(candidate)
|
||||
if list_first:
|
||||
do_syncfirst = True
|
||||
return list_first
|
||||
result = []
|
||||
installed_pkglist = config.handle.get_localdb().pkgcache
|
||||
for pkg in installed_pkglist:
|
||||
candidate = pyalpm.sync_newversion(pkg, config.handle.get_syncdbs())
|
||||
if candidate:
|
||||
result.append(candidate)
|
||||
return result
|
||||
|
||||
def get_new_version_available(pkgname):
|
||||
for repo in config.handle.get_syncdbs():
|
||||
pkg = repo.get_pkg(pkgname)
|
||||
if pkg is not None:
|
||||
return pkg.version
|
||||
break
|
||||
|
||||
def format_size(size):
|
||||
KiB_size = size / 1024
|
||||
if KiB_size < 1000:
|
||||
size_string = '%.1f KiB' % (KiB_size)
|
||||
return size_string
|
||||
else:
|
||||
size_string = '%.2f MiB' % (KiB_size / 1024)
|
||||
return size_string
|
||||
@ -0,0 +1,4 @@
|
||||
#! /bin/bash
|
||||
|
||||
/usr/bin/pamac-daemon.py &
|
||||
|
||||
@ -0,0 +1,27 @@
|
||||
#! /usr/bin/python
|
||||
# -*-coding:utf-8-*-
|
||||
|
||||
import dbus, os
|
||||
from pamac import transaction
|
||||
|
||||
def policykit_auth():
|
||||
bus_name = dbus.service.BusName('apps.nano77.gdm3setup', bus)
|
||||
dbus.service.Object.__init__(self, bus_name, '/apps/nano77/gdm3setup')
|
||||
|
||||
def policykit_test(sender,connexion,action):
|
||||
bus = dbus.SystemBus()
|
||||
proxy_dbus = connexion.get_object('org.freedesktop.DBus','/org/freedesktop/DBus/Bus', False)
|
||||
dbus_info = dbus.Interface(proxy_dbus,'org.freedesktop.DBus')
|
||||
sender_pid = dbus_info.GetConnectionUnixProcessID(sender)
|
||||
proxy_policykit = bus.get_object('org.freedesktop.PolicyKit1','/org/freedesktop/PolicyKit1/Authority',False)
|
||||
policykit_authority = dbus.Interface(proxy_policykit,'org.freedesktop.PolicyKit1.Authority')
|
||||
|
||||
Subject = ('unix-process', {'pid': dbus.UInt32(sender_pid, variant_level=1),
|
||||
'start-time': dbus.UInt64(0, variant_level=1)})
|
||||
(is_authorized,is_challenge,details) = policykit_authority.CheckAuthorization(Subject, action, {'': ''}, dbus.UInt32(1), '')
|
||||
return is_authorized
|
||||
return pk_granted
|
||||
|
||||
if policykit_auth() == 1:
|
||||
print('ok')
|
||||
transaction.do_refresh()
|
||||
Loading…
Reference in new issue