Kaydet (Commit) 0fad819c authored tarafından Bahadır Kandemir's avatar Bahadır Kandemir

Use polkit-auth

üst 5d0d275d
2009-06-04 Bahadır Kandemir <bahadir@pardus.org.tr>
* api: Use polkit-auth
2009-05-11 Bahadır Kandemir <bahadir@pardus.org.tr>
* network: callScrip(profile, state) for executing profile scripts under
/etc/network/netlink.d/profilename.state
......
......@@ -31,6 +31,9 @@ Asynchronous calls:
# Localize strings
link.setLocale()
# Use authentication agent (GUI)
link.useAgent()
# Make an asynchronous call to get service information
def handler(package, exception, result):
if exception:
......@@ -49,5 +52,7 @@ Connecting COMAR service on alternate destination:
This will simply try to connect tr.org.pardus.comar2 instead
of tr.org.pardus.comar
COMAR 3.0's primary destination is tr.org.pardus.comar3 and
alternate destination is tr.org.pardus.comar3.updated
Connecting to alternative DBus server:
import comar
link = comar.Link(socket="/mnt/target/var/run/dbus/system_bus_socket")
......@@ -14,6 +14,7 @@ __version__ = '2.4.1'
import dbus
import locale
import os
import subprocess
class Call:
def __init__(self, link, group, class_=None, package=None, method=None):
......@@ -128,17 +129,11 @@ class Call:
raise AttributeError, "Package name required for non-async calls."
def queryPolicyKit(self, action):
if "DISPLAY" not in os.environ:
raise Exception, "X session required to query PolKit"
bus = dbus.SessionBus()
try:
obj = bus.get_object("org.freedesktop.PolicyKit.AuthenticationAgent", "/")
except dbus.DBusException, exception:
return False
iface = dbus.Interface(obj, "org.freedesktop.PolicyKit.AuthenticationAgent")
try:
return iface.ObtainAuthorization(action, 0, os.getpid(), timeout=2**16-1) == 1
except:
if not self.link.useAgent:
os.environ["POLKIT_AUTH_FORCE_TEXT"] = "1"
ret = subprocess.call(["/usr/bin/polkit-auth", "--obtain", action])
if ret == 0:
return True
return False
......@@ -148,6 +143,7 @@ class Link:
self.address = "tr.org.pardus.comar"
self.interface = "tr.org.pardus.comar"
self.socket = socket
self.useAgent = False
if not socket:
self.bus = dbus.SystemBus()
......@@ -157,6 +153,9 @@ class Link:
if alternate:
self.address += "2"
def useAgent(self, agent=True):
self.useAgent = agent
def setLocale(self):
try:
code, encoding = locale.getdefaultlocale()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment