Mercurial > libervia-desktop-kivy
annotate service/main.py @ 402:ab1e97b7e8a5
core: log parse config files
author | Goffi <goffi@goffi.org> |
---|---|
date | Wed, 12 Feb 2020 20:02:58 +0100 |
parents | bbf992b0be0d |
children | 203755bbe0fe |
rev | line source |
---|---|
369
bbf992b0be0d
android (service): set autorestart:
Goffi <goffi@goffi.org>
parents:
359
diff
changeset
|
1 #!/usr/bin/env python3 |
64
8e16abcadbb8
core: launch SàT backend as a service on Android and wait for it on pb bridge connection.
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
2 |
8e16abcadbb8
core: launch SàT backend as a service on Android and wait for it on pb bridge connection.
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
3 # Cagou: desktop/mobile frontend for Salut à Toi XMPP client |
126 | 4 # Copyright (C) 2016-2018 Jérôme Poisson (goffi@goffi.org) |
64
8e16abcadbb8
core: launch SàT backend as a service on Android and wait for it on pb bridge connection.
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
5 |
8e16abcadbb8
core: launch SàT backend as a service on Android and wait for it on pb bridge connection.
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
6 # This program is free software: you can redistribute it and/or modify |
8e16abcadbb8
core: launch SàT backend as a service on Android and wait for it on pb bridge connection.
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
7 # it under the terms of the GNU Affero General Public License as published by |
8e16abcadbb8
core: launch SàT backend as a service on Android and wait for it on pb bridge connection.
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
8 # the Free Software Foundation, either version 3 of the License, or |
8e16abcadbb8
core: launch SàT backend as a service on Android and wait for it on pb bridge connection.
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
9 # (at your option) any later version. |
8e16abcadbb8
core: launch SàT backend as a service on Android and wait for it on pb bridge connection.
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
10 |
8e16abcadbb8
core: launch SàT backend as a service on Android and wait for it on pb bridge connection.
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
11 # This program is distributed in the hope that it will be useful, |
8e16abcadbb8
core: launch SàT backend as a service on Android and wait for it on pb bridge connection.
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of |
8e16abcadbb8
core: launch SàT backend as a service on Android and wait for it on pb bridge connection.
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
8e16abcadbb8
core: launch SàT backend as a service on Android and wait for it on pb bridge connection.
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
14 # GNU Affero General Public License for more details. |
8e16abcadbb8
core: launch SàT backend as a service on Android and wait for it on pb bridge connection.
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
15 |
8e16abcadbb8
core: launch SàT backend as a service on Android and wait for it on pb bridge connection.
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
16 # You should have received a copy of the GNU Affero General Public License |
8e16abcadbb8
core: launch SàT backend as a service on Android and wait for it on pb bridge connection.
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
17 # along with this program. If not, see <http://www.gnu.org/licenses/>. |
8e16abcadbb8
core: launch SàT backend as a service on Android and wait for it on pb bridge connection.
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
18 |
8e16abcadbb8
core: launch SàT backend as a service on Android and wait for it on pb bridge connection.
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
19 import sys |
8e16abcadbb8
core: launch SàT backend as a service on Android and wait for it on pb bridge connection.
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
20 import os |
8e16abcadbb8
core: launch SàT backend as a service on Android and wait for it on pb bridge connection.
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
21 # we want the service to access the modules from parent dir (sat, etc.) |
8e16abcadbb8
core: launch SàT backend as a service on Android and wait for it on pb bridge connection.
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
22 os.chdir('..') |
8e16abcadbb8
core: launch SàT backend as a service on Android and wait for it on pb bridge connection.
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
23 sys.path.insert(0, '') |
8e16abcadbb8
core: launch SàT backend as a service on Android and wait for it on pb bridge connection.
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
24 from sat.core.constants import Const as C |
8e16abcadbb8
core: launch SàT backend as a service on Android and wait for it on pb bridge connection.
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
25 from sat.core import log_config |
8e16abcadbb8
core: launch SàT backend as a service on Android and wait for it on pb bridge connection.
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
26 # SàT log conf must be done before calling Kivy |
8e16abcadbb8
core: launch SàT backend as a service on Android and wait for it on pb bridge connection.
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
27 log_config.satConfigure(C.LOG_BACKEND_STANDARD, C) |
8e16abcadbb8
core: launch SàT backend as a service on Android and wait for it on pb bridge connection.
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
28 # if this module is called, we should be on android, |
8e16abcadbb8
core: launch SàT backend as a service on Android and wait for it on pb bridge connection.
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
29 # but just in case... |
8e16abcadbb8
core: launch SàT backend as a service on Android and wait for it on pb bridge connection.
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
30 from kivy import utils as kivy_utils |
8e16abcadbb8
core: launch SàT backend as a service on Android and wait for it on pb bridge connection.
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
31 if kivy_utils.platform == "android": |
8e16abcadbb8
core: launch SàT backend as a service on Android and wait for it on pb bridge connection.
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
32 # sys.platform is "linux" on android by default |
8e16abcadbb8
core: launch SàT backend as a service on Android and wait for it on pb bridge connection.
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
33 # so we change it to allow backend to detect android |
8e16abcadbb8
core: launch SàT backend as a service on Android and wait for it on pb bridge connection.
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
34 sys.platform = "android" |
318
834d5c267219
core: fixed state encoding + PLUGIN_EXT on Android following Python 3 port
Goffi <goffi@goffi.org>
parents:
126
diff
changeset
|
35 C.PLUGIN_EXT = "pyc" |
64
8e16abcadbb8
core: launch SàT backend as a service on Android and wait for it on pb bridge connection.
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
36 from sat.core import sat_main |
8e16abcadbb8
core: launch SàT backend as a service on Android and wait for it on pb bridge connection.
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
37 from twisted.internet import reactor |
359
38d763febed6
android (service): fixed backend launch
Goffi <goffi@goffi.org>
parents:
318
diff
changeset
|
38 from twisted.application import app, service |
369
bbf992b0be0d
android (service): set autorestart:
Goffi <goffi@goffi.org>
parents:
359
diff
changeset
|
39 from jnius import autoclass |
bbf992b0be0d
android (service): set autorestart:
Goffi <goffi@goffi.org>
parents:
359
diff
changeset
|
40 |
bbf992b0be0d
android (service): set autorestart:
Goffi <goffi@goffi.org>
parents:
359
diff
changeset
|
41 |
bbf992b0be0d
android (service): set autorestart:
Goffi <goffi@goffi.org>
parents:
359
diff
changeset
|
42 PythonService = autoclass('org.kivy.android.PythonService') |
bbf992b0be0d
android (service): set autorestart:
Goffi <goffi@goffi.org>
parents:
359
diff
changeset
|
43 PythonService.mService.setAutoRestartService(True) |
bbf992b0be0d
android (service): set autorestart:
Goffi <goffi@goffi.org>
parents:
359
diff
changeset
|
44 |
64
8e16abcadbb8
core: launch SàT backend as a service on Android and wait for it on pb bridge connection.
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
45 |
8e16abcadbb8
core: launch SàT backend as a service on Android and wait for it on pb bridge connection.
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
46 sat = sat_main.SAT() |
359
38d763febed6
android (service): fixed backend launch
Goffi <goffi@goffi.org>
parents:
318
diff
changeset
|
47 application = service.Application("SàT backend") |
38d763febed6
android (service): fixed backend launch
Goffi <goffi@goffi.org>
parents:
318
diff
changeset
|
48 sat.setServiceParent(application) |
38d763febed6
android (service): fixed backend launch
Goffi <goffi@goffi.org>
parents:
318
diff
changeset
|
49 app.startApplication(application, None) |
64
8e16abcadbb8
core: launch SàT backend as a service on Android and wait for it on pb bridge connection.
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
50 reactor.run() |