2018-02-02 10:29:00 +01:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
#
|
|
|
|
# This program is free software; you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation; either version 2 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
|
|
|
|
import sys
|
|
|
|
import multiprocessing
|
|
|
|
|
|
|
|
|
|
|
|
def maybe_start_tuhi(queue):
|
|
|
|
should_start = queue.get()
|
|
|
|
|
|
|
|
if not should_start:
|
|
|
|
return
|
|
|
|
|
|
|
|
import tuhi.base
|
|
|
|
tuhi.base.main(['tuhi'])
|
|
|
|
|
|
|
|
|
|
|
|
def main(args=sys.argv):
|
|
|
|
|
|
|
|
queue = multiprocessing.Queue()
|
|
|
|
|
|
|
|
tuhi_process = multiprocessing.Process(target=maybe_start_tuhi, args=(queue,))
|
|
|
|
tuhi_process.daemon = True
|
|
|
|
tuhi_process.start()
|
|
|
|
|
|
|
|
# import after spawning the process, or the 2 processes will fight for GLib
|
2018-03-06 10:00:49 +01:00
|
|
|
import kete
|
2018-02-02 10:29:00 +01:00
|
|
|
from gi.repository import Gio, GLib
|
|
|
|
|
|
|
|
# connect to the session
|
|
|
|
try:
|
|
|
|
connection = Gio.bus_get_sync(Gio.BusType.SESSION, None)
|
|
|
|
except GLib.Error as e:
|
|
|
|
if (e.domain == 'g-io-error-quark' and
|
|
|
|
e.code == Gio.IOErrorEnum.DBUS_ERROR):
|
2018-03-06 10:00:49 +01:00
|
|
|
raise kete.DBusError(e.message)
|
2018-02-02 10:29:00 +01:00
|
|
|
else:
|
|
|
|
raise e
|
|
|
|
|
|
|
|
# attempt to connect to tuhi
|
|
|
|
try:
|
|
|
|
proxy = Gio.DBusProxy.new_sync(connection,
|
|
|
|
Gio.DBusProxyFlags.NONE, None,
|
2018-03-06 10:00:49 +01:00
|
|
|
kete.TUHI_DBUS_NAME,
|
|
|
|
kete.ROOT_PATH,
|
|
|
|
kete.ORG_FREEDESKTOP_TUHI1_MANAGER,
|
2018-02-02 10:29:00 +01:00
|
|
|
None)
|
|
|
|
except GLib.Error as e:
|
|
|
|
if (e.domain == 'g-io-error-quark' and
|
|
|
|
e.code == Gio.IOErrorEnum.DBUS_ERROR):
|
2018-03-06 10:00:49 +01:00
|
|
|
raise kete.DBusError(e.message)
|
2018-02-02 10:29:00 +01:00
|
|
|
else:
|
|
|
|
raise e
|
|
|
|
|
|
|
|
started = proxy.get_name_owner() is not None
|
|
|
|
|
|
|
|
if not started:
|
2018-03-06 10:00:49 +01:00
|
|
|
print(f'No-one is handling {kete.TUHI_DBUS_NAME}, attempting to start a daemon')
|
2018-02-02 10:29:00 +01:00
|
|
|
|
|
|
|
queue.put(not started)
|
|
|
|
|
2018-03-06 10:00:49 +01:00
|
|
|
kete.main(args)
|
2018-02-02 10:29:00 +01:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
main(sys.argv)
|