Mercurial > libervia-backend
annotate src/core/constants.py @ 994:652c01ca69b1
core (log): configuration and environment variables are now checked for log level and colors:
- variable change logs behaviour, so far only level and colors are implemented
- configuration use log_[name], for example you can put log_level=debug in sat.conf (section [DEFAULT]) to see all levels
- environment variables use SAT_LOG_[NAME]: e.g. SAT_LOG_LEVEL=debug
- colors can be true, false or force to force colors even if stdout is not a tty
author | Goffi <goffi@goffi.org> |
---|---|
date | Sat, 19 Apr 2014 20:11:23 +0200 |
parents | 05e02f8b7eb4 |
children | eb3601ff73bc |
rev | line source |
---|---|
914
1a3ba959f0ab
core (memory): moved Params in its own module + introduced a new core/constants module, and moved some constants there
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1 #!/usr/bin/python |
1a3ba959f0ab
core (memory): moved Params in its own module + introduced a new core/constants module, and moved some constants there
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
2 # -*- coding: utf-8 -*- |
1a3ba959f0ab
core (memory): moved Params in its own module + introduced a new core/constants module, and moved some constants there
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
3 |
1a3ba959f0ab
core (memory): moved Params in its own module + introduced a new core/constants module, and moved some constants there
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
4 # SàT: a XMPP client |
1a3ba959f0ab
core (memory): moved Params in its own module + introduced a new core/constants module, and moved some constants there
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
5 # Copyright (C) 2009, 2010, 2011, 2012, 2013, 2014 Jérôme Poisson (goffi@goffi.org) |
1a3ba959f0ab
core (memory): moved Params in its own module + introduced a new core/constants module, and moved some constants there
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
6 |
1a3ba959f0ab
core (memory): moved Params in its own module + introduced a new core/constants module, and moved some constants there
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
7 # This program is free software: you can redistribute it and/or modify |
1a3ba959f0ab
core (memory): moved Params in its own module + introduced a new core/constants module, and moved some constants there
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
8 # it under the terms of the GNU Affero General Public License as published by |
1a3ba959f0ab
core (memory): moved Params in its own module + introduced a new core/constants module, and moved some constants there
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
9 # the Free Software Foundation, either version 3 of the License, or |
1a3ba959f0ab
core (memory): moved Params in its own module + introduced a new core/constants module, and moved some constants there
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
10 # (at your option) any later version. |
1a3ba959f0ab
core (memory): moved Params in its own module + introduced a new core/constants module, and moved some constants there
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
11 |
1a3ba959f0ab
core (memory): moved Params in its own module + introduced a new core/constants module, and moved some constants there
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
12 # This program is distributed in the hope that it will be useful, |
1a3ba959f0ab
core (memory): moved Params in its own module + introduced a new core/constants module, and moved some constants there
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of |
1a3ba959f0ab
core (memory): moved Params in its own module + introduced a new core/constants module, and moved some constants there
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
1a3ba959f0ab
core (memory): moved Params in its own module + introduced a new core/constants module, and moved some constants there
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
15 # GNU Affero General Public License for more details. |
1a3ba959f0ab
core (memory): moved Params in its own module + introduced a new core/constants module, and moved some constants there
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
16 |
1a3ba959f0ab
core (memory): moved Params in its own module + introduced a new core/constants module, and moved some constants there
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
17 # You should have received a copy of the GNU Affero General Public License |
1a3ba959f0ab
core (memory): moved Params in its own module + introduced a new core/constants module, and moved some constants there
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. |
1a3ba959f0ab
core (memory): moved Params in its own module + introduced a new core/constants module, and moved some constants there
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
19 |
930
cbf4122baae7
core, memory: use XDG recommended paths as the defaults for the config and local directories
souliane <souliane@mailoo.org>
parents:
926
diff
changeset
|
20 import os.path |
967
242bd4fc654c
core, frontends (constants): frontends Const inheritates from core Const
souliane <souliane@mailoo.org>
parents:
944
diff
changeset
|
21 try: |
242bd4fc654c
core, frontends (constants): frontends Const inheritates from core Const
souliane <souliane@mailoo.org>
parents:
944
diff
changeset
|
22 from xdg import BaseDirectory |
242bd4fc654c
core, frontends (constants): frontends Const inheritates from core Const
souliane <souliane@mailoo.org>
parents:
944
diff
changeset
|
23 except ImportError: |
242bd4fc654c
core, frontends (constants): frontends Const inheritates from core Const
souliane <souliane@mailoo.org>
parents:
944
diff
changeset
|
24 # Catch JS runtime error while using Libervia |
242bd4fc654c
core, frontends (constants): frontends Const inheritates from core Const
souliane <souliane@mailoo.org>
parents:
944
diff
changeset
|
25 BaseDirectory = None |
930
cbf4122baae7
core, memory: use XDG recommended paths as the defaults for the config and local directories
souliane <souliane@mailoo.org>
parents:
926
diff
changeset
|
26 |
914
1a3ba959f0ab
core (memory): moved Params in its own module + introduced a new core/constants module, and moved some constants there
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
27 |
1a3ba959f0ab
core (memory): moved Params in its own module + introduced a new core/constants module, and moved some constants there
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
28 class Const(object): |
942
598fc223cf59
core: more organisation in constants.py
Goffi <goffi@goffi.org>
parents:
930
diff
changeset
|
29 |
598fc223cf59
core: more organisation in constants.py
Goffi <goffi@goffi.org>
parents:
930
diff
changeset
|
30 ## Application ## |
923 | 31 APP_NAME = u'Salut à Toi' |
32 APP_NAME_SHORT = u'SàT' | |
33 APP_NAME_FULL = u'%s (%s)' % (APP_NAME_SHORT, APP_NAME) | |
967
242bd4fc654c
core, frontends (constants): frontends Const inheritates from core Const
souliane <souliane@mailoo.org>
parents:
944
diff
changeset
|
34 APP_VERSION = u'0.4.1D' # Please add 'D' at the end for dev versions |
242bd4fc654c
core, frontends (constants): frontends Const inheritates from core Const
souliane <souliane@mailoo.org>
parents:
944
diff
changeset
|
35 APP_URL = 'http://salut-a-toi.org' |
942
598fc223cf59
core: more organisation in constants.py
Goffi <goffi@goffi.org>
parents:
930
diff
changeset
|
36 |
994
652c01ca69b1
core (log): configuration and environment variables are now checked for log level and colors:
Goffi <goffi@goffi.org>
parents:
991
diff
changeset
|
37 |
942
598fc223cf59
core: more organisation in constants.py
Goffi <goffi@goffi.org>
parents:
930
diff
changeset
|
38 ## Parameters ## |
598fc223cf59
core: more organisation in constants.py
Goffi <goffi@goffi.org>
parents:
930
diff
changeset
|
39 NO_SECURITY_LIMIT = -1 |
598fc223cf59
core: more organisation in constants.py
Goffi <goffi@goffi.org>
parents:
930
diff
changeset
|
40 INDIVIDUAL = "individual" |
598fc223cf59
core: more organisation in constants.py
Goffi <goffi@goffi.org>
parents:
930
diff
changeset
|
41 GENERAL = "general" |
598fc223cf59
core: more organisation in constants.py
Goffi <goffi@goffi.org>
parents:
930
diff
changeset
|
42 |
598fc223cf59
core: more organisation in constants.py
Goffi <goffi@goffi.org>
parents:
930
diff
changeset
|
43 |
598fc223cf59
core: more organisation in constants.py
Goffi <goffi@goffi.org>
parents:
930
diff
changeset
|
44 ## Profile and entities ## |
598fc223cf59
core: more organisation in constants.py
Goffi <goffi@goffi.org>
parents:
930
diff
changeset
|
45 PROF_KEY_NONE = '@NONE@' |
598fc223cf59
core: more organisation in constants.py
Goffi <goffi@goffi.org>
parents:
930
diff
changeset
|
46 PROF_KEY_DEFAULT = '@DEFAULT@' |
598fc223cf59
core: more organisation in constants.py
Goffi <goffi@goffi.org>
parents:
930
diff
changeset
|
47 ENTITY_ALL = '@ALL@' |
944
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
943
diff
changeset
|
48 ENTITY_LAST_RESOURCE = 'LAST_RESOURCE' |
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
943
diff
changeset
|
49 ENTITY_CAP_HASH = 'CAP_HASH' |
942
598fc223cf59
core: more organisation in constants.py
Goffi <goffi@goffi.org>
parents:
930
diff
changeset
|
50 |
994
652c01ca69b1
core (log): configuration and environment variables are now checked for log level and colors:
Goffi <goffi@goffi.org>
parents:
991
diff
changeset
|
51 |
652c01ca69b1
core (log): configuration and environment variables are now checked for log level and colors:
Goffi <goffi@goffi.org>
parents:
991
diff
changeset
|
52 ## Configuration ## |
967
242bd4fc654c
core, frontends (constants): frontends Const inheritates from core Const
souliane <souliane@mailoo.org>
parents:
944
diff
changeset
|
53 if BaseDirectory: # skipped when imported from Libervia browser_side |
942
598fc223cf59
core: more organisation in constants.py
Goffi <goffi@goffi.org>
parents:
930
diff
changeset
|
54 |
967
242bd4fc654c
core, frontends (constants): frontends Const inheritates from core Const
souliane <souliane@mailoo.org>
parents:
944
diff
changeset
|
55 ## Configuration ## |
242bd4fc654c
core, frontends (constants): frontends Const inheritates from core Const
souliane <souliane@mailoo.org>
parents:
944
diff
changeset
|
56 DEFAULT_CONFIG = { |
242bd4fc654c
core, frontends (constants): frontends Const inheritates from core Const
souliane <souliane@mailoo.org>
parents:
944
diff
changeset
|
57 'media_dir': '/usr/share/sat/media', |
242bd4fc654c
core, frontends (constants): frontends Const inheritates from core Const
souliane <souliane@mailoo.org>
parents:
944
diff
changeset
|
58 'pid_dir': '/tmp', |
242bd4fc654c
core, frontends (constants): frontends Const inheritates from core Const
souliane <souliane@mailoo.org>
parents:
944
diff
changeset
|
59 'log_dir': BaseDirectory.save_data_path('sat'), |
242bd4fc654c
core, frontends (constants): frontends Const inheritates from core Const
souliane <souliane@mailoo.org>
parents:
944
diff
changeset
|
60 } |
923 | 61 |
967
242bd4fc654c
core, frontends (constants): frontends Const inheritates from core Const
souliane <souliane@mailoo.org>
parents:
944
diff
changeset
|
62 # XXX: tmp update code, will be removed in the future |
242bd4fc654c
core, frontends (constants): frontends Const inheritates from core Const
souliane <souliane@mailoo.org>
parents:
944
diff
changeset
|
63 # When you remove this, please add that in DEFAULT_CONFIG: |
242bd4fc654c
core, frontends (constants): frontends Const inheritates from core Const
souliane <souliane@mailoo.org>
parents:
944
diff
changeset
|
64 # 'local_dir': BaseDirectory.save_data_path('sat'), |
242bd4fc654c
core, frontends (constants): frontends Const inheritates from core Const
souliane <souliane@mailoo.org>
parents:
944
diff
changeset
|
65 # and also remove sat.memory.memory.Memory.__fixLocalDir |
242bd4fc654c
core, frontends (constants): frontends Const inheritates from core Const
souliane <souliane@mailoo.org>
parents:
944
diff
changeset
|
66 DEFAULT_LOCAL_DIR = BaseDirectory.save_data_path('sat') |
930
cbf4122baae7
core, memory: use XDG recommended paths as the defaults for the config and local directories
souliane <souliane@mailoo.org>
parents:
926
diff
changeset
|
67 |
967
242bd4fc654c
core, frontends (constants): frontends Const inheritates from core Const
souliane <souliane@mailoo.org>
parents:
944
diff
changeset
|
68 # List of the configuration filenames sorted by ascending priority |
242bd4fc654c
core, frontends (constants): frontends Const inheritates from core Const
souliane <souliane@mailoo.org>
parents:
944
diff
changeset
|
69 CONFIG_FILES = [(os.path.expanduser(path) + 'sat.conf') for path in \ |
242bd4fc654c
core, frontends (constants): frontends Const inheritates from core Const
souliane <souliane@mailoo.org>
parents:
944
diff
changeset
|
70 ['/etc/', '~/', '~/.', '', '.'] + \ |
242bd4fc654c
core, frontends (constants): frontends Const inheritates from core Const
souliane <souliane@mailoo.org>
parents:
944
diff
changeset
|
71 ['%s/' % path for path in list(BaseDirectory.load_config_paths('sat'))] |
994
652c01ca69b1
core (log): configuration and environment variables are now checked for log level and colors:
Goffi <goffi@goffi.org>
parents:
991
diff
changeset
|
72 ] |
652c01ca69b1
core (log): configuration and environment variables are now checked for log level and colors:
Goffi <goffi@goffi.org>
parents:
991
diff
changeset
|
73 |
926
d609581bf74a
plugin text commands: refactoring, text now only contain main commands, and other plugin can add commands themselve:
Goffi <goffi@goffi.org>
parents:
923
diff
changeset
|
74 |
942
598fc223cf59
core: more organisation in constants.py
Goffi <goffi@goffi.org>
parents:
930
diff
changeset
|
75 ## Plugins ## |
926
d609581bf74a
plugin text commands: refactoring, text now only contain main commands, and other plugin can add commands themselve:
Goffi <goffi@goffi.org>
parents:
923
diff
changeset
|
76 # names of widely used plugins |
d609581bf74a
plugin text commands: refactoring, text now only contain main commands, and other plugin can add commands themselve:
Goffi <goffi@goffi.org>
parents:
923
diff
changeset
|
77 TEXT_CMDS = 'TEXT-COMMANDS' |
942
598fc223cf59
core: more organisation in constants.py
Goffi <goffi@goffi.org>
parents:
930
diff
changeset
|
78 |
994
652c01ca69b1
core (log): configuration and environment variables are now checked for log level and colors:
Goffi <goffi@goffi.org>
parents:
991
diff
changeset
|
79 |
991
05e02f8b7eb4
core: logging refactoring, first step:
Goffi <goffi@goffi.org>
parents:
990
diff
changeset
|
80 ## Logging ## |
05e02f8b7eb4
core: logging refactoring, first step:
Goffi <goffi@goffi.org>
parents:
990
diff
changeset
|
81 LOG_BACKEND_STANDARD = 'standard' |
05e02f8b7eb4
core: logging refactoring, first step:
Goffi <goffi@goffi.org>
parents:
990
diff
changeset
|
82 LOG_BACKEND_TWISTED = 'twisted' |
05e02f8b7eb4
core: logging refactoring, first step:
Goffi <goffi@goffi.org>
parents:
990
diff
changeset
|
83 LOG_BACKEND_BASIC = 'basic' |
05e02f8b7eb4
core: logging refactoring, first step:
Goffi <goffi@goffi.org>
parents:
990
diff
changeset
|
84 LOG_BASE_LOGGER = 'root' |
994
652c01ca69b1
core (log): configuration and environment variables are now checked for log level and colors:
Goffi <goffi@goffi.org>
parents:
991
diff
changeset
|
85 LOG_OPT_PREFIX = 'log_' |
652c01ca69b1
core (log): configuration and environment variables are now checked for log level and colors:
Goffi <goffi@goffi.org>
parents:
991
diff
changeset
|
86 # (option_name, default_value) tuples |
652c01ca69b1
core (log): configuration and environment variables are now checked for log level and colors:
Goffi <goffi@goffi.org>
parents:
991
diff
changeset
|
87 LOG_OPT_COLORS = ('colors', 'true') |
652c01ca69b1
core (log): configuration and environment variables are now checked for log level and colors:
Goffi <goffi@goffi.org>
parents:
991
diff
changeset
|
88 LOG_OPT_LEVEL = ('level', 'info') |
652c01ca69b1
core (log): configuration and environment variables are now checked for log level and colors:
Goffi <goffi@goffi.org>
parents:
991
diff
changeset
|
89 |
991
05e02f8b7eb4
core: logging refactoring, first step:
Goffi <goffi@goffi.org>
parents:
990
diff
changeset
|
90 |
942
598fc223cf59
core: more organisation in constants.py
Goffi <goffi@goffi.org>
parents:
930
diff
changeset
|
91 ## Misc ## |
598fc223cf59
core: more organisation in constants.py
Goffi <goffi@goffi.org>
parents:
930
diff
changeset
|
92 SAVEFILE_DATABASE = "sat.db" |
598fc223cf59
core: more organisation in constants.py
Goffi <goffi@goffi.org>
parents:
930
diff
changeset
|
93 IQ_SET = '/iq[@type="set"]' |
994
652c01ca69b1
core (log): configuration and environment variables are now checked for log level and colors:
Goffi <goffi@goffi.org>
parents:
991
diff
changeset
|
94 ENV_PREFIX = 'SAT_' # Prefix used for environment variables |
652c01ca69b1
core (log): configuration and environment variables are now checked for log level and colors:
Goffi <goffi@goffi.org>
parents:
991
diff
changeset
|
95 |
990
f0e407709d8e
core (constants): added some basic ANSI escape codes
Goffi <goffi@goffi.org>
parents:
971
diff
changeset
|
96 |
f0e407709d8e
core (constants): added some basic ANSI escape codes
Goffi <goffi@goffi.org>
parents:
971
diff
changeset
|
97 ## ANSI escape sequences ## |
f0e407709d8e
core (constants): added some basic ANSI escape codes
Goffi <goffi@goffi.org>
parents:
971
diff
changeset
|
98 # XXX: used for logging |
f0e407709d8e
core (constants): added some basic ANSI escape codes
Goffi <goffi@goffi.org>
parents:
971
diff
changeset
|
99 # XXX: there will be probably moved in a dedicated module in the future |
f0e407709d8e
core (constants): added some basic ANSI escape codes
Goffi <goffi@goffi.org>
parents:
971
diff
changeset
|
100 ANSI_RESET = '\033[0m' |
f0e407709d8e
core (constants): added some basic ANSI escape codes
Goffi <goffi@goffi.org>
parents:
971
diff
changeset
|
101 ANSI_NORMAL_WEIGHT = '\033[22m' |
f0e407709d8e
core (constants): added some basic ANSI escape codes
Goffi <goffi@goffi.org>
parents:
971
diff
changeset
|
102 ANSI_FG_BLACK, ANSI_FG_RED, ANSI_FG_GREEN, ANSI_FG_YELLOW, ANSI_FG_BLUE, ANSI_FG_MAGENTA, ANSI_FG_CYAN, ANSI_FG_WHITE = ('\033[3%dm' % nb for nb in xrange(8)) |
f0e407709d8e
core (constants): added some basic ANSI escape codes
Goffi <goffi@goffi.org>
parents:
971
diff
changeset
|
103 ANSI_BOLD = '\033[1m' |
f0e407709d8e
core (constants): added some basic ANSI escape codes
Goffi <goffi@goffi.org>
parents:
971
diff
changeset
|
104 ANSI_BLINK = '\033[5m' |
f0e407709d8e
core (constants): added some basic ANSI escape codes
Goffi <goffi@goffi.org>
parents:
971
diff
changeset
|
105 ANSI_BLINK_OFF = '\033[25m' |