diff --git a/doc/README.txt b/doc/README.txt index 547327308..c9c1edc1c 100644 --- a/doc/README.txt +++ b/doc/README.txt @@ -50,7 +50,7 @@ home directory, usually "C:\Documents and Settings\UserName". Dependencies ------------- -Dosage is requires Python version 2.5 or higher, which can be downloaded +Dosage requires Python version 2.7 or higher, which can be downloaded from http://www.python.org. No external Python modules are required - only the Python Standard Library that gets installed with Python. diff --git a/doc/changelog.txt b/doc/changelog.txt index 6eb25809d..95b13616d 100644 --- a/doc/changelog.txt +++ b/doc/changelog.txt @@ -7,6 +7,7 @@ Features: Changes: - installation: Added support for dynamic configuration values. +- installation: Require and use Python 2.7 - comics: Removed the twisted and zope dependencies by adding an internal plugin search mechanism. - testing: Refactored the test comic routine in proper unit tests. diff --git a/dosagelib/__init__.py b/dosagelib/__init__.py index b38fa4a3c..0814ee8ad 100644 --- a/dosagelib/__init__.py +++ b/dosagelib/__init__.py @@ -17,5 +17,5 @@ thus making their individual implementations trivial. """ import sys if not (hasattr(sys, 'version_info') or - sys.version_info < (2, 5, 0, 'final', 0)): - raise SystemExit("This program requires Python 2.5 or later.") + sys.version_info < (2, 7, 0, 'final', 0)): + raise SystemExit("This program requires Python 2.7 or later.") diff --git a/dosagelib/loader.py b/dosagelib/loader.py index 6ea543e65..bedfaac77 100644 --- a/dosagelib/loader.py +++ b/dosagelib/loader.py @@ -4,45 +4,33 @@ Functions to load plugin modules. """ import os -import sys +import importlib -def get_modules(folder, importprefix): - """Find all valid modules in the plugins directory. A valid module +def get_modules(folder='plugins'): + """Find all valid modules in the plugins subdirectory. A valid module must have a .py extension, and is importable. @return: all loaded valid modules @rtype: iterator of module """ - for filename in get_importable_modules(folder): + dirname = os.path.join(os.path.dirname(__file__), folder) + for modname in get_importable_modules(dirname): try: - module = load_module(filename, importprefix) - if module is not None: - yield module + name ="..%s.%s" % (folder, modname) + yield importlib.import_module(name, __name__) except StandardError, msg: - print "ERROR: could not load module %s: %s" % (filename, msg) + print "ERROR: could not load module %s: %s" % (modname, msg) def get_importable_modules(folder): """Find all module files in the given folder that end witn '.py' and don't start with an underscore. - @return module filenames + @return module names @rtype: iterator of string """ for fname in sorted(os.listdir(folder)): if fname.endswith('.py') and not fname.startswith('_'): - yield os.path.join(folder, fname) - - -def load_module(filename, importprefix): - """Load and return the module given by the filename. - Other exceptions than ImportError are not catched. - @return: loaded module or None on import errors - @rtype: module or None - """ - name = os.path.splitext(os.path.basename(filename))[0] - modulename = "%s%s" % (importprefix, name) - __import__(modulename) - return sys.modules[modulename] + yield fname[:-3] def get_plugins(modules, classobj): diff --git a/dosagelib/scraper.py b/dosagelib/scraper.py index 358d1f552..f38dc9396 100644 --- a/dosagelib/scraper.py +++ b/dosagelib/scraper.py @@ -154,9 +154,7 @@ def get_scrapers(): """ global _scrapers if _scrapers is None: - folder = os.path.join(os.path.dirname(__file__), 'plugins') - importprefix = 'dosagelib.plugins.' - modules = loader.get_modules(folder, importprefix) + modules = loader.get_modules() plugins = loader.get_plugins(modules, _BasicScraper) _scrapers = list(plugins) _scrapers.sort(key=lambda s: s.get_name())