diff --git a/earwigbot/__init__.py b/earwigbot/__init__.py index 282f66b..1ebde74 100644 --- a/earwigbot/__init__.py +++ b/earwigbot/__init__.py @@ -32,5 +32,20 @@ __copyright__ = "Copyright (C) 2009, 2010, 2011, 2012 by Ben Kurtovic" __license__ = "MIT License" __version__ = "0.1.dev" __email__ = "ben.kurtovic@verizon.net" +__release__ = False + +if not __release__: + def _add_git_commit_id_to_version(version): + from git import Repo + from os.path import split, dirname + path = split(dirname(__file__))[0] + commit_id = Repo(path).head.object.hexsha + return version + ".git+" + commit_id[:8] + try: + __version__ = _add_git_commit_id_to_version(__version__) + except Exception: + pass + finally: + del _add_git_commit_id_to_version from earwigbot import blowfish, bot, commands, config, irc, tasks, util, wiki diff --git a/earwigbot/bot.py b/earwigbot/bot.py index ac2c566..ea40dcd 100644 --- a/earwigbot/bot.py +++ b/earwigbot/bot.py @@ -20,6 +20,7 @@ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE # SOFTWARE. +import logging from threading import Lock, Thread from time import sleep, time @@ -99,9 +100,11 @@ class Bot(object): while self._keep_looping: with self.component_lock: if self.frontend and self.frontend.is_stopped(): + self.logger.warn("IRC frontend has stopped; restarting") self.frontend = Frontend(self) Thread(name=name, target=self.frontend.loop).start() if self.watcher and self.watcher.is_stopped(): + self.logger.warn("IRC watcher has stopped; restarting") self.watcher = Watcher(self) Thread(name=name, target=self.watcher.loop).start() sleep(5) @@ -121,6 +124,7 @@ class Bot(object): self._loop() def restart(self): + self.logger.info("Restarting bot per request from owner") with self.component_lock: self._stop_irc_components() self.config.load() @@ -129,6 +133,7 @@ class Bot(object): self._start_irc_components() def stop(self): + self.logger.info("Shutting down bot") with self.component_lock: self._stop_irc_components() self._keep_looping = False diff --git a/earwigbot/config.py b/earwigbot/config.py index f2830e0..fc73a08 100644 --- a/earwigbot/config.py +++ b/earwigbot/config.py @@ -208,8 +208,8 @@ class BotConfig(object): decrypted if they were decrypted beforehand. """ if not path.exists(self._config_path): - print "You haven't configured the bot yet!" - choice = raw_input("Would you like to do this now? [y/n] ") + print "Config file not found:", self._config_path + choice = raw_input("Would you like to create a config file now? [y/n] ") if choice.lower().startswith("y"): self._make_new() else: diff --git a/earwigbot/util.py b/earwigbot/util.py index 8b3ad5a..5f139da 100755 --- a/earwigbot/util.py +++ b/earwigbot/util.py @@ -31,29 +31,33 @@ __all__ = ["BotUtility", "main"] class BotUtility(object): """ - DOCSTRING NEEDED + This is a command-line utility for EarwigBot that enables you to easily + start the bot without writing generally unnecessary three-line bootstrap + scripts. It supports starting the bot from any directory, as well as + starting individual tasks instead of the entire bot. """ def version(self): - return __version__ + return "EarwigBot v{0}".format(__version__) - def run(self): - root_dir = path.abspath(path.curdir()) + def run(self, root_dir): bot = Bot(root_dir) - try: - bot.run() - finally: - bot.stop() + print self.version() + #try: + # bot.run() + #finally: + # bot.stop() def main(self): - print "EarwigBot v{0}\n".format(self.version()) parser = argparse.ArgumentParser(description=BotUtility.__doc__) - parser.add_argument("-V", "--version", action="version", + parser.add_argument("-v", "--version", action="version", version=self.version()) - + parser.add_argument("root_dir", metavar="path", nargs="?", default=path.curdir) args = parser.parse_args() -# args.func(args) + + root_dir = path.abspath(args.root_dir) + self.run(root_dir) main = BotUtility().main diff --git a/setup.py b/setup.py index 67234d9..490faa5 100644 --- a/setup.py +++ b/setup.py @@ -34,7 +34,9 @@ setup( entry_points = {"console_scripts": ["earwigbot = earwigbot.util:main"]}, install_requires = ["PyYAML >= 3.10", # Config parsing "oursql >= 0.9.3", # Talking with MediaWiki databases - "oauth2 >= 1.5.211"], # Talking with Yahoo BOSS Search + "oauth2 >= 1.5.211", # Talking with Yahoo BOSS Search + "GitPython >= 0.3.2.RC1", # Interfacing with git + ], test_suite = "tests", version = __version__, author = "Ben Kurtovic",