[SCM] morituri/master: * 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.
js at users.alioth.debian.org
js at users.alioth.debian.org
Sun Oct 19 20:09:45 UTC 2014
The following commit has been merged in the master branch:
commit 7f36f540d092e476b070e9120cee84568e5d8ca0
Author: Thomas Vander Stichele <thomas (at) apestaart (dot) org>
Date: Sun Nov 25 18:22:03 2012 +0000
* 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.
diff --git a/ChangeLog b/ChangeLog
index be6f6c0..4c51330 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,14 @@
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:
* morituri/configure/installed.py.in:
* morituri/configure/uninstalled.py.in:
diff --git a/morituri/result/logger.py b/morituri/result/logger.py
index 7ae1871..3e0bed1 100644
--- a/morituri/result/logger.py
+++ b/morituri/result/logger.py
@@ -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)
diff --git a/morituri/result/result.py b/morituri/result/result.py
index 1d0f0eb..1235368 100644
--- a/morituri/result/result.py
+++ b/morituri/result/result.py
@@ -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
diff --git a/morituri/rip/cd.py b/morituri/rip/cd.py
index abb2732..97c8b28 100644
--- a/morituri/rip/cd.py
+++ b/morituri/rip/cd.py
@@ -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)
diff --git a/morituri/rip/main.py b/morituri/rip/main.py
index 523ccef..60d13a8 100644
--- a/morituri/rip/main.py
+++ b/morituri/rip/main.py
@@ -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)
--
morituri packaging
More information about the pkg-multimedia-commits
mailing list