import io
import tarfile
+from . import util
+from .i18n import _
+
class Exporter(abc.ABC):
"""
Abstract class to define an exporter
The main entry point to export something with this exporter...
"""
# Export!
- self.export(f, **kwargs)
+ with util.Stopwatch(_("Exporting %(name)s using %(exporter)s") % \
+ { "name" : self.list.name, "exporter" : self.__class__.__name__ }):
+ self.export(f, **kwargs)
@abc.abstractmethod
def export(self, f, **kwargs):
###############################################################################
import idna
+import logging
import re
+import time
import unicodedata
+from .i18n import _
+
+# Setup logging
+log = logging.getLogger(__name__)
+
+class Stopwatch(object):
+ def __init__(self, task):
+ self.task = task
+
+ self.started_at = None
+ self.ended_at = None
+
+ def __enter__(self):
+ # Store the start time
+ self.started_at = time.perf_counter()
+
+ return self
+
+ def __exit__(self, type, value, traceback):
+ # Store the end time
+ self.ended_at = time.perf_counter()
+
+ # Compute how much time has elapsed
+ elapsed = self.ended_at - self.started_at
+
+ # Log the time
+ log.debug(_("%(task)s took %(time)s") % {
+ "task" : self.task,
+ "time" : ("%.0fs" % elapsed) if elapsed > 10 else ("%.2fms" % (elapsed * 1000)),
+ })
+
+
def slugify(text, iteration=None):
# Append the iteration
if iteration: