comparison src/plugins/plugin_blog_import_dokuwiki.py @ 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 1a9c12644552
comparison
equal deleted inserted replaced
1843:a51355982f11 1844:489b968b3723
112 @param media_repo (unicode): New remote media repository 112 @param media_repo (unicode): New remote media repository
113 """ 113 """
114 DokuWiki.__init__(self, url, user, passwd) 114 DokuWiki.__init__(self, url, user, passwd)
115 self.url = url 115 self.url = url
116 self.media_repo = media_repo 116 self.media_repo = media_repo
117 self.temp_dir = None 117 self.temp_dir = tempfile.mkdtemp() if self.media_repo else None
118 if self.media_repo:
119 self.temp_dir = tempfile.mkdtemp()
120 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))
121 else:
122 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)
123 self.limit = limit 118 self.limit = limit
124 self.posts_data = OrderedDict() 119 self.posts_data = OrderedDict()
125 120
126 def getPostId(self, post): 121 def getPostId(self, post):
127 """Return a unique and constant post id 122 """Return a unique and constant post id
265 return text 260 return text
266 261
267 def moveMedia(self, link, subs): 262 def moveMedia(self, link, subs):
268 """Move a media from the DokuWiki host to the new repository. 263 """Move a media from the DokuWiki host to the new repository.
269 264
265 This also updates the hyperlinks to internal media files.
270 @param link (unicode): media link 266 @param link (unicode): media link
271 @param subs (dict): substitutions data 267 @param subs (dict): substitutions data
272 """ 268 """
273 url = urlparse.urljoin(self.url, link) 269 url = urlparse.urljoin(self.url, link)
274 user_media = re.match(r"(/lib/exe/\w+.php\?)(.*)", link) 270 user_media = re.match(r"(/lib/exe/\w+.php\?)(.*)", link)
367 raise exceptions.DataError('parameter "user" is required') 363 raise exceptions.DataError('parameter "user" is required')
368 try: 364 try:
369 passwd = options["passwd"] 365 passwd = options["passwd"]
370 except KeyError: 366 except KeyError:
371 raise exceptions.DataError('parameter "passwd" is required') 367 raise exceptions.DataError('parameter "passwd" is required')
368
369 opt_upload_images = options.get(OPT_UPLOAD_IMAGES, None)
372 try: 370 try:
373 media_repo = options["media_repo"] 371 media_repo = options["media_repo"]
372 if opt_upload_images:
373 options[OPT_UPLOAD_IMAGES] = False # force using --no-images-upload
374 info_msg = _("DokuWiki media files will be *downloaded* to {temp_dir} - to finish the import you have to upload them *manually* to {media_repo}")
374 except KeyError: 375 except KeyError:
375 media_repo = DEFAULT_MEDIA_REPO 376 media_repo = DEFAULT_MEDIA_REPO
376 if options.get(OPT_UPLOAD_IMAGES, None): 377 if opt_upload_images:
377 # TODO: when media_repo is not defined or empty, we should not force this option 378 info_msg = _("DokuWiki media files will be *uploaded* to the XMPP server. Hyperlinks to these media may not been updated though.")
378 options[OPT_UPLOAD_IMAGES] = False 379 else:
379 msg = _(u"Option --no-images-upload will be used by force.") 380 info_msg = _("DokuWiki media files will *stay* on {location} - some of them may be protected by DokuWiki ACL and will not be accessible.")
380 self.host.actionNew({'xmlui': xml_tools.note(msg).toXml()}, profile=client.profile) 381
381 try: 382 try:
382 namespace = options["namespace"] 383 namespace = options["namespace"]
383 except KeyError: 384 except KeyError:
384 namespace = DEFAULT_NAMESPACE 385 namespace = DEFAULT_NAMESPACE
385 try: 386 try:
386 limit = options["limit"] 387 limit = options["limit"]
387 except KeyError: 388 except KeyError:
388 limit = DEFAULT_LIMIT 389 limit = DEFAULT_LIMIT
390
389 dk_importer = Importer(location, user, passwd, media_repo, limit) 391 dk_importer = Importer(location, user, passwd, media_repo, limit)
390 self.host.actionNew({'xmlui': xml_tools.note(dk_importer.info_msg).toXml()}, profile=client.profile) 392 info_msg = info_msg.format(temp_dir=dk_importer.temp_dir, media_repo=media_repo, location=location)
393 self.host.actionNew({'xmlui': xml_tools.note(info_msg).toXml()}, profile=client.profile)
391 d = threads.deferToThread(dk_importer.process, client, namespace) 394 d = threads.deferToThread(dk_importer.process, client, namespace)
392 return d 395 return d