changeset 1844:489b968b3723

plugin blog_import_dokuwiki: also uses the generic image uploader from blog_import (when media_repo is empty and OPT_UPLOAD_IMAGES is True)
author souliane <souliane@mailoo.org>
date Thu, 04 Feb 2016 18:56:53 +0100
parents a51355982f11
children 2bde6fc7aabd
files src/plugins/plugin_blog_import.py src/plugins/plugin_blog_import_dokuwiki.py
diffstat 2 files changed, 16 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- a/src/plugins/plugin_blog_import.py	Thu Feb 04 17:37:33 2016 +0100
+++ b/src/plugins/plugin_blog_import.py	Thu Feb 04 18:56:53 2016 +0100
@@ -281,6 +281,7 @@
 
         tmp_dir = tempfile.mkdtemp()
         try:
+            # TODO: would be nice to also update the hyperlinks to these images, e.g. when you have <a href="{url}"><img src="{url}"></a>
             for img_elt in xml_tools.findAll(top_elt, ['img']):
                 yield self.imgFilters(client, img_elt, options, opt_host, tmp_dir)
         finally:
--- a/src/plugins/plugin_blog_import_dokuwiki.py	Thu Feb 04 17:37:33 2016 +0100
+++ b/src/plugins/plugin_blog_import_dokuwiki.py	Thu Feb 04 18:56:53 2016 +0100
@@ -114,12 +114,7 @@
         DokuWiki.__init__(self, url, user, passwd)
         self.url = url
         self.media_repo = media_repo
-        self.temp_dir = None
-        if self.media_repo:
-            self.temp_dir = tempfile.mkdtemp()
-            self.info_msg = _("DokuWiki media files will be downloaded to %s - to finish the import you will need to upload them to %s" % (self.temp_dir, self.media_repo))
-        else:
-            self.info_msg = _("DokuWiki media files will stay on %s - some of them may be protected by DokuWiki ACL and will not be accessible." % url)
+        self.temp_dir = tempfile.mkdtemp() if self.media_repo else None
         self.limit = limit
         self.posts_data = OrderedDict()
 
@@ -267,6 +262,7 @@
     def moveMedia(self, link, subs):
         """Move a media from the DokuWiki host to the new repository.
 
+        This also updates the hyperlinks to internal media files.
         @param link (unicode): media link
         @param subs (dict): substitutions data
         """
@@ -369,15 +365,20 @@
             passwd = options["passwd"]
         except KeyError:
             raise exceptions.DataError('parameter "passwd" is required')
+
+        opt_upload_images = options.get(OPT_UPLOAD_IMAGES, None)
         try:
             media_repo = options["media_repo"]
+            if opt_upload_images:
+                options[OPT_UPLOAD_IMAGES] = False  # force using --no-images-upload
+            info_msg = _("DokuWiki media files will be *downloaded* to {temp_dir} - to finish the import you have to upload them *manually* to {media_repo}")
         except KeyError:
             media_repo = DEFAULT_MEDIA_REPO
-        if options.get(OPT_UPLOAD_IMAGES, None):
-            # TODO: when media_repo is not defined or empty, we should not force this option
-            options[OPT_UPLOAD_IMAGES] = False
-            msg = _(u"Option --no-images-upload will be used by force.")
-            self.host.actionNew({'xmlui': xml_tools.note(msg).toXml()}, profile=client.profile)
+            if opt_upload_images:
+                info_msg = _("DokuWiki media files will be *uploaded* to the XMPP server. Hyperlinks to these media may not been updated though.")
+            else:
+                info_msg = _("DokuWiki media files will *stay* on {location} - some of them may be protected by DokuWiki ACL and will not be accessible.")
+
         try:
             namespace = options["namespace"]
         except KeyError:
@@ -386,7 +387,9 @@
             limit = options["limit"]
         except KeyError:
             limit = DEFAULT_LIMIT
+
         dk_importer = Importer(location, user, passwd, media_repo, limit)
-        self.host.actionNew({'xmlui': xml_tools.note(dk_importer.info_msg).toXml()}, profile=client.profile)
+        info_msg = info_msg.format(temp_dir=dk_importer.temp_dir, media_repo=media_repo, location=location)
+        self.host.actionNew({'xmlui': xml_tools.note(info_msg).toXml()}, profile=client.profile)
         d = threads.deferToThread(dk_importer.process, client, namespace)
         return d