comparison sat/core/constants.py @ 2562:26edcf3a30eb

core, setup: huge cleaning: - moved directories from src and frontends/src to sat and sat_frontends, which is the recommanded naming convention - move twisted directory to root - removed all hacks from setup.py, and added missing dependencies, it is now clean - use https URL for website in setup.py - removed "Environment :: X11 Applications :: GTK", as wix is deprecated and removed - renamed sat.sh to sat and fixed its installation - added python_requires to specify Python version needed - replaced glib2reactor which use deprecated code by gtk3reactor sat can now be installed directly from virtualenv without using --system-site-packages anymore \o/
author Goffi <goffi@goffi.org>
date Mon, 02 Apr 2018 19:44:50 +0200
parents src/core/constants.py@e96076cdf74c
children ea106dfa2145
comparison
equal deleted inserted replaced
2561:bd30dc3ffe5a 2562:26edcf3a30eb
1 #!/usr/bin/env python2
2 # -*- coding: utf-8 -*-
3
4 # SàT: a XMPP client
5 # Copyright (C) 2009-2018 Jérôme Poisson (goffi@goffi.org)
6
7 # This program is free software: you can redistribute it and/or modify
8 # it under the terms of the GNU Affero General Public License as published by
9 # the Free Software Foundation, either version 3 of the License, or
10 # (at your option) any later version.
11
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU Affero General Public License for more details.
16
17 # You should have received a copy of the GNU Affero General Public License
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
19
20 try:
21 from xdg import BaseDirectory
22 from os.path import expanduser, realpath
23 except ImportError:
24 BaseDirectory = None
25
26
27 class Const(object):
28
29 ## Application ##
30 APP_NAME = u'Salut à Toi'
31 APP_NAME_SHORT = u'SàT'
32 APP_NAME_FILE = u'sat'
33 APP_NAME_FULL = u'%s (%s)' % (APP_NAME_SHORT, APP_NAME)
34 APP_VERSION = u'0.7.0D' # Please add 'D' at the end for dev versions
35 APP_RELEASE_NAME = u'La Commune'
36 APP_URL = u'http://salut-a-toi.org'
37
38
39 ## Runtime ##
40 PLUGIN_EXT = "py"
41 HISTORY_SKIP = u'skip'
42
43 ## Main config ##
44 DEFAULT_BRIDGE = 'dbus'
45
46
47 ## Protocol ##
48 XMPP_C2S_PORT = 5222
49 XMPP_KEEP_ALIFE = 180
50 XMPP_MAX_RETRIES = 2
51 # default port used on Prosody, may differ on other servers
52 XMPP_COMPONENT_PORT = 5347
53
54
55 ## Parameters ##
56 NO_SECURITY_LIMIT = -1 # FIXME: to rename
57 SECURITY_LIMIT_MAX = 0
58 INDIVIDUAL = "individual"
59 GENERAL = "general"
60 # General parameters
61 HISTORY_LIMIT = "History"
62 SHOW_OFFLINE_CONTACTS = "Offline contacts"
63 SHOW_EMPTY_GROUPS = "Empty groups"
64 # Parameters related to connection
65 FORCE_SERVER_PARAM = "Force server"
66 FORCE_PORT_PARAM = "Force port"
67 # Parameters related to encryption
68 PROFILE_PASS_PATH = ('General', 'Password')
69 MEMORY_CRYPTO_NAMESPACE = 'crypto' # for the private persistent binary dict
70 MEMORY_CRYPTO_KEY = 'personal_key'
71 # Parameters for static blog pages
72 # FIXME: blog constants should not be in core constants
73 STATIC_BLOG_KEY = "Blog page"
74 STATIC_BLOG_PARAM_TITLE = "Title"
75 STATIC_BLOG_PARAM_BANNER = "Banner"
76 STATIC_BLOG_PARAM_KEYWORDS = "Keywords"
77 STATIC_BLOG_PARAM_DESCRIPTION = "Description"
78
79
80 ## Menus ##
81 MENU_GLOBAL = "GLOBAL"
82 MENU_ROOM = "ROOM"
83 MENU_SINGLE = "SINGLE"
84 MENU_JID_CONTEXT = "JID_CONTEXT"
85 MENU_ROSTER_JID_CONTEXT = "ROSTER_JID_CONTEXT"
86 MENU_ROSTER_GROUP_CONTEXT = "MENU_ROSTER_GROUP_CONTEXT"
87 MENU_ROOM_OCCUPANT_CONTEXT = "MENU_ROOM_OCCUPANT_CONTEXT"
88
89
90 ## Profile and entities ##
91 PROF_KEY_NONE = '@NONE@'
92 PROF_KEY_DEFAULT = '@DEFAULT@'
93 PROF_KEY_ALL = '@ALL@'
94 ENTITY_ALL = '@ALL@'
95 ENTITY_ALL_RESOURCES = '@ALL_RESOURCES@'
96 ENTITY_MAIN_RESOURCE = '@MAIN_RESOURCE@'
97 ENTITY_CAP_HASH = 'CAP_HASH'
98 ENTITY_TYPE = 'TYPE'
99
100
101 ## Roster jids selection ##
102 PUBLIC = 'PUBLIC'
103 ALL = 'ALL' # ALL means all known contacts, while PUBLIC means everybody, known or not
104 GROUP = 'GROUP'
105 JID = 'JID'
106
107
108 ## Messages ##
109 MESS_TYPE_INFO = 'info'
110 MESS_TYPE_CHAT = 'chat'
111 MESS_TYPE_ERROR = 'error'
112 MESS_TYPE_GROUPCHAT = 'groupchat'
113 MESS_TYPE_HEADLINE = 'headline'
114 MESS_TYPE_NORMAL = 'normal'
115 MESS_TYPE_AUTO = 'auto' # magic value to let the backend guess the type
116 MESS_TYPE_STANDARD = (MESS_TYPE_CHAT, MESS_TYPE_ERROR, MESS_TYPE_GROUPCHAT, MESS_TYPE_HEADLINE, MESS_TYPE_NORMAL)
117 MESS_TYPE_ALL = MESS_TYPE_STANDARD + (MESS_TYPE_INFO, MESS_TYPE_AUTO)
118
119 MESS_EXTRA_INFO = "info_type"
120
121
122 ## Chat ##
123 CHAT_ONE2ONE = 'one2one'
124 CHAT_GROUP = 'group'
125
126
127 ## Presence ##
128 PRESENCE_UNAVAILABLE = 'unavailable'
129 PRESENCE_SHOW_AWAY = 'away'
130 PRESENCE_SHOW_CHAT = 'chat'
131 PRESENCE_SHOW_DND = 'dnd'
132 PRESENCE_SHOW_XA = 'xa'
133 PRESENCE_SHOW = 'show'
134 PRESENCE_STATUSES = 'statuses'
135 PRESENCE_STATUSES_DEFAULT = 'default'
136 PRESENCE_PRIORITY = 'priority'
137
138
139 ## Common namespaces ##
140 NS_XML = 'http://www.w3.org/XML/1998/namespace'
141 NS_CLIENT = 'jabber:client'
142 NS_FORWARD = 'urn:xmpp:forward:0'
143 NS_DELAY = 'urn:xmpp:delay'
144 NS_XHTML = 'http://www.w3.org/1999/xhtml'
145
146 ## Common XPath ##
147
148 IQ_GET = '/iq[@type="get"]'
149 IQ_SET = '/iq[@type="set"]'
150
151 ## Directories ##
152
153 # directory for components specific data
154 COMPONENTS_DIR = u'components'
155 CACHE_DIR = u'cache'
156 # files in file dir are stored for long term
157 # files dir is global, i.e. for all profiles
158 FILES_DIR = u'files'
159 # FILES_LINKS_DIR is a directory where files owned by a specific profile
160 # are linked to the global files directory. This way the directory can be
161 # shared per profiles while keeping global directory where identical files
162 # shared between different profiles are not duplicated.
163 FILES_LINKS_DIR = u'files_links'
164 # FILES_TMP_DIR is where profile's partially transfered files are put.
165 # Once transfer is completed, they are moved to FILES_DIR
166 FILES_TMP_DIR = u'files_tmp'
167
168
169 ## Configuration ##
170 if BaseDirectory: # skipped when xdg module is not available (should not happen in backend)
171 if "org.goffi.cagou.cagou" in BaseDirectory.__file__:
172 # FIXME: hack to make config read from the right location on Android
173 # TODO: fix it in a more proper way
174 BaseDirectory = None
175 DEFAULT_CONFIG = {
176 'local_dir': '/data/data/org.goffi.cagou.cagou/',
177 'media_dir': '/data/data/org.goffi.cagou.cagou/files/media',
178 'pid_dir': '%(local_dir)s',
179 'log_dir': '%(local_dir)s',
180 }
181 CONFIG_FILES = ['/data/data/org.goffi.cagou.cagou/files/platform/android/' + APP_NAME_FILE + '.conf']
182 else:
183
184 ## Configuration ##
185 DEFAULT_CONFIG = {
186 'media_dir': '/usr/share/' + APP_NAME_FILE + '/media',
187 'local_dir': BaseDirectory.save_data_path(APP_NAME_FILE),
188 'pid_dir': '%(local_dir)s',
189 'log_dir': '%(local_dir)s',
190 }
191
192 # List of the configuration filenames sorted by ascending priority
193 CONFIG_FILES = [realpath(expanduser(path) + APP_NAME_FILE + '.conf') for path in
194 ['/etc/', '~/', '~/.', '', '.'] +
195 ['%s/' % path for path in list(BaseDirectory.load_config_paths(APP_NAME_FILE))]
196 ]
197
198 ## Templates ##
199 TEMPLATE_THEME_DEFAULT = u'default'
200 TEMPLATE_STATIC_DIR = u'static'
201
202
203 ## Plugins ##
204
205 # PLUGIN_INFO keys
206 # XXX: we use PI instead of PLUG_INFO which would normally be used
207 # to make the header more readable
208 PI_NAME = u'name'
209 PI_IMPORT_NAME = u'import_name'
210 PI_MAIN = u'main'
211 PI_HANDLER = u'handler'
212 PI_TYPE = u'type' # FIXME: should be types, and should handle single unicode type or tuple of types (e.g. "blog" and "import")
213 PI_MODES = u'modes'
214 PI_PROTOCOLS = u'protocols'
215 PI_DEPENDENCIES = u'dependencies'
216 PI_RECOMMENDATIONS = u'recommendations'
217 PI_DESCRIPTION = u'description'
218 PI_USAGE = u'usage'
219
220 # Types
221 PLUG_TYPE_XEP = "XEP"
222 PLUG_TYPE_MISC = "MISC"
223 PLUG_TYPE_EXP = "EXP"
224 PLUG_TYPE_SEC = "SEC"
225 PLUG_TYPE_SYNTAXE = "SYNTAXE"
226 PLUG_TYPE_BLOG = "BLOG"
227 PLUG_TYPE_IMPORT = "IMPORT"
228 PLUG_TYPE_ENTRY_POINT = "ENTRY_POINT"
229
230 # Modes
231 PLUG_MODE_CLIENT = "client"
232 PLUG_MODE_COMPONENT = "component"
233 PLUG_MODE_DEFAULT = (PLUG_MODE_CLIENT,)
234 PLUG_MODE_BOTH = (PLUG_MODE_CLIENT, PLUG_MODE_COMPONENT)
235
236 # names of widely used plugins
237 TEXT_CMDS = 'TEXT-COMMANDS'
238
239 # PubSub event categories
240 PS_PEP = "PEP"
241 PS_MICROBLOG = "MICROBLOG"
242
243 # PubSub
244 PS_PUBLISH = "publish"
245 PS_RETRACT = "retract" # used for items
246 PS_DELETE = "delete" # used for nodes
247 PS_ITEM = "item"
248 PS_ITEMS = "items" # Can contain publish and retract items
249 PS_EVENTS = (PS_ITEMS, PS_DELETE)
250
251
252 ## XMLUI ##
253 XMLUI_WINDOW = 'window'
254 XMLUI_POPUP = 'popup'
255 XMLUI_FORM = 'form'
256 XMLUI_PARAM = 'param'
257 XMLUI_DIALOG = 'dialog'
258 XMLUI_DIALOG_CONFIRM = "confirm"
259 XMLUI_DIALOG_MESSAGE = "message"
260 XMLUI_DIALOG_NOTE = "note"
261 XMLUI_DIALOG_FILE = "file"
262 XMLUI_DATA_ANSWER = "answer"
263 XMLUI_DATA_CANCELLED = "cancelled"
264 XMLUI_DATA_TYPE = "type"
265 XMLUI_DATA_MESS = "message"
266 XMLUI_DATA_LVL = "level"
267 XMLUI_DATA_LVL_INFO = "info"
268 XMLUI_DATA_LVL_WARNING = "warning"
269 XMLUI_DATA_LVL_ERROR = "error"
270 XMLUI_DATA_LVL_DEFAULT = XMLUI_DATA_LVL_INFO
271 XMLUI_DATA_LVLS = (XMLUI_DATA_LVL_INFO, XMLUI_DATA_LVL_WARNING, XMLUI_DATA_LVL_ERROR)
272 XMLUI_DATA_BTNS_SET = "buttons_set"
273 XMLUI_DATA_BTNS_SET_OKCANCEL = "ok/cancel"
274 XMLUI_DATA_BTNS_SET_YESNO = "yes/no"
275 XMLUI_DATA_BTNS_SET_DEFAULT = XMLUI_DATA_BTNS_SET_OKCANCEL
276 XMLUI_DATA_FILETYPE = 'filetype'
277 XMLUI_DATA_FILETYPE_FILE = "file"
278 XMLUI_DATA_FILETYPE_DIR = "dir"
279 XMLUI_DATA_FILETYPE_DEFAULT = XMLUI_DATA_FILETYPE_FILE
280
281
282 ## Logging ##
283 LOG_LVL_DEBUG = 'DEBUG'
284 LOG_LVL_INFO = 'INFO'
285 LOG_LVL_WARNING = 'WARNING'
286 LOG_LVL_ERROR = 'ERROR'
287 LOG_LVL_CRITICAL = 'CRITICAL'
288 LOG_LEVELS = (LOG_LVL_DEBUG, LOG_LVL_INFO, LOG_LVL_WARNING, LOG_LVL_ERROR, LOG_LVL_CRITICAL)
289 LOG_BACKEND_STANDARD = 'standard'
290 LOG_BACKEND_TWISTED = 'twisted'
291 LOG_BACKEND_BASIC = 'basic'
292 LOG_BACKEND_CUSTOM = 'custom'
293 LOG_BASE_LOGGER = 'root'
294 LOG_TWISTED_LOGGER = 'twisted'
295 LOG_OPT_SECTION = 'DEFAULT' # section of sat.conf where log options should be
296 LOG_OPT_PREFIX = 'log_'
297 # (option_name, default_value) tuples
298 LOG_OPT_COLORS = ('colors', 'true') # true for auto colors, force to have colors even if stdout is not a tty, false for no color
299 LOG_OPT_TAINTS_DICT = ('levels_taints_dict', {
300 LOG_LVL_DEBUG: ('cyan',),
301 LOG_LVL_INFO: (),
302 LOG_LVL_WARNING: ('yellow',),
303 LOG_LVL_ERROR: ('red', 'blink', r'/!\ ', 'blink_off'),
304 LOG_LVL_CRITICAL: ('bold', 'red', 'Guru Meditation ', 'normal_weight')
305 })
306 LOG_OPT_LEVEL = ('level', 'info')
307 LOG_OPT_FORMAT = ('fmt', '%(message)s') # similar to logging format.
308 LOG_OPT_LOGGER = ('logger', '') # regex to filter logger name
309 LOG_OPT_OUTPUT_SEP = '//'
310 LOG_OPT_OUTPUT_DEFAULT = 'default'
311 LOG_OPT_OUTPUT_MEMORY = 'memory'
312 LOG_OPT_OUTPUT_MEMORY_LIMIT = 50
313 LOG_OPT_OUTPUT_FILE = 'file' # file is implicit if only output
314 LOG_OPT_OUTPUT = ('output', LOG_OPT_OUTPUT_SEP + LOG_OPT_OUTPUT_DEFAULT) # //default = normal output (stderr or a file with twistd), path/to/file for a file (must be the first if used), //memory for memory (options can be put in parenthesis, e.g.: //memory(500) for a 500 lines memory)
315
316
317 ## action constants ##
318 META_TYPE_FILE = "file"
319 META_TYPE_OVERWRITE = "overwrite"
320
321
322 ## HARD-CODED ACTIONS IDS (generated with uuid.uuid4) ##
323 AUTHENTICATE_PROFILE_ID = u'b03bbfa8-a4ae-4734-a248-06ce6c7cf562'
324 CHANGE_XMPP_PASSWD_ID = u'878b9387-de2b-413b-950f-e424a147bcd0'
325
326
327 ## Text values ##
328 BOOL_TRUE = "true"
329 BOOL_FALSE = "false"
330
331
332 ## Special values used in bridge methods calls ##
333 HISTORY_LIMIT_DEFAULT = -1
334 HISTORY_LIMIT_NONE = -2
335
336
337 ## Progress error special values ##
338 PROGRESS_ERROR_DECLINED = u'declined' # session has been declined by peer user
339
340
341 ## Files ##
342 FILE_TYPE_DIRECTORY = 'directory'
343 FILE_TYPE_FILE = 'file'
344
345
346 ## Permissions management ##
347 ACCESS_PERM_READ = u'read'
348 ACCESS_PERM_WRITE = u'write'
349 ACCESS_PERMS = {ACCESS_PERM_READ, ACCESS_PERM_WRITE}
350 ACCESS_TYPE_PUBLIC = u'public'
351 ACCESS_TYPE_WHITELIST = u'whitelist'
352 ACCESS_TYPES = (ACCESS_TYPE_PUBLIC, ACCESS_TYPE_WHITELIST)
353
354
355 ## Common data keys ##
356 KEY_THUMBNAILS = u'thumbnails'
357 KEY_PROGRESS_ID = u'progress_id'
358
359
360 ## Misc ##
361 SAVEFILE_DATABASE = APP_NAME_FILE + ".db"
362 IQ_SET = '/iq[@type="set"]'
363 ENV_PREFIX = 'SAT_' # Prefix used for environment variables
364 IGNORE = 'ignore'
365 NO_LIMIT = -1 # used in bridge when a integer value is expected
366 DEFAULT_MAX_AGE = 1209600 # default max age of cached files, in seconds
367 HASH_SHA1_EMPTY = 'da39a3ee5e6b4b0d3255bfef95601890afd80709'
368
369 @classmethod
370 def LOG_OPTIONS(cls):
371 """Return options checked for logs"""
372 # XXX: we use a classmethod so we can use Const inheritance to change default options
373 return(cls.LOG_OPT_COLORS, cls.LOG_OPT_TAINTS_DICT, cls.LOG_OPT_LEVEL, cls.LOG_OPT_FORMAT, cls.LOG_OPT_LOGGER, cls.LOG_OPT_OUTPUT)
374
375 @classmethod
376 def bool(cls, value):
377 """@return (bool): bool value for associated constant"""
378 assert isinstance(value, basestring)
379 return value.lower() in (cls.BOOL_TRUE, "1", "yes")
380
381 @classmethod
382 def boolConst(cls, value):
383 """@return (str): constant associated to bool value"""
384 assert isinstance(value, bool)
385 return cls.BOOL_TRUE if value else cls.BOOL_FALSE