cc1  v2.1
CC1 source code docs
 All Classes Namespaces Files Functions Variables Pages
message.py
Go to the documentation of this file.
1 # -*- coding: utf-8 -*-
2 # @cond LICENSE
3 #
4 # Copyright [2010-2013] Institute of Nuclear Physics PAN, Krakow, Poland
5 #
6 # Licensed under the Apache License, Version 2.0 (the "License");
7 # you may not use this file except in compliance with the License.
8 # You may obtain a copy of the License at
9 #
10 # http://www.apache.org/licenses/LICENSE-2.0
11 #
12 # Unless required by applicable law or agreed to in writing, software
13 # distributed under the License is distributed on an "AS IS" BASIS,
14 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 # See the License for the specific language governing permissions and
16 # limitations under the License.
17 #
18 # @endcond LICENSE
19 
20 ##
21 # @package src.cm.message
22 #
23 from common.states import message_levels
24 
25 from cm.utils import log
26 
27 MESSAGES = {}
28 
29 
30 def add(user_id, data):
31  try:
32  global MESSAGES
33  if user_id not in MESSAGES:
34  MESSAGES[user_id] = []
35  MESSAGES[user_id].append(data)
36  except:
37  log.exception(user_id, 'Add message')
38 
39 
40 def error(user_id, code, params={}):
41  d = {}
42  d['user_id'] = user_id
43  d['level'] = message_levels['error']
44  d['params'] = params
45  d['code'] = code
46  add(user_id, d)
47 
48 
49 def info(user_id, code, params={}):
50  d = {}
51  d['user_id'] = user_id
52  d['level'] = message_levels['info']
53  d['params'] = params
54  d['code'] = code
55  add(user_id, d)
56 
57 
58 def warn(user_id, code, params={}):
59  d = {}
60  d['user_id'] = user_id
61  d['level'] = message_levels['warn']
62  d['params'] = params
63  d['code'] = code
64  add(user_id, d)
65