import base64
import datetime
import io
+import logging
import os
import pathlib
import tarfile
from . import util
from .i18n import _
+# Setup logging
+log = logging.getLogger(__name__)
+
class Exporter(abc.ABC):
"""
Abstract class to define an exporter
# Store the root
self.root = pathlib.Path(root)
- async def __call__(self):
+ async def __call__(self, force=False):
# Ensure the root directory exists
try:
self.root.mkdir()
# For MultiExporters, we will have to export everything at once
if issubclass(exporter, MultiExporter):
e = exporter(self.backend, self.lists)
- await self.export(e, name)
+ await self.export(e, name, force=force)
# For regular exporters, we will have to export each list at a time
else:
for list in self.lists:
e = exporter(self.backend, list)
- await self.export(e, name, list=list)
+ await self.export(e, name, list=list, force=force)
- async def export(self, exporter, name, **kwargs):
+ async def export(self, exporter, name, force=False, **kwargs):
"""
This function takes an exporter instance and runs it
"""
# Make the path
path = self._make_path(name, **kwargs)
+ # Skip the export if we don't need it
+ if not force and os.path.getmtime(path) >= exporter.exported_at.timestamp():
+ log.debug("Skipping export because the file seems to be recent enough")
+ return
+
# Ensure the parent directory exists
try:
path.parent.mkdir()
# export-all
export = subparsers.add_parser("export-all", help=_("Export all lists"))
export.add_argument("directory", help=_("Output Directory"))
+ export.add_argument("--force", action="store_true", help=_("Force an export"))
export.set_defaults(func=self.__export_all)
# add-source
# Launch the DirectoryExporter
exporter = dbl.exporters.DirectoryExporter(backend,
root=args.directory, lists=[l async for l in backend.lists])
- await exporter()
+ await exporter(force=args.force)
async def __add_source(self, backend, args):
"""