| OLD | NEW |
| 1 # Copyright 2016 The Chromium Authors. All rights reserved. | 1 # Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
| 4 | 4 |
| 5 """Handles requests to the crash config page.""" | 5 """Handles requests to the crash config page.""" |
| 6 | 6 |
| 7 import json | 7 import json |
| 8 import pickle |
| 9 import re |
| 10 import zlib |
| 8 | 11 |
| 9 from google.appengine.api import users | 12 from google.appengine.api import users |
| 10 | 13 |
| 11 from common.base_handler import BaseHandler | 14 from common.base_handler import BaseHandler |
| 12 from common.base_handler import Permission | 15 from common.base_handler import Permission |
| 13 from model.crash.crash_config import CrashConfig as CrashConfigModel | 16 from model.crash.crash_config import CrashConfig as CrashConfigModel |
| 14 | 17 |
| 15 | 18 |
| 16 class CrashConfig(BaseHandler): | 19 class CrashConfig(BaseHandler): |
| 17 PERMISSION_LEVEL = Permission.ADMIN | 20 PERMISSION_LEVEL = Permission.ADMIN |
| 18 | 21 |
| 19 def HandleGet(self): | 22 def HandleGet(self): |
| 20 settings = CrashConfigModel.Get() | 23 settings = CrashConfigModel.Get() |
| 21 | 24 |
| 22 data = { | 25 data = { |
| 23 'fracas': settings.fracas, | 26 'fracas': settings.fracas, |
| 27 'component_classifier': settings.str_component_classifier, |
| 28 'project_classifier': settings.project_classifier, |
| 24 } | 29 } |
| 25 | 30 |
| 26 return {'template': 'crash/crash_config.html', 'data': data} | 31 return {'template': 'crash/crash_config.html', 'data': data} |
| 27 | 32 |
| 28 def HandlePost(self): | 33 def HandlePost(self): |
| 29 data = self.request.params.get('data') | 34 data = self.request.params.get('data') |
| 30 new_config_dict = json.loads(data) | 35 new_config_dict = json.loads(data) |
| 36 |
| 37 component_config = new_config_dict['component_classifier'] |
| 38 |
| 39 # Convert the pattern strings to re compiled objects. |
| 40 path_function_component = [] |
| 41 for path, function, component in component_config.get( |
| 42 'path_function_component', []): |
| 43 path_function_component.append(( |
| 44 re.compile(path), |
| 45 re.compile(function) if function else None, |
| 46 component)) |
| 47 |
| 48 if path_function_component: |
| 49 component_config['path_function_component'] = path_function_component |
| 50 |
| 51 # Compress component config since it may grow bigger. |
| 52 new_config_dict['compressed_component_classifier'] = zlib.compress( |
| 53 pickle.dumps(component_config)) |
| 54 # Delete the oringinal string component classifier settings since it's |
| 55 # already be compressed 'compressed_component_classifier'. |
| 56 del new_config_dict['component_classifier'] |
| 57 |
| 31 CrashConfigModel.Get().Update( | 58 CrashConfigModel.Get().Update( |
| 32 users.get_current_user(), users.IsCurrentUserAdmin(), **new_config_dict) | 59 users.get_current_user(), users.IsCurrentUserAdmin(), **new_config_dict) |
| 33 return self.HandleGet() | 60 return self.HandleGet() |
| OLD | NEW |