* morituri/result/logger.py:

* morituri/result/result.py:
	* morituri/rip/cd.py:
	* morituri/rip/main.py:
	  Expose loggers as pluggable.
	  Add --logger option to rip cd rip to specify logger.
This commit is contained in:
Thomas Vander Stichele
2012-11-25 18:22:03 +00:00
parent cd295537fc
commit 7f36f540d0
5 changed files with 68 additions and 8 deletions

View File

@@ -1,3 +1,12 @@
2012-11-25 Thomas Vander Stichele <thomas at apestaart dot org>
* morituri/result/logger.py:
* morituri/result/result.py:
* morituri/rip/cd.py:
* morituri/rip/main.py:
Expose loggers as pluggable.
Add --logger option to rip cd rip to specify logger.
2012-11-25 Thomas Vander Stichele <thomas at apestaart dot org>
* configure.ac:

View File

@@ -24,9 +24,9 @@ import time
from morituri.common import common
from morituri.configure import configure
from morituri.result import result
class MorituriLogger(object):
class MorituriLogger(result.Logger):
def log(self, ripResult, epoch=time.time()):
lines = self.logRip(ripResult, epoch=epoch)

View File

@@ -20,10 +20,9 @@
# You should have received a copy of the GNU General Public License
# along with morituri. If not, see <http://www.gnu.org/licenses/>.
import pkg_resources
import time
from morituri.result import logger
class TrackResult:
"""
@@ -117,6 +116,7 @@ class Logger(object):
Create a log from the given ripresult.
@param epoch: when the log file gets generated
@type epoch: float
@type ripResult: L{RipResult}
@rtype: str
@@ -124,5 +124,27 @@ class Logger(object):
raise NotImplementedError
def getLogger():
return logger.MorituriLogger()
# A setuptools-like entry point
class EntryPoint(object):
name = 'morituri'
def load(self):
from morituri.result import logger
return logger.MorituriLogger
def getLoggers():
"""
Get all logger plugins with entry point 'morituri.logger'.
@rtype: dict of C{str} -> C{Logger}
"""
d = {}
pluggables = list(pkg_resources.iter_entry_points("morituri.logger"))
for entrypoint in [EntryPoint(), ] + pluggables:
plugin_class = entrypoint.load()
d[entrypoint.name] = plugin_class
return d

View File

@@ -68,6 +68,15 @@ Log files will log the path to tracks relative to this directory.
"""
def addOptions(self):
loggers = result.getLoggers().keys()
self.parser.add_option('-L', '--logger',
action="store", dest="logger",
default='morituri',
help="logger to use "
"(default '%default', choose from '" +
"', '".join(loggers) + "')"
)
# FIXME: get from config
default = 0
self.parser.add_option('-o', '--offset',
@@ -386,8 +395,12 @@ See http://sourceforge.net/tracker/?func=detail&aid=604751&group_id=2171&atid=1
self.stdout.write("\n".join(prog.getAccurateRipResults()) + "\n")
# write log file
logger = result.getLogger()
prog.writeLog(discName, logger)
try:
klazz = result.getLoggers()[self.options.logger]
prog.writeLog(discName, klazz())
except KeyError:
self.stderr.write("No logger named %s found!\n" % (
self.options.logger))
prog.ejectDevice(device)

View File

@@ -1,7 +1,9 @@
# -*- Mode: Python -*-
# vi:si:et:sw=4:sts=4:ts=4
import os
import sys
import pkg_resources
from morituri.common import log, logcommand, common
@@ -12,6 +14,20 @@ from morituri.extern.task import task
def main(argv):
# load plugins
from morituri.configure import configure
pluginsdir = configure.pluginsdir
homepluginsdir = os.path.join(os.path.expanduser('~'),
'.morituri', 'plugins')
distributions, errors = pkg_resources.working_set.find_plugins(
pkg_resources.Environment([pluginsdir, homepluginsdir]))
if errors:
log.warning('errors finding plugins: %r', errors)
log.debug('mapping distributions %r', distributions)
map(pkg_resources.working_set.add, distributions)
c = Rip()
try:
ret = c.parse(argv)