| OLD | NEW |
| (Empty) |
| 1 # Copyright (c) 2013 Google Inc. All rights reserved. | |
| 2 # | |
| 3 # Redistribution and use in source and binary forms, with or without | |
| 4 # modification, are permitted provided that the following conditions are | |
| 5 # met: | |
| 6 # | |
| 7 # * Redistributions of source code must retain the above copyright | |
| 8 # notice, this list of conditions and the following disclaimer. | |
| 9 # * Redistributions in binary form must reproduce the above | |
| 10 # copyright notice, this list of conditions and the following disclaimer | |
| 11 # in the documentation and/or other materials provided with the | |
| 12 # distribution. | |
| 13 # | |
| 14 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
| 15 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |
| 16 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | |
| 17 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | |
| 18 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |
| 19 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |
| 20 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | |
| 21 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | |
| 22 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
| 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. | |
| 25 | |
| 26 import logging | |
| 27 import optparse | |
| 28 import time | |
| 29 import traceback | |
| 30 | |
| 31 from webkitpy.tool.bot.commit_announcer import CommitAnnouncerThread | |
| 32 from webkitpy.tool.bot.commit_announcer import UPDATE_WAIT_SECONDS | |
| 33 from webkitpy.tool.commands.command import Command | |
| 34 | |
| 35 _log = logging.getLogger(__name__) | |
| 36 ANNOUNCE_PATH = 'third_party/WebKit' | |
| 37 | |
| 38 | |
| 39 class CommitAnnouncerCommand(Command): | |
| 40 name = 'commit-announcer' | |
| 41 help_text = 'Start an IRC bot for announcing new git commits.' | |
| 42 show_in_main_help = True | |
| 43 | |
| 44 def __init__(self): | |
| 45 options = [ | |
| 46 optparse.make_option('--irc-password', default=None, help='Specify I
RC password to use.'), | |
| 47 ] | |
| 48 super(CommitAnnouncerCommand, self).__init__(options) | |
| 49 | |
| 50 def execute(self, options, args, tool): | |
| 51 bot_thread = CommitAnnouncerThread(tool, ANNOUNCE_PATH, options.irc_pass
word) | |
| 52 bot_thread.start() | |
| 53 _log.info('Bot started') | |
| 54 try: | |
| 55 while bot_thread.is_alive(): | |
| 56 bot_thread.bot.post_new_commits() | |
| 57 time.sleep(UPDATE_WAIT_SECONDS) | |
| 58 except KeyboardInterrupt: | |
| 59 _log.error('Terminated by keyboard interrupt') | |
| 60 except Exception: | |
| 61 _log.error('Unexpected error:') | |
| 62 _log.error(traceback.format_exc()) | |
| 63 | |
| 64 if bot_thread.is_alive(): | |
| 65 _log.info('Disconnecting bot') | |
| 66 bot_thread.stop() | |
| 67 else: | |
| 68 _log.info('Bot offline') | |
| 69 _log.info('Done') | |
| OLD | NEW |