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"
"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"/>
@ -10,10 +9,8 @@
<!-- 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"/>
<allow send_destination="org.manjaro.pamac"
send_interface="org.manjaro.pamac"/>
</policy>
</busconfig>

View File

@ -2,4 +2,4 @@
Name=org.manjaro.pamac
Exec=/usr/bin/start-pamac-daemon
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
from pamac import config
handle = config.handle
# Callbacks
interface = Gtk.Builder()

View File

@ -36,7 +36,7 @@ installed_column.set_sort_column_id(1)
name_column.set_sort_column_id(0)
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:
if not name in tmp_list:
tmp_list.append(name)
@ -59,13 +59,13 @@ def set_list_dict_search(*patterns):
pkg_name_list = []
pkg_object_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):
if not pkg_object.name in pkg_name_list:
pkg_name_list.append(pkg_object.name)
pkg_object_dict[pkg_object.name] = pkg_object
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)
if not pkg_object.name in pkg_name_list:
pkg_name_list.append(pkg_object.name)
@ -80,7 +80,7 @@ def set_list_dict_group(group):
pkg_name_list = []
pkg_object_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)
if grp is not None:
name, pkg_list = grp
@ -89,7 +89,7 @@ def set_list_dict_group(group):
pkg_name_list.append(pkg_object.name)
pkg_object_dict[pkg_object.name] = pkg_object
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)
if grp is not None:
name, pkg_list = grp
@ -206,7 +206,7 @@ def set_transaction_sum():
bottom_label.set_markup('')
if transaction.to_add:
installed = []
for pkg_object in config.handle.get_localdb().pkgcache:
for pkg_object in callbacks.handle.get_localdb().pkgcache:
installed.append(pkg_object.name)
transaction.to_update = sorted(set(installed).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.t_lock = False
transaction.get_to_remove()
#transaction.get_to_add()
transaction.get_to_add()
set_transaction_sum()
ConfDialog.show_all()
if transaction_type is "install":

View File

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

View File

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

View File

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