| 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 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 65 return | 65 return |
| 66 new_commits = self.git.git_commits_since(self.last_commit) | 66 new_commits = self.git.git_commits_since(self.last_commit) |
| 67 if not new_commits: | 67 if not new_commits: |
| 68 return | 68 return |
| 69 self.last_commit = new_commits[-1] | 69 self.last_commit = new_commits[-1] |
| 70 for commit in new_commits: | 70 for commit in new_commits: |
| 71 if not self._should_announce_commit(commit): | 71 if not self._should_announce_commit(commit): |
| 72 continue | 72 continue |
| 73 commit_detail = self._commit_detail(commit) | 73 commit_detail = self._commit_detail(commit) |
| 74 if commit_detail: | 74 if commit_detail: |
| 75 _log.info('%s Posting commit %s' % (self._time(), commit)) | 75 _log.info('%s Posting commit %s', self._time(), commit) |
| 76 _log.info('%s Posted message: %s' % (self._time(), repr(commit_d
etail))) | 76 _log.info('%s Posted message: %s', self._time(), repr(commit_det
ail)) |
| 77 self._post(commit_detail) | 77 self._post(commit_detail) |
| 78 else: | 78 else: |
| 79 _log.error('Malformed commit log for %s' % commit) | 79 _log.error('Malformed commit log for %s', commit) |
| 80 | 80 |
| 81 # Bot commands. | 81 # Bot commands. |
| 82 | 82 |
| 83 def help(self): | 83 def help(self): |
| 84 self._post('Commands available: %s' % ' '.join(self.commands.keys())) | 84 self._post('Commands available: %s' % ' '.join(self.commands.keys())) |
| 85 | 85 |
| 86 def ping(self): | 86 def ping(self): |
| 87 self._post('Pong.') | 87 self._post('Pong.') |
| 88 | 88 |
| 89 def stop(self, message=""): | 89 def stop(self, message=""): |
| (...skipping 16 matching lines...) Expand all Loading... |
| 106 | 106 |
| 107 def _update(self, force_clean=False): | 107 def _update(self, force_clean=False): |
| 108 if not self.git.is_cleanly_tracking_remote_master(): | 108 if not self.git.is_cleanly_tracking_remote_master(): |
| 109 if not force_clean: | 109 if not force_clean: |
| 110 confirm = raw_input('This repository has local changes, continue
? (uncommitted changes will be lost) y/n: ') | 110 confirm = raw_input('This repository has local changes, continue
? (uncommitted changes will be lost) y/n: ') |
| 111 if not confirm.lower() == 'y': | 111 if not confirm.lower() == 'y': |
| 112 return False | 112 return False |
| 113 try: | 113 try: |
| 114 self.git.ensure_cleanly_tracking_remote_master() | 114 self.git.ensure_cleanly_tracking_remote_master() |
| 115 except ScriptError as e: | 115 except ScriptError as e: |
| 116 _log.error('Failed to clean repository: %s' % e) | 116 _log.error('Failed to clean repository: %s', e) |
| 117 return False | 117 return False |
| 118 | 118 |
| 119 attempts = 1 | 119 attempts = 1 |
| 120 while attempts <= retry_attempts: | 120 while attempts <= retry_attempts: |
| 121 if attempts > 1: | 121 if attempts > 1: |
| 122 # User may have sent a keyboard interrupt during the wait. | 122 # User may have sent a keyboard interrupt during the wait. |
| 123 if not self.connection.is_connected(): | 123 if not self.connection.is_connected(): |
| 124 return False | 124 return False |
| 125 wait = int(update_wait_seconds) << (attempts - 1) | 125 wait = int(update_wait_seconds) << (attempts - 1) |
| 126 if wait < 120: | 126 if wait < 120: |
| 127 _log.info('Waiting %s seconds' % wait) | 127 _log.info('Waiting %s seconds', wait) |
| 128 else: | 128 else: |
| 129 _log.info('Waiting %s minutes' % (wait / 60)) | 129 _log.info('Waiting %s minutes', wait / 60) |
| 130 time.sleep(wait) | 130 time.sleep(wait) |
| 131 _log.info('Pull attempt %s out of %s' % (attempts, retry_attempt
s)) | 131 _log.info('Pull attempt %s out of %s', attempts, retry_attempts) |
| 132 try: | 132 try: |
| 133 self.git.pull() | 133 self.git.pull() |
| 134 return True | 134 return True |
| 135 except ScriptError as e: | 135 except ScriptError as e: |
| 136 _log.error('Error pulling from server: %s' % e) | 136 _log.error('Error pulling from server: %s', e) |
| 137 _log.error('Output: %s' % e.output) | 137 _log.error('Output: %s', e.output) |
| 138 attempts += 1 | 138 attempts += 1 |
| 139 _log.error('Exceeded pull attempts') | 139 _log.error('Exceeded pull attempts') |
| 140 _log.error('Aborting at time: %s' % self._time()) | 140 _log.error('Aborting at time: %s', self._time()) |
| 141 return False | 141 return False |
| 142 | 142 |
| 143 def _time(self): | 143 def _time(self): |
| 144 return time.strftime('[%x %X %Z]', time.localtime()) | 144 return time.strftime('[%x %X %Z]', time.localtime()) |
| 145 | 145 |
| 146 def _message_command(self, message): | 146 def _message_command(self, message): |
| 147 prefix = '%s:' % self.connection.get_nickname() | 147 prefix = '%s:' % self.connection.get_nickname() |
| 148 if message.startswith(prefix): | 148 if message.startswith(prefix): |
| 149 command_name = message[len(prefix):].strip() | 149 command_name = message[len(prefix):].strip() |
| 150 if command_name in self.commands: | 150 if command_name in self.commands: |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 193 def __init__(self, tool, announce_path, irc_password): | 193 def __init__(self, tool, announce_path, irc_password): |
| 194 threading.Thread.__init__(self) | 194 threading.Thread.__init__(self) |
| 195 self.bot = CommitAnnouncer(tool, announce_path, irc_password) | 195 self.bot = CommitAnnouncer(tool, announce_path, irc_password) |
| 196 | 196 |
| 197 def run(self): | 197 def run(self): |
| 198 self.bot.start() | 198 self.bot.start() |
| 199 | 199 |
| 200 def stop(self): | 200 def stop(self): |
| 201 self.bot.stop() | 201 self.bot.stop() |
| 202 self.join() | 202 self.join() |
| OLD | NEW |