From 5b50e92cc8ba0143000d5b1e9a3787cb569e0ce8 Mon Sep 17 00:00:00 2001 From: guinux Date: Sun, 13 Jan 2013 16:37:17 +0100 Subject: [PATCH] I think I made it (hope, hope) --- data/dbus/org.manjaro.pamac.conf | 7 ++--- data/dbus/org.manjaro.pamac.service | 2 +- data/systemd/pamac.service | 8 +++++ pamac/callbacks.py | 1 + pamac/manager.py | 14 ++++----- pamac/pamac-daemon.py | 46 ++++++++++++++--------------- pamac/transaction.py | 22 +++++++------- start-pamac-daemon | 3 +- test.py | 27 ----------------- 9 files changed, 53 insertions(+), 77 deletions(-) create mode 100644 data/systemd/pamac.service delete mode 100755 test.py diff --git a/data/dbus/org.manjaro.pamac.conf b/data/dbus/org.manjaro.pamac.conf index d53cca6..2d727f7 100644 --- a/data/dbus/org.manjaro.pamac.conf +++ b/data/dbus/org.manjaro.pamac.conf @@ -2,7 +2,6 @@ - system @@ -10,10 +9,8 @@ - - - - + diff --git a/data/dbus/org.manjaro.pamac.service b/data/dbus/org.manjaro.pamac.service index 6448986..a64390b 100644 --- a/data/dbus/org.manjaro.pamac.service +++ b/data/dbus/org.manjaro.pamac.service @@ -2,4 +2,4 @@ Name=org.manjaro.pamac Exec=/usr/bin/start-pamac-daemon User=root - +SystemdService=pamac.service diff --git a/data/systemd/pamac.service b/data/systemd/pamac.service new file mode 100644 index 0000000..6a9954f --- /dev/null +++ b/data/systemd/pamac.service @@ -0,0 +1,8 @@ +[Unit] +Description=Pamac + +[Service] +Type=dbus +BusName=org.manjaro.pamac +ExecStart=/usr/bin/start-pamac-daemon +RemainAfterExit=Yes diff --git a/pamac/callbacks.py b/pamac/callbacks.py index 2c0d2e2..83ca037 100755 --- a/pamac/callbacks.py +++ b/pamac/callbacks.py @@ -5,6 +5,7 @@ from gi.repository import Gtk import pyalpm from pamac import config +handle = config.handle # Callbacks interface = Gtk.Builder() diff --git a/pamac/manager.py b/pamac/manager.py index 8ab3174..d13c48c 100755 --- a/pamac/manager.py +++ b/pamac/manager.py @@ -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": diff --git a/pamac/pamac-daemon.py b/pamac/pamac-daemon.py index 40f16f1..e59905b 100755 --- a/pamac/pamac-daemon.py +++ b/pamac/pamac-daemon.py @@ -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() diff --git a/pamac/transaction.py b/pamac/transaction.py index 65936b5..ae4e37f 100755 --- a/pamac/transaction.py +++ b/pamac/transaction.py @@ -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 diff --git a/start-pamac-daemon b/start-pamac-daemon index 6dc35a3..a09fb06 100755 --- a/start-pamac-daemon +++ b/start-pamac-daemon @@ -1,4 +1,3 @@ #! /bin/bash -/usr/bin/pamac-daemon.py & - +DISPLAY=:0.0 pamac-daemon.py & diff --git a/test.py b/test.py deleted file mode 100755 index f94ac92..0000000 --- a/test.py +++ /dev/null @@ -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()