changeset 1843:a51355982f11

plugin blog_import_dokuwiki: fixes wrong URL when a substitution occurs twice
author souliane <souliane@mailoo.org>
date Thu, 04 Feb 2016 17:37:33 +0100
parents 9fd517248dc8
children 489b968b3723
files src/plugins/plugin_blog_import_dokuwiki.py
diffstat 1 files changed, 7 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/src/plugins/plugin_blog_import_dokuwiki.py	Thu Feb 04 17:36:22 2016 +0100
+++ b/src/plugins/plugin_blog_import_dokuwiki.py	Thu Feb 04 17:37:33 2016 +0100
@@ -247,7 +247,7 @@
             tgt = '/blog/%s/%s" target="#"' % (profile_jid.user, backlink)
             text = text.replace(src, tgt)
 
-        subs = []
+        subs = {}
 
         link_pattern = r"""<(img|a)[^>]* (src|href)="([^"]+)"[^>]*>"""
         for tag in re.finditer(link_pattern, text):
@@ -257,10 +257,10 @@
                 continue
             if self.media_repo:
                 self.moveMedia(link, subs)
-            else:
-                subs.append((link, urlparse.urljoin(self.url, link)))
+            elif link not in subs:
+                subs[link] = urlparse.urljoin(self.url, link)
 
-        for url, new_url in subs:
+        for url, new_url in subs.iteritems():
             text = text.replace(url, new_url)
         return text
 
@@ -268,7 +268,7 @@
         """Move a media from the DokuWiki host to the new repository.
 
         @param link (unicode): media link
-        @param subs (set(couple)): substitutions list
+        @param subs (dict): substitutions data
         """
         url = urlparse.urljoin(self.url, link)
         user_media = re.match(r"(/lib/exe/\w+.php\?)(.*)", link)
@@ -282,7 +282,7 @@
                 log.warning("No media found in fetch URL: %s" % user_media.group(2))
                 return
             if re.match(r"^\w*://", media):  # external URL to link directly
-                subs.append((link, media))
+                subs[link] = media
                 return
             try:  # create thumbnail
                 thumb_width = params["w"][0]
@@ -308,7 +308,7 @@
             self.createThumbnail(filepath, thumbnail, thumb_width)
 
         new_url = os.path.join(self.media_repo, filename)
-        subs.append((link, new_url))
+        subs[link] = new_url
 
     def downloadMedia(self, source, dest):
         """Copy media to localhost.