annotate cagou/core/kivy_hack.py @ 439:12d188cb1206

core: use of new profileConnected method: bookmarks cache is now retrieved in profileConnected, as getting it in ProfilePlugged could result in an exception is client was not fully connected (if plugins were not all initialised).
author Goffi <goffi@goffi.org>
date Sat, 07 Mar 2020 00:05:49 +0100
parents 1da3c379205b
children 3c9ba4a694ef
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
6
85649eca9f9b core (logs): integrate Kivy logs with SàT:
Goffi <goffi@goffi.org>
parents:
diff changeset
1 #!/usr//bin/env python2
379
1da3c379205b fixed shebangs
Goffi <goffi@goffi.org>
parents: 378
diff changeset
2
6
85649eca9f9b core (logs): integrate Kivy logs with SàT:
Goffi <goffi@goffi.org>
parents:
diff changeset
3
85649eca9f9b core (logs): integrate Kivy logs with SàT:
Goffi <goffi@goffi.org>
parents:
diff changeset
4 # Cagou: desktop/mobile frontend for Salut à Toi XMPP client
378
4d660b252487 dates update
Goffi <goffi@goffi.org>
parents: 312
diff changeset
5 # Copyright (C) 2016-2020 Jérôme Poisson (goffi@goffi.org)
6
85649eca9f9b core (logs): integrate Kivy logs with SàT:
Goffi <goffi@goffi.org>
parents:
diff changeset
6
85649eca9f9b core (logs): integrate Kivy logs with SàT:
Goffi <goffi@goffi.org>
parents:
diff changeset
7 # This program is free software: you can redistribute it and/or modify
85649eca9f9b core (logs): integrate Kivy logs with SàT:
Goffi <goffi@goffi.org>
parents:
diff changeset
8 # it under the terms of the GNU Affero General Public License as published by
85649eca9f9b core (logs): integrate Kivy logs with SàT:
Goffi <goffi@goffi.org>
parents:
diff changeset
9 # the Free Software Foundation, either version 3 of the License, or
85649eca9f9b core (logs): integrate Kivy logs with SàT:
Goffi <goffi@goffi.org>
parents:
diff changeset
10 # (at your option) any later version.
85649eca9f9b core (logs): integrate Kivy logs with SàT:
Goffi <goffi@goffi.org>
parents:
diff changeset
11
85649eca9f9b core (logs): integrate Kivy logs with SàT:
Goffi <goffi@goffi.org>
parents:
diff changeset
12 # This program is distributed in the hope that it will be useful,
85649eca9f9b core (logs): integrate Kivy logs with SàT:
Goffi <goffi@goffi.org>
parents:
diff changeset
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
85649eca9f9b core (logs): integrate Kivy logs with SàT:
Goffi <goffi@goffi.org>
parents:
diff changeset
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
85649eca9f9b core (logs): integrate Kivy logs with SàT:
Goffi <goffi@goffi.org>
parents:
diff changeset
15 # GNU Affero General Public License for more details.
85649eca9f9b core (logs): integrate Kivy logs with SàT:
Goffi <goffi@goffi.org>
parents:
diff changeset
16
85649eca9f9b core (logs): integrate Kivy logs with SàT:
Goffi <goffi@goffi.org>
parents:
diff changeset
17 # You should have received a copy of the GNU Affero General Public License
85649eca9f9b core (logs): integrate Kivy logs with SàT:
Goffi <goffi@goffi.org>
parents:
diff changeset
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
85649eca9f9b core (logs): integrate Kivy logs with SàT:
Goffi <goffi@goffi.org>
parents:
diff changeset
19
85649eca9f9b core (logs): integrate Kivy logs with SàT:
Goffi <goffi@goffi.org>
parents:
diff changeset
20 CONF_KIVY_LEVEL = 'log_kivy_level'
85649eca9f9b core (logs): integrate Kivy logs with SàT:
Goffi <goffi@goffi.org>
parents:
diff changeset
21
48
028a98983e46 core: avoid kivy arguments hijacking so QuickApp arguments parsing can be used
Goffi <goffi@goffi.org>
parents: 15
diff changeset
22
028a98983e46 core: avoid kivy arguments hijacking so QuickApp arguments parsing can be used
Goffi <goffi@goffi.org>
parents: 15
diff changeset
23 def do_hack():
028a98983e46 core: avoid kivy arguments hijacking so QuickApp arguments parsing can be used
Goffi <goffi@goffi.org>
parents: 15
diff changeset
24 """work around Kivy hijacking of logs and arguments"""
028a98983e46 core: avoid kivy arguments hijacking so QuickApp arguments parsing can be used
Goffi <goffi@goffi.org>
parents: 15
diff changeset
25 # we remove args so kivy doesn't use them
028a98983e46 core: avoid kivy arguments hijacking so QuickApp arguments parsing can be used
Goffi <goffi@goffi.org>
parents: 15
diff changeset
26 # this is need to avoid kivy breaking QuickApp args handling
028a98983e46 core: avoid kivy arguments hijacking so QuickApp arguments parsing can be used
Goffi <goffi@goffi.org>
parents: 15
diff changeset
27 import sys
028a98983e46 core: avoid kivy arguments hijacking so QuickApp arguments parsing can be used
Goffi <goffi@goffi.org>
parents: 15
diff changeset
28 ori_argv = sys.argv[:]
028a98983e46 core: avoid kivy arguments hijacking so QuickApp arguments parsing can be used
Goffi <goffi@goffi.org>
parents: 15
diff changeset
29 sys.argv = sys.argv[:1]
312
772c170b47a9 Python3 port:
Goffi <goffi@goffi.org>
parents: 284
diff changeset
30 from .constants import Const as C
6
85649eca9f9b core (logs): integrate Kivy logs with SàT:
Goffi <goffi@goffi.org>
parents:
diff changeset
31 from sat.core import log_config
85649eca9f9b core (logs): integrate Kivy logs with SàT:
Goffi <goffi@goffi.org>
parents:
diff changeset
32 log_config.satConfigure(C.LOG_BACKEND_STANDARD, C)
85649eca9f9b core (logs): integrate Kivy logs with SàT:
Goffi <goffi@goffi.org>
parents:
diff changeset
33
312
772c170b47a9 Python3 port:
Goffi <goffi@goffi.org>
parents: 284
diff changeset
34 from . import config
6
85649eca9f9b core (logs): integrate Kivy logs with SàT:
Goffi <goffi@goffi.org>
parents:
diff changeset
35 kivy_level = config.getConfig(C.CONFIG_SECTION, CONF_KIVY_LEVEL, 'follow').upper()
85649eca9f9b core (logs): integrate Kivy logs with SàT:
Goffi <goffi@goffi.org>
parents:
diff changeset
36
85649eca9f9b core (logs): integrate Kivy logs with SàT:
Goffi <goffi@goffi.org>
parents:
diff changeset
37 # kivy handles its own loggers, we don't want that!
85649eca9f9b core (logs): integrate Kivy logs with SàT:
Goffi <goffi@goffi.org>
parents:
diff changeset
38 import logging
85649eca9f9b core (logs): integrate Kivy logs with SàT:
Goffi <goffi@goffi.org>
parents:
diff changeset
39 root_logger = logging.root
85649eca9f9b core (logs): integrate Kivy logs with SàT:
Goffi <goffi@goffi.org>
parents:
diff changeset
40 kivy_logger = logging.getLogger('kivy')
85649eca9f9b core (logs): integrate Kivy logs with SàT:
Goffi <goffi@goffi.org>
parents:
diff changeset
41 ori_addHandler = kivy_logger.addHandler
284
ca4daced4638 misc: replaced "dummy" by "__"
Goffi <goffi@goffi.org>
parents: 282
diff changeset
42 kivy_logger.addHandler = lambda __: None
6
85649eca9f9b core (logs): integrate Kivy logs with SàT:
Goffi <goffi@goffi.org>
parents:
diff changeset
43 ori_setLevel = kivy_logger.setLevel
85649eca9f9b core (logs): integrate Kivy logs with SàT:
Goffi <goffi@goffi.org>
parents:
diff changeset
44 if kivy_level == 'FOLLOW':
85649eca9f9b core (logs): integrate Kivy logs with SàT:
Goffi <goffi@goffi.org>
parents:
diff changeset
45 # level is following SàT level
85649eca9f9b core (logs): integrate Kivy logs with SàT:
Goffi <goffi@goffi.org>
parents:
diff changeset
46 kivy_logger.setLevel = lambda level: None
85649eca9f9b core (logs): integrate Kivy logs with SàT:
Goffi <goffi@goffi.org>
parents:
diff changeset
47 elif kivy_level == 'KIVY':
85649eca9f9b core (logs): integrate Kivy logs with SàT:
Goffi <goffi@goffi.org>
parents:
diff changeset
48 # level will be set by Kivy according to its own conf
85649eca9f9b core (logs): integrate Kivy logs with SàT:
Goffi <goffi@goffi.org>
parents:
diff changeset
49 pass
85649eca9f9b core (logs): integrate Kivy logs with SàT:
Goffi <goffi@goffi.org>
parents:
diff changeset
50 elif kivy_level in C.LOG_LEVELS:
85649eca9f9b core (logs): integrate Kivy logs with SàT:
Goffi <goffi@goffi.org>
parents:
diff changeset
51 kivy_logger.setLevel(kivy_level)
85649eca9f9b core (logs): integrate Kivy logs with SàT:
Goffi <goffi@goffi.org>
parents:
diff changeset
52 kivy_logger.setLevel = lambda level: None
85649eca9f9b core (logs): integrate Kivy logs with SàT:
Goffi <goffi@goffi.org>
parents:
diff changeset
53 else:
312
772c170b47a9 Python3 port:
Goffi <goffi@goffi.org>
parents: 284
diff changeset
54 raise ValueError("Unknown value for {name}: {value}".format(name=CONF_KIVY_LEVEL, value=kivy_level))
6
85649eca9f9b core (logs): integrate Kivy logs with SàT:
Goffi <goffi@goffi.org>
parents:
diff changeset
55
85649eca9f9b core (logs): integrate Kivy logs with SàT:
Goffi <goffi@goffi.org>
parents:
diff changeset
56 # during import kivy set its logging stuff
85649eca9f9b core (logs): integrate Kivy logs with SàT:
Goffi <goffi@goffi.org>
parents:
diff changeset
57 import kivy
85649eca9f9b core (logs): integrate Kivy logs with SàT:
Goffi <goffi@goffi.org>
parents:
diff changeset
58 kivy # to avoid pyflakes warning
85649eca9f9b core (logs): integrate Kivy logs with SàT:
Goffi <goffi@goffi.org>
parents:
diff changeset
59
85649eca9f9b core (logs): integrate Kivy logs with SàT:
Goffi <goffi@goffi.org>
parents:
diff changeset
60 # we want to separate kivy logs from other logs
85649eca9f9b core (logs): integrate Kivy logs with SàT:
Goffi <goffi@goffi.org>
parents:
diff changeset
61 logging.root = root_logger
7
5ebe1592a05a core (logs): forbid kivy to handle stderr itself
Goffi <goffi@goffi.org>
parents: 6
diff changeset
62 from kivy import logger
5ebe1592a05a core (logs): forbid kivy to handle stderr itself
Goffi <goffi@goffi.org>
parents: 6
diff changeset
63 sys.stderr = logger.previous_stderr
6
85649eca9f9b core (logs): integrate Kivy logs with SàT:
Goffi <goffi@goffi.org>
parents:
diff changeset
64
85649eca9f9b core (logs): integrate Kivy logs with SàT:
Goffi <goffi@goffi.org>
parents:
diff changeset
65 # we restore original methods
85649eca9f9b core (logs): integrate Kivy logs with SàT:
Goffi <goffi@goffi.org>
parents:
diff changeset
66 kivy_logger.addHandler = ori_addHandler
85649eca9f9b core (logs): integrate Kivy logs with SàT:
Goffi <goffi@goffi.org>
parents:
diff changeset
67 kivy_logger.setLevel = ori_setLevel
48
028a98983e46 core: avoid kivy arguments hijacking so QuickApp arguments parsing can be used
Goffi <goffi@goffi.org>
parents: 15
diff changeset
68
028a98983e46 core: avoid kivy arguments hijacking so QuickApp arguments parsing can be used
Goffi <goffi@goffi.org>
parents: 15
diff changeset
69 # we restore original arguments
028a98983e46 core: avoid kivy arguments hijacking so QuickApp arguments parsing can be used
Goffi <goffi@goffi.org>
parents: 15
diff changeset
70 sys.argv = ori_argv