Author: lslezak Date: Thu Mar 5 13:37:37 2009 New Revision: 55931 URL: http://svn.opensuse.org/viewcvs/yast?rev=55931&view=rev Log: - fixed DBus desktop example - obtain authorization if needed Modified: branches/tmp/lslezak/core/dbus/namespace_service/doc/dbus_samba_export.py Modified: branches/tmp/lslezak/core/dbus/namespace_service/doc/dbus_samba_export.py URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/lslezak/core/dbus/namespace_service/doc/dbus_samba_export.py?rev=55931&r1=55930&r2=55931&view=diff ============================================================================== --- branches/tmp/lslezak/core/dbus/namespace_service/doc/dbus_samba_export.py (original) +++ branches/tmp/lslezak/core/dbus/namespace_service/doc/dbus_samba_export.py Thu Mar 5 13:37:37 2009 @@ -4,6 +4,8 @@ import dbus import sys +import os +import re def main(): @@ -24,7 +26,32 @@ samba = bus.get_object('org.opensuse.YaST.modules', '/org/opensuse/YaST/modules/YaPI__Samba') print 'Exporting directory ' + directory - result = samba.AddShare(share_name, {'path':directory, 'comment':'Exported directory ' + directory, 'read only':'Yes'}, dbus_interface='org.opensuse.YaST.Values'); + try: + result = samba.AddShare(share_name, {'path':directory, 'comment':'Exported directory ' + directory, 'read only':'Yes'}, dbus_interface='org.opensuse.YaST.Values'); + except dbus.exceptions.DBusException, e: + if e.get_dbus_name() == 'org.freedesktop.PolicyKit.Error.NotAuthorized': + message = e.get_dbus_message() + + # get result and action name + parts = re.split(' +', message) + + if len(parts) == 2: + if re.match("auth_.*", parts[1]): + print 'Authorization ' + parts[0] + ' is needed' + + if os.system('polkit-auth --obtain ' + parts[0]) == 0: + try: + result = samba.AddShare(share_name, {'path':directory, 'comment':'Exported directory ' + directory, 'read only':'Yes'}, dbus_interface='org.opensuse.YaST.Values'); + except dbus.exceptions.DBusException, e: + exit(1) + else: + print 'PolicyKit error: ' + message + exit(1) + else: + print 'DBus error:' + print e.message + exit(1) + else: print 'Error: missing argument' exit(1) -- To unsubscribe, e-mail: yast-commit+unsubscribe@opensuse.org For additional commands, e-mail: yast-commit+help@opensuse.org