Commits

Jason R. Coombs committed f2af6ce

Moved config into pmxbot package

  • Participants
  • Parent commits 274a698

Comments (0)

Files changed (8)

    `pmxbot.util:karma` nor `pmxbot.karma.karma`.
  - Similarly, the Quotes store must now be referenced as
    `pmxbot.quotes:Quotes.store` (a class attribute).
+
+Other backward-incompatible changes::
+
+ - The `config` object has been moved into the parent `pmxbot` package.

File pmxbot/__init__.py

+# -*- coding: utf-8 -*-
+# vim:ts=4:sw=4:noexpandtab
+
+from .dictlib import ConfigDict
+
+config = ConfigDict(
+	use_ssl = False,
+	password = None,
+	silent_bot = False,
+)
+"The config object"

File pmxbot/karma.py

 # vim:ts=4:sw=4:noexpandtab
 
-from __future__ import print_function
+from __future__ import print_function, absolute_import
 
 import itertools
 import re
-import importlib
 import random
 
+import pmxbot
 from . import storage
 from .botbase import command
 
 class Karma(storage.SelectableStorage):
 	@classmethod
 	def initialize(cls):
-		pmxbot = importlib.import_module('pmxbot.pmxbot')
+		import pmxbot.pmxbot
 		cls.store = cls.from_URI(pmxbot.config.database)
-		pmxbot._finalizers.append(cls.finalize)
+		pmxbot.pmxbot._finalizers.append(cls.finalize)
 
 	@classmethod
 	def finalize(cls):
 		del cls.store
-		del globals()['karma']
-		del importlib.import_module('pmxbot.util').karma
 
 class SQLiteKarma(Karma, storage.SQLiteStorage):
 	def init_tables(self):

File pmxbot/notify.py

 # vim:ts=4:sw=4:noexpandtab
 
+from __future__ import absolute_import
+
 import time
 
+import pmxbot
 from . import storage
-from . import pmxbot
 from .botbase import command, on_join
 
 class Notify(storage.SelectableStorage):
     @classmethod
     def init(cls):
+        import pmxbot.pmxbot
         cls.store = cls.from_URI(pmxbot.config.database)
-        pmxbot._finalizers.append(cls.finalize)
+        pmxbot.pmxbot._finalizers.append(cls.finalize)
 
     @classmethod
     def finalize(cls):

File pmxbot/pmxbot.py

 import argparse
 import logging
 
+import pmxbot
 from . import dictlib
 from . import botbase
 
 log = logging.getLogger(__name__)
-config = None
 
 def get_args():
 	parser = argparse.ArgumentParser()
 
 def initialize(config):
 	"""
-	Initialize the bot with a pmxbot.dictlib.ConfigDict
+	Initialize the bot with a dictionary of config items
 	"""
-	assert isinstance(config, dictlib.ConfigDict)
-	globals().update(config=config)
+	pmxbot.config.update(config)
 
 	_setup_logging()
 	_load_library_extensions()
 
-	use_ssl = getattr(config, 'use_ssl', False)
-	password = getattr(config, 'password', None)
-
-	silent_bot = getattr(config, 'silent', False)
-
 	class_ = (botbase.LoggingCommandBot
-		if not silent_bot else botbase.SilentCommandBot)
+		if not pmxbot.config.silent_bot else botbase.SilentCommandBot)
 
 	return class_(config.database, config.server_host, config.server_port,
 		config.bot_nickname, config.log_channels, config.other_channels,
-		use_ssl=use_ssl, password=password)
+		use_ssl=pmxbot.config.use_ssl, password=pmxbot.config.password)
 
 
 _finalizers = [

File pmxbot/quotes.py

 # vim:ts=4:sw=4:noexpandtab
 
+from __future__ import absolute_import
+
 import random
-import importlib
 
+import pmxbot
 from . import storage
 from .botbase import command
 
 
 	@classmethod
 	def initialize(cls):
-		pmxbot = importlib.import_module('pmxbot.pmxbot')
+		import pmxbot.pmxbot
 		cls.store = cls.from_URI(pmxbot.config.database)
-		pmxbot._finalizers.append(cls.finalize)
+		pmxbot.pmxbot._finalizers.append(cls.finalize)
 
 	@classmethod
 	def finalize(cls):

File pmxbot/rss.py

 
 import feedparser
 
+import pmxbot
 from . import botbase
-from . import pmxbot
 from . import storage
 from . import timing
 
 	"""
 
 	def __init__(self):
+		import pmxbot.pmxbot
 		self.feed_interval = pmxbot.config.feed_interval
 		self.feeds = pmxbot.config.feeds
 		self.store = FeedparserDB.from_URI(pmxbot.config.database)
 		timer = timing.Stopwatch()
 		self.seen_feeds = set(self.store.get_seen_feeds())
 		log.info("Loaded feed history in %s", timer.split())
-		pmxbot._finalizers.append(self.finalize)
+		pmxbot.pmxbot._finalizers.append(self.finalize)
 
 	def finalize(self):
 		del self.store

File tests/functional/test_logging.py

 # -*- coding: utf-8 -*-
-import os
+
 import time
 import uuid
 from tests.functional import PmxbotHarness