annotate service/main.py @ 359:38d763febed6

android (service): fixed backend launch
author Goffi <goffi@goffi.org>
date Sat, 18 Jan 2020 23:12:52 +0100
parents 834d5c267219
children bbf992b0be0d
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
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
1 #!/usr//bin/env python2
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 # -*- coding: utf-8 -*-
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
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
4 # Cagou: desktop/mobile frontend for Salut à Toi XMPP client
126
cd99f70ea592 global file reorganisation:
Goffi <goffi@goffi.org>
parents: 87
diff changeset
5 # 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
6
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 # 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
8 # 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
9 # 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
10 # (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
11
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 # 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
13 # 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
14 # 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
15 # 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
16
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 # 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
18 # 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
19
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 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
21 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
22 # 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
23 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
24 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
25 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
26 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
27 # 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
28 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
29 # 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
30 # 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
31 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
32 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
33 # 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
34 # 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
35 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
36 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
37 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
38 from twisted.internet import reactor
359
38d763febed6 android (service): fixed backend launch
Goffi <goffi@goffi.org>
parents: 318
diff changeset
39 from twisted.application import app, service
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
40
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
41 sat = sat_main.SAT()
359
38d763febed6 android (service): fixed backend launch
Goffi <goffi@goffi.org>
parents: 318
diff changeset
42 application = service.Application("SàT backend")
38d763febed6 android (service): fixed backend launch
Goffi <goffi@goffi.org>
parents: 318
diff changeset
43 sat.setServiceParent(application)
38d763febed6 android (service): fixed backend launch
Goffi <goffi@goffi.org>
parents: 318
diff changeset
44 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
45 reactor.run()