| OLD | NEW |
| 1 # Copyright (c) 2013 Google Inc. All rights reserved. | 1 # Copyright (c) 2013 Google Inc. All rights reserved. |
| 2 # | 2 # |
| 3 # Redistribution and use in source and binary forms, with or without | 3 # Redistribution and use in source and binary forms, with or without |
| 4 # modification, are permitted provided that the following conditions are | 4 # modification, are permitted provided that the following conditions are |
| 5 # met: | 5 # met: |
| 6 # | 6 # |
| 7 # * Redistributions of source code must retain the above copyright | 7 # * Redistributions of source code must retain the above copyright |
| 8 # notice, this list of conditions and the following disclaimer. | 8 # notice, this list of conditions and the following disclaimer. |
| 9 # * Redistributions in binary form must reproduce the above | 9 # * Redistributions in binary form must reproduce the above |
| 10 # copyright notice, this list of conditions and the following disclaimer | 10 # copyright notice, this list of conditions and the following disclaimer |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 22 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 23 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 23 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 24 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 24 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 25 | 25 |
| 26 import logging | 26 import logging |
| 27 from optparse import make_option | 27 from optparse import make_option |
| 28 import time | 28 import time |
| 29 import traceback | 29 import traceback |
| 30 | 30 |
| 31 from webkitpy.common.config.irc import update_wait_seconds | 31 from webkitpy.common.config.irc import update_wait_seconds |
| 32 from webkitpy.tool.bot.commitannouncer import CommitAnnouncer | |
| 33 from webkitpy.tool.bot.commitannouncer import CommitAnnouncerThread | 32 from webkitpy.tool.bot.commitannouncer import CommitAnnouncerThread |
| 34 from webkitpy.tool.commands.command import Command | 33 from webkitpy.tool.commands.command import Command |
| 35 | 34 |
| 36 _log = logging.getLogger(__name__) | 35 _log = logging.getLogger(__name__) |
| 37 announce_path = "third_party/WebKit" | 36 announce_path = "third_party/WebKit" |
| 38 | 37 |
| 39 | 38 |
| 40 class CommitAnnouncerCommand(Command): | 39 class CommitAnnouncerCommand(Command): |
| 41 name = "commit-announcer" | 40 name = "commit-announcer" |
| 42 help_text = "Start an IRC bot for announcing new git commits." | 41 help_text = "Start an IRC bot for announcing new git commits." |
| 43 show_in_main_help = True | 42 show_in_main_help = True |
| 44 | 43 |
| 45 def __init__(self): | 44 def __init__(self): |
| 46 options = [ | 45 options = [ |
| 47 make_option("--irc-password", default=None, help="Specify IRC passwo
rd to use."), | 46 make_option("--irc-password", default=None, help="Specify IRC passwo
rd to use."), |
| 48 ] | 47 ] |
| 49 super(CommitAnnouncerCommand, self).__init__(options) | 48 super(CommitAnnouncerCommand, self).__init__(options) |
| 50 | 49 |
| 51 def execute(self, options, args, tool): | 50 def execute(self, options, args, tool): |
| 52 bot_thread = CommitAnnouncerThread(tool, announce_path, options.irc_pass
word) | 51 bot_thread = CommitAnnouncerThread(tool, announce_path, options.irc_pass
word) |
| 53 bot_thread.start() | 52 bot_thread.start() |
| 54 _log.info("Bot started") | 53 _log.info("Bot started") |
| 55 try: | 54 try: |
| 56 while bot_thread.is_alive(): | 55 while bot_thread.is_alive(): |
| 57 bot_thread.bot.post_new_commits() | 56 bot_thread.bot.post_new_commits() |
| 58 time.sleep(update_wait_seconds) | 57 time.sleep(update_wait_seconds) |
| 59 except KeyboardInterrupt: | 58 except KeyboardInterrupt: |
| 60 _log.error("Terminated by keyboard interrupt") | 59 _log.error("Terminated by keyboard interrupt") |
| 61 except Exception as e: | 60 except Exception: |
| 62 _log.error("Unexpected error:") | 61 _log.error("Unexpected error:") |
| 63 _log.error(traceback.format_exc()) | 62 _log.error(traceback.format_exc()) |
| 64 | 63 |
| 65 if bot_thread.is_alive(): | 64 if bot_thread.is_alive(): |
| 66 _log.info("Disconnecting bot") | 65 _log.info("Disconnecting bot") |
| 67 bot_thread.stop() | 66 bot_thread.stop() |
| 68 else: | 67 else: |
| 69 _log.info("Bot offline") | 68 _log.info("Bot offline") |
| 70 _log.info("Done") | 69 _log.info("Done") |
| OLD | NEW |