I think I made it (hope, hope)

This commit is contained in:
guinux 2013-01-13 16:37:17 +01:00
parent 5982973656
commit 5b50e92cc8
9 changed files with 53 additions and 77 deletions

View File

@ -2,7 +2,6 @@
<!DOCTYPE busconfig PUBLIC "-//freedesktop//DTD D-BUS Bus Configuration 1.0//EN" <!DOCTYPE busconfig PUBLIC "-//freedesktop//DTD D-BUS Bus Configuration 1.0//EN"
"http://www.freedesktop.org/standards/dbus/1.0/busconfig.dtd"> "http://www.freedesktop.org/standards/dbus/1.0/busconfig.dtd">
<busconfig> <busconfig>
<type>system</type>
<!-- Only root can own the service --> <!-- Only root can own the service -->
<policy user="root"> <policy user="root">
<allow own="org.manjaro.pamac"/> <allow own="org.manjaro.pamac"/>
@ -10,10 +9,8 @@
<!-- Allow anyone to invoke methods on the interfaces --> <!-- Allow anyone to invoke methods on the interfaces -->
<policy context="default"> <policy context="default">
<allow send_destination="org.manjaro.pamac"/> <allow send_destination="org.manjaro.pamac"
<allow send_interface="org.manjaro.pamac"/> send_interface="org.manjaro.pamac"/>
<allow receive_interface="org.manjaro.pamac"/>
<allow receive_sender="org.manjaro.pamac"/>
</policy> </policy>
</busconfig> </busconfig>

View File

@ -2,4 +2,4 @@
Name=org.manjaro.pamac Name=org.manjaro.pamac
Exec=/usr/bin/start-pamac-daemon Exec=/usr/bin/start-pamac-daemon
User=root User=root
SystemdService=pamac.service

View File

@ -0,0 +1,8 @@
[Unit]
Description=Pamac
[Service]
Type=dbus
BusName=org.manjaro.pamac
ExecStart=/usr/bin/start-pamac-daemon
RemainAfterExit=Yes

View File

@ -5,6 +5,7 @@ from gi.repository import Gtk
import pyalpm import pyalpm
from pamac import config from pamac import config
handle = config.handle
# Callbacks # Callbacks
interface = Gtk.Builder() interface = Gtk.Builder()

View File

@ -36,7 +36,7 @@ installed_column.set_sort_column_id(1)
name_column.set_sort_column_id(0) name_column.set_sort_column_id(0)
tmp_list = [] tmp_list = []
for repo in config.handle.get_syncdbs(): for repo in config.pacman_conf.initialize_alpm().get_syncdbs():
for name, pkgs in repo.grpcache: for name, pkgs in repo.grpcache:
if not name in tmp_list: if not name in tmp_list:
tmp_list.append(name) tmp_list.append(name)
@ -59,13 +59,13 @@ def set_list_dict_search(*patterns):
pkg_name_list = [] pkg_name_list = []
pkg_object_dict = {} pkg_object_dict = {}
pkg_installed_dict = {} pkg_installed_dict = {}
for db in config.handle.get_syncdbs(): for db in config.pacman_conf.initialize_alpm().get_syncdbs():
for pkg_object in db.search(*patterns): for pkg_object in db.search(*patterns):
if not pkg_object.name in pkg_name_list: if not pkg_object.name in pkg_name_list:
pkg_name_list.append(pkg_object.name) pkg_name_list.append(pkg_object.name)
pkg_object_dict[pkg_object.name] = pkg_object pkg_object_dict[pkg_object.name] = pkg_object
pkg_installed_dict[pkg_object.name] = False pkg_installed_dict[pkg_object.name] = False
for pkg_object in config.handle.get_localdb().search(*patterns): for pkg_object in config.pacman_conf.initialize_alpm().get_localdb().search(*patterns):
print(pkg_object) print(pkg_object)
if not pkg_object.name in pkg_name_list: if not pkg_object.name in pkg_name_list:
pkg_name_list.append(pkg_object.name) pkg_name_list.append(pkg_object.name)
@ -80,7 +80,7 @@ def set_list_dict_group(group):
pkg_name_list = [] pkg_name_list = []
pkg_object_dict = {} pkg_object_dict = {}
pkg_installed_dict = {} pkg_installed_dict = {}
for db in config.handle.get_syncdbs(): for db in config.pacman_conf.initialize_alpm().get_syncdbs():
grp = db.read_grp(group) grp = db.read_grp(group)
if grp is not None: if grp is not None:
name, pkg_list = grp name, pkg_list = grp
@ -89,7 +89,7 @@ def set_list_dict_group(group):
pkg_name_list.append(pkg_object.name) pkg_name_list.append(pkg_object.name)
pkg_object_dict[pkg_object.name] = pkg_object pkg_object_dict[pkg_object.name] = pkg_object
pkg_installed_dict[pkg_object.name] = False pkg_installed_dict[pkg_object.name] = False
db = config.handle.get_localdb() db = config.pacman_conf.initialize_alpm().get_localdb()
grp = db.read_grp(group) grp = db.read_grp(group)
if grp is not None: if grp is not None:
name, pkg_list = grp name, pkg_list = grp
@ -206,7 +206,7 @@ def set_transaction_sum():
bottom_label.set_markup('') bottom_label.set_markup('')
if transaction.to_add: if transaction.to_add:
installed = [] installed = []
for pkg_object in config.handle.get_localdb().pkgcache: for pkg_object in callbacks.handle.get_localdb().pkgcache:
installed.append(pkg_object.name) installed.append(pkg_object.name)
transaction.to_update = sorted(set(installed).intersection(transaction.to_add)) transaction.to_update = sorted(set(installed).intersection(transaction.to_add))
to_remove_from_add = sorted(set(transaction.to_update).intersection(transaction.to_add)) to_remove_from_add = sorted(set(transaction.to_update).intersection(transaction.to_add))
@ -273,7 +273,7 @@ class Handler:
transaction.Release() transaction.Release()
transaction.t_lock = False transaction.t_lock = False
transaction.get_to_remove() transaction.get_to_remove()
#transaction.get_to_add() transaction.get_to_add()
set_transaction_sum() set_transaction_sum()
ConfDialog.show_all() ConfDialog.show_all()
if transaction_type is "install": if transaction_type is "install":

View File

@ -4,14 +4,13 @@
import dbus import dbus
import dbus.service import dbus.service
from dbus.mainloop.glib import DBusGMainLoop from dbus.mainloop.glib import DBusGMainLoop
import os
from gi.repository import GObject, Gtk from gi.repository import GObject, Gtk
import pyalpm import pyalpm
import traceback import traceback
from pamac import config, callbacks from pamac import config, callbacks
LANG = os.environ['LANG'] loop = GObject.MainLoop()
t = None t = None
error = '' error = ''
@ -42,13 +41,13 @@ class PamacDBusService(dbus.service.Object):
if self.policykit_test(sender,connexion,'org.manjaro.pamac.init_release'): if self.policykit_test(sender,connexion,'org.manjaro.pamac.init_release'):
error = '' error = ''
try: try:
config.handle.dlcb = callbacks.cb_dl callbacks.handle.dlcb = callbacks.cb_dl
config.handle.totaldlcb = callbacks.totaldlcb callbacks.handle.totaldlcb = callbacks.totaldlcb
config.handle.eventcb = callbacks.cb_event callbacks.handle.eventcb = callbacks.cb_event
config.handle.questioncb = callbacks.cb_conv callbacks.handle.questioncb = callbacks.cb_conv
config.handle.progresscb = callbacks.cb_progress callbacks.handle.progresscb = callbacks.cb_progress
config.handle.logcb = callbacks.cb_log callbacks.handle.logcb = callbacks.cb_log
t = config.handle.init_transaction(**options) t = callbacks.handle.init_transaction(**options)
print('Init:',t.flags) print('Init:',t.flags)
except pyalpm.error: except pyalpm.error:
error = traceback.format_exc() error = traceback.format_exc()
@ -57,13 +56,13 @@ class PamacDBusService(dbus.service.Object):
else : else :
return 'You are not authorized' return 'You are not authorized'
@dbus.service.method('org.manjaro.pamac', 's', 's', sender_keyword='sender', connection_keyword='connexion') @dbus.service.method('org.manjaro.pamac', 's', 's')
def Remove(self, pkgname, sender=None, connexion=None): def Remove(self, pkgname):
global t global t
global error global error
error = '' error = ''
try: try:
pkg = config.handle.get_localdb().get_pkg(pkgname) pkg = callbacks.handle.get_localdb().get_pkg(pkgname)
if pkg is not None: if pkg is not None:
t.remove_pkg(pkg) t.remove_pkg(pkg)
except pyalpm.error: except pyalpm.error:
@ -71,13 +70,13 @@ class PamacDBusService(dbus.service.Object):
finally: finally:
return error return error
@dbus.service.method('org.manjaro.pamac', 's', 's', sender_keyword='sender', connection_keyword='connexion') @dbus.service.method('org.manjaro.pamac', 's', 's')
def Add(self, pkgname, sender=None, connexion=None): def Add(self, pkgname):
global t global t
global error global error
error = '' error = ''
try: try:
for repo in config.handle.get_syncdbs(): for repo in callbacks.handle.get_syncdbs():
pkg = repo.get_pkg(pkgname) pkg = repo.get_pkg(pkgname)
if pkg: if pkg:
t.add_pkg(pkg) t.add_pkg(pkg)
@ -87,8 +86,8 @@ class PamacDBusService(dbus.service.Object):
finally: finally:
return error return error
@dbus.service.method('org.manjaro.pamac', '', 's', sender_keyword='sender', connection_keyword='connexion') @dbus.service.method('org.manjaro.pamac', '', 's')
def Prepare(self, sender=None, connexion=None): def Prepare(self):
global t global t
global error global error
error = '' error = ''
@ -101,16 +100,16 @@ class PamacDBusService(dbus.service.Object):
print('to_remove:',t.to_remove) print('to_remove:',t.to_remove)
return error return error
@dbus.service.method('org.manjaro.pamac', '', 'as', sender_keyword='sender', connection_keyword='connexion') @dbus.service.method('org.manjaro.pamac', '', 'as')
def To_Remove(self, sender=None, connexion=None): def To_Remove(self):
global t global t
liste = [] liste = []
for pkg in t.to_remove: for pkg in t.to_remove:
liste.append(pkg.name) liste.append(pkg.name)
return liste return liste
@dbus.service.method('org.manjaro.pamac', '', 'as', sender_keyword='sender', connection_keyword='connexion') @dbus.service.method('org.manjaro.pamac', '', 'as')
def To_Add(self, sender=None, connexion=None): def To_Add(self):
global t global t
liste = [] liste = []
for pkg in t.to_add: for pkg in t.to_add:
@ -150,12 +149,11 @@ class PamacDBusService(dbus.service.Object):
else : else :
return 'You are not authorized' return 'You are not authorized'
@dbus.service.method('org.manjaro.pamac',sender_keyword='sender', connection_keyword='connexion') @dbus.service.method('org.manjaro.pamac')
def StopDaemon(self,sender=None, connexion=None): def StopDaemon(self):
loop.quit() loop.quit()
DBusGMainLoop(set_as_default=True) DBusGMainLoop(set_as_default=True)
myservice = PamacDBusService() myservice = PamacDBusService()
loop = GObject.MainLoop()
loop.run() loop.run()

View File

@ -7,7 +7,7 @@ import pyalpm
import traceback import traceback
import dbus import dbus
from pamac import config from pamac import config, callbacks
interface = Gtk.Builder() interface = Gtk.Builder()
interface.add_from_file('/usr/share/pamac/gui/dialogs.glade') interface.add_from_file('/usr/share/pamac/gui/dialogs.glade')
@ -58,7 +58,7 @@ def check_conflicts():
to_check = [] to_check = []
warning = '' warning = ''
for pkgname in to_add: for pkgname in to_add:
for repo in config.handle.get_syncdbs(): for repo in callbacks.handle.get_syncdbs():
pkg = repo.get_pkg(pkgname) pkg = repo.get_pkg(pkgname)
if pkg: if pkg:
to_check.append(pkg) to_check.append(pkg)
@ -66,7 +66,7 @@ def check_conflicts():
for target in to_check: for target in to_check:
if target.replaces: if target.replaces:
for name in target.replaces: for name in target.replaces:
pkg = config.handle.get_localdb().get_pkg(name) pkg = callbacks.handle.get_localdb().get_pkg(name)
if pkg: if pkg:
if not pkg.name in to_remove: if not pkg.name in to_remove:
to_remove.append(pkg.name) to_remove.append(pkg.name)
@ -75,11 +75,11 @@ def check_conflicts():
warning = warning+pkg.name+' will be replaced by '+target.name warning = warning+pkg.name+' will be replaced by '+target.name
if target.conflicts: if target.conflicts:
for name in target.conflicts: for name in target.conflicts:
pkg = config.handle.get_localdb().get_pkg(name) pkg = callbacks.handle.get_localdb().get_pkg(name)
if pkg: if pkg:
if not pkg.name in to_remove: if not pkg.name in to_remove:
to_remove.append(pkg.name) to_remove.append(pkg.name)
for installed_pkg in config.handle.get_localdb().pkgcache: for installed_pkg in callbacks.handle.get_localdb().pkgcache:
if installed_pkg.conflicts: if installed_pkg.conflicts:
for name in installed_pkg.conflicts: for name in installed_pkg.conflicts:
if name == target.name: if name == target.name:
@ -122,7 +122,7 @@ def do_refresh():
"""Sync databases like pacman -Sy""" """Sync databases like pacman -Sy"""
global t global t
global t_lock global t_lock
for db in config.handle.get_syncdbs(): for db in callbacks.handle.get_syncdbs():
if t_lock is False: if t_lock is False:
t = init_transaction() t = init_transaction()
try: try:
@ -146,23 +146,23 @@ def get_updates():
global list_first global list_first
if config.syncfirst: if config.syncfirst:
for name in config.syncfirst: for name in config.syncfirst:
pkg = config.handle.get_localdb().get_pkg(name) pkg = callbacks.handle.get_localdb().get_pkg(name)
candidate = pyalpm.sync_newversion(pkg, config.handle.get_syncdbs()) candidate = pyalpm.sync_newversion(pkg, callbacks.handle.get_syncdbs())
if candidate: if candidate:
list_first.append(candidate) list_first.append(candidate)
if list_first: if list_first:
do_syncfirst = True do_syncfirst = True
return list_first return list_first
result = [] result = []
installed_pkglist = config.handle.get_localdb().pkgcache installed_pkglist = callbacks.handle.get_localdb().pkgcache
for pkg in installed_pkglist: for pkg in installed_pkglist:
candidate = pyalpm.sync_newversion(pkg, config.handle.get_syncdbs()) candidate = pyalpm.sync_newversion(pkg, callbacks.handle.get_syncdbs())
if candidate: if candidate:
result.append(candidate) result.append(candidate)
return result return result
def get_new_version_available(pkgname): def get_new_version_available(pkgname):
for repo in config.handle.get_syncdbs(): for repo in callbacks.handle.get_syncdbs():
pkg = repo.get_pkg(pkgname) pkg = repo.get_pkg(pkgname)
if pkg is not None: if pkg is not None:
return pkg.version return pkg.version

View File

@ -1,4 +1,3 @@
#! /bin/bash #! /bin/bash
/usr/bin/pamac-daemon.py & DISPLAY=:0.0 pamac-daemon.py &

27
test.py
View File

@ -1,27 +0,0 @@
#! /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()