| OLD | NEW |
| 1 # Copyright 2013 The LUCI Authors. All rights reserved. | 1 # Copyright 2013 The LUCI Authors. All rights reserved. |
| 2 # Use of this source code is governed under the Apache License, Version 2.0 | 2 # Use of this source code is governed under the Apache License, Version 2.0 |
| 3 # that can be found in the LICENSE file. | 3 # that can be found in the LICENSE file. |
| 4 | 4 |
| 5 """Swarming bot main process. | 5 """Swarming bot main process. |
| 6 | 6 |
| 7 This is the program that communicates with the Swarming server, ensures the code | 7 This is the program that communicates with the Swarming server, ensures the code |
| 8 is always up to date and executes a child process to run tasks and upload | 8 is always up to date and executes a child process to run tasks and upload |
| 9 results back. | 9 results back. |
| 10 | 10 |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 133 from config import bot_config as _BOT_CONFIG | 133 from config import bot_config as _BOT_CONFIG |
| 134 return _BOT_CONFIG | 134 return _BOT_CONFIG |
| 135 | 135 |
| 136 | 136 |
| 137 def _register_extra_bot_config(content): | 137 def _register_extra_bot_config(content): |
| 138 """Registers the server injected extra bot_config.py. | 138 """Registers the server injected extra bot_config.py. |
| 139 | 139 |
| 140 This file is called implicitly by _call_hook() and _call_hook_safe(). | 140 This file is called implicitly by _call_hook() and _call_hook_safe(). |
| 141 """ | 141 """ |
| 142 global _EXTRA_BOT_CONFIG | 142 global _EXTRA_BOT_CONFIG |
| 143 if isinstance(content, unicode): |
| 144 # compile will throw if there's a '# coding: utf-8' line and the string is |
| 145 # in unicode. <3 python. |
| 146 content = content.encode('utf-8') |
| 143 try: | 147 try: |
| 144 compiled = compile(content, 'bot_config.py', 'exec') | 148 compiled = compile(content, 'bot_config.py', 'exec') |
| 145 _EXTRA_BOT_CONFIG = types.ModuleType('bot_config') | 149 _EXTRA_BOT_CONFIG = types.ModuleType('bot_config') |
| 146 exec(compiled, _EXTRA_BOT_CONFIG.__dict__) | 150 exec(compiled, _EXTRA_BOT_CONFIG.__dict__) |
| 147 except (SyntaxError, TypeError) as e: | 151 except (SyntaxError, TypeError) as e: |
| 148 _set_quarantined('handshake returned invalid bot_config: %s' % e) | 152 _set_quarantined('handshake returned invalid bot_config: %s' % e) |
| 149 | 153 |
| 150 | 154 |
| 151 def _log_call(name=None): | 155 def _log_call(name=None): |
| 152 def gen(fn): | 156 def gen(fn): |
| (...skipping 962 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1115 error = None | 1119 error = None |
| 1116 if len(args) != 0: | 1120 if len(args) != 0: |
| 1117 error = 'Unexpected arguments: %s' % args | 1121 error = 'Unexpected arguments: %s' % args |
| 1118 try: | 1122 try: |
| 1119 return _run_bot(error) | 1123 return _run_bot(error) |
| 1120 finally: | 1124 finally: |
| 1121 _call_hook_safe( | 1125 _call_hook_safe( |
| 1122 True, bot.Bot(None, None, None, None, base_dir, None), | 1126 True, bot.Bot(None, None, None, None, base_dir, None), |
| 1123 'on_bot_shutdown') | 1127 'on_bot_shutdown') |
| 1124 logging.info('main() returning') | 1128 logging.info('main() returning') |
| OLD | NEW |