@@ -32,5 +32,20 @@ __copyright__ = "Copyright (C) 2009, 2010, 2011, 2012 by Ben Kurtovic" | |||||
__license__ = "MIT License" | __license__ = "MIT License" | ||||
__version__ = "0.1.dev" | __version__ = "0.1.dev" | ||||
__email__ = "ben.kurtovic@verizon.net" | __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 | from earwigbot import blowfish, bot, commands, config, irc, tasks, util, wiki |
@@ -20,6 +20,7 @@ | |||||
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||||
# SOFTWARE. | # SOFTWARE. | ||||
import logging | |||||
from threading import Lock, Thread | from threading import Lock, Thread | ||||
from time import sleep, time | from time import sleep, time | ||||
@@ -99,9 +100,11 @@ class Bot(object): | |||||
while self._keep_looping: | while self._keep_looping: | ||||
with self.component_lock: | with self.component_lock: | ||||
if self.frontend and self.frontend.is_stopped(): | if self.frontend and self.frontend.is_stopped(): | ||||
self.logger.warn("IRC frontend has stopped; restarting") | |||||
self.frontend = Frontend(self) | self.frontend = Frontend(self) | ||||
Thread(name=name, target=self.frontend.loop).start() | Thread(name=name, target=self.frontend.loop).start() | ||||
if self.watcher and self.watcher.is_stopped(): | if self.watcher and self.watcher.is_stopped(): | ||||
self.logger.warn("IRC watcher has stopped; restarting") | |||||
self.watcher = Watcher(self) | self.watcher = Watcher(self) | ||||
Thread(name=name, target=self.watcher.loop).start() | Thread(name=name, target=self.watcher.loop).start() | ||||
sleep(5) | sleep(5) | ||||
@@ -121,6 +124,7 @@ class Bot(object): | |||||
self._loop() | self._loop() | ||||
def restart(self): | def restart(self): | ||||
self.logger.info("Restarting bot per request from owner") | |||||
with self.component_lock: | with self.component_lock: | ||||
self._stop_irc_components() | self._stop_irc_components() | ||||
self.config.load() | self.config.load() | ||||
@@ -129,6 +133,7 @@ class Bot(object): | |||||
self._start_irc_components() | self._start_irc_components() | ||||
def stop(self): | def stop(self): | ||||
self.logger.info("Shutting down bot") | |||||
with self.component_lock: | with self.component_lock: | ||||
self._stop_irc_components() | self._stop_irc_components() | ||||
self._keep_looping = False | self._keep_looping = False | ||||
@@ -208,8 +208,8 @@ class BotConfig(object): | |||||
decrypted if they were decrypted beforehand. | decrypted if they were decrypted beforehand. | ||||
""" | """ | ||||
if not path.exists(self._config_path): | 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"): | if choice.lower().startswith("y"): | ||||
self._make_new() | self._make_new() | ||||
else: | else: | ||||
@@ -31,29 +31,33 @@ __all__ = ["BotUtility", "main"] | |||||
class BotUtility(object): | 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): | 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) | bot = Bot(root_dir) | ||||
try: | |||||
bot.run() | |||||
finally: | |||||
bot.stop() | |||||
print self.version() | |||||
#try: | |||||
# bot.run() | |||||
#finally: | |||||
# bot.stop() | |||||
def main(self): | def main(self): | ||||
print "EarwigBot v{0}\n".format(self.version()) | |||||
parser = argparse.ArgumentParser(description=BotUtility.__doc__) | parser = argparse.ArgumentParser(description=BotUtility.__doc__) | ||||
parser.add_argument("-V", "--version", action="version", | |||||
parser.add_argument("-v", "--version", action="version", | |||||
version=self.version()) | version=self.version()) | ||||
parser.add_argument("root_dir", metavar="path", nargs="?", default=path.curdir) | |||||
args = parser.parse_args() | args = parser.parse_args() | ||||
# args.func(args) | |||||
root_dir = path.abspath(args.root_dir) | |||||
self.run(root_dir) | |||||
main = BotUtility().main | main = BotUtility().main | ||||
@@ -34,7 +34,9 @@ setup( | |||||
entry_points = {"console_scripts": ["earwigbot = earwigbot.util:main"]}, | entry_points = {"console_scripts": ["earwigbot = earwigbot.util:main"]}, | ||||
install_requires = ["PyYAML >= 3.10", # Config parsing | install_requires = ["PyYAML >= 3.10", # Config parsing | ||||
"oursql >= 0.9.3", # Talking with MediaWiki databases | "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", | test_suite = "tests", | ||||
version = __version__, | version = __version__, | ||||
author = "Ben Kurtovic", | author = "Ben Kurtovic", | ||||