From 7f2d6e56c73897df310b7dae9de0d480f62a39fa Mon Sep 17 00:00:00 2001 From: souliane Date: Thu, 4 Feb 2016 18:56:53 +0100 Subject: [PATCH] plugin blog_import_dokuwiki: also uses the generic image uploader from blog_import (when media_repo is empty and OPT_UPLOAD_IMAGES is True) --- src/plugins/plugin_blog_import.py | 1 + src/plugins/plugin_blog_import_dokuwiki.py | 27 ++++++++++++---------- 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/src/plugins/plugin_blog_import.py b/src/plugins/plugin_blog_import.py index 4640c829..375d0c3b 100755 --- a/src/plugins/plugin_blog_import.py +++ b/src/plugins/plugin_blog_import.py @@ -281,6 +281,7 @@ class BlogImportPlugin(object): tmp_dir = tempfile.mkdtemp() try: + # TODO: would be nice to also update the hyperlinks to these images, e.g. when you have for img_elt in xml_tools.findAll(top_elt, ['img']): yield self.imgFilters(client, img_elt, options, opt_host, tmp_dir) finally: diff --git a/src/plugins/plugin_blog_import_dokuwiki.py b/src/plugins/plugin_blog_import_dokuwiki.py index ce4d4dad..64abf7d8 100755 --- a/src/plugins/plugin_blog_import_dokuwiki.py +++ b/src/plugins/plugin_blog_import_dokuwiki.py @@ -114,12 +114,7 @@ class Importer(DokuWiki): 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 @@ class Importer(DokuWiki): 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 @@ class DokuwikiImport(object): 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 @@ class DokuwikiImport(object): 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