Przeglądaj źródła

git version info, logging updates, utility

tags/v0.1^2
Ben Kurtovic 12 lat temu
rodzic
commit
362db3d1c8
5 zmienionych plików z 41 dodań i 15 usunięć
  1. +15
    -0
      earwigbot/__init__.py
  2. +5
    -0
      earwigbot/bot.py
  3. +2
    -2
      earwigbot/config.py
  4. +16
    -12
      earwigbot/util.py
  5. +3
    -1
      setup.py

+ 15
- 0
earwigbot/__init__.py Wyświetl plik

@@ -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

+ 5
- 0
earwigbot/bot.py Wyświetl plik

@@ -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


+ 2
- 2
earwigbot/config.py Wyświetl plik

@@ -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:


+ 16
- 12
earwigbot/util.py Wyświetl plik

@@ -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


+ 3
- 1
setup.py Wyświetl plik

@@ -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",


Ładowanie…
Anuluj
Zapisz