#!/usr/bin/env python

"""
(c) 2010 Andreas Boehler, andy (dot) boehler (at) gmx (dot) at

Execute program via DBus' System Bus. Run dbus-exec-server.py 
on startup in your WM and use dbus-exec.py to execute your
programs as root user.

v0.01, 2010/03/21
Initial Release

"""

import sys
from traceback import print_exc

import dbus

def main():
    bus = dbus.SystemBus()
    


    try:
        remote_object = bus.get_object("org.dyndns.klasseonline.dbus_exec",
                                       "/exec")
        if sys.argv[1:] == ['--exit-service']:
            remote_object.Exit(dbus_interface = 'org.dyndns.klasseonline.dbus_exec')
            sys.exit(1)
            
        # you can either specify the dbus_interface in each call...
        retcode = remote_object.execute(sys.argv[1:], 
            dbus_interface = 'org.dyndns.klasseonline.dbus_exec')
    except dbus.DBusException:
        print_exc()
        sys.exit(1)

    print retcode



if __name__ == '__main__':
    main()

