Mercurial > libervia-backend
comparison src/plugins/plugin_blog_import_dokuwiki.py @ 1853:1a9c12644552
plugin blog import dokuwiki: fixed bad use of MissingModule and unmodified docstring
author | Goffi <goffi@goffi.org> |
---|---|
date | Thu, 25 Feb 2016 16:05:31 +0100 |
parents | 489b968b3723 |
children | 2daf7b4c6756 |
comparison
equal
deleted
inserted
replaced
1852:569c48e4cf0d | 1853:1a9c12644552 |
---|---|
1 #!/usr/bin/python | 1 #!/usr/bin/python |
2 # -*- coding: utf-8 -*- | 2 # -*- coding: utf-8 -*- |
3 | 3 |
4 # SàT plugin to import external blogs | 4 # SàT plugin to import dokuwiki blogs |
5 # Copyright (C) 2009-2016 Jérôme Poisson (goffi@goffi.org) | 5 # Copyright (C) 2009-2016 Jérôme Poisson (goffi@goffi.org) |
6 # Copyright (C) 2013-2016 Adrien Cossa (souliane@mailoo.org) | 6 # Copyright (C) 2013-2016 Adrien Cossa (souliane@mailoo.org) |
7 | 7 |
8 # This program is free software: you can redistribute it and/or modify | 8 # This program is free software: you can redistribute it and/or modify |
9 # it under the terms of the GNU Affero General Public License as published by | 9 # it under the terms of the GNU Affero General Public License as published by |
39 raise exceptions.MissingModule(u'Missing module dokuwiki, please install it with "pip install dokuwiki"') | 39 raise exceptions.MissingModule(u'Missing module dokuwiki, please install it with "pip install dokuwiki"') |
40 try: | 40 try: |
41 from PIL import Image # this is already needed by plugin XEP-0054 | 41 from PIL import Image # this is already needed by plugin XEP-0054 |
42 except: | 42 except: |
43 raise exceptions.MissingModule(u"Missing module pillow, please download/install it from https://python-pillow.github.io") | 43 raise exceptions.MissingModule(u"Missing module pillow, please download/install it from https://python-pillow.github.io") |
44 try: | |
45 from plugin_blog_import import OPT_HOST, OPT_UPLOAD_IMAGES | |
46 except: | |
47 raise exceptions.MissingModule(u'Missing module plugin_blog_import, please install the Salut à Toi "BLOG_IMPORT" plugin') | |
48 | 44 |
49 PLUGIN_INFO = { | 45 PLUGIN_INFO = { |
50 "name": "Dokuwiki import", | 46 "name": "Dokuwiki import", |
51 "import_name": "IMPORT_DOKUWIKI", | 47 "import_name": "IMPORT_DOKUWIKI", |
52 "type": C.PLUG_TYPE_BLOG, | 48 "type": C.PLUG_TYPE_BLOG, |
81 passwd: DokuWiki admin password | 77 passwd: DokuWiki admin password |
82 namespace: DokuWiki namespace to import (default: root namespace "/") | 78 namespace: DokuWiki namespace to import (default: root namespace "/") |
83 media_repo: URL to the new remote media repository (default: none) | 79 media_repo: URL to the new remote media repository (default: none) |
84 limit: maximal number of posts to import (default: 100) | 80 limit: maximal number of posts to import (default: 100) |
85 | 81 |
86 Example of usage: | 82 Example of usage (with jp frontend): |
87 | 83 |
88 jp import dokuwiki -p dave --pwd xxxxxx --connect | 84 jp import dokuwiki -p dave --pwd xxxxxx --connect |
89 http://127.0.1.1 -o user souliane -o passwd qwertz | 85 http://127.0.1.1 -o user souliane -o passwd qwertz |
90 -o namespace public:2015:10 | 86 -o namespace public:2015:10 |
91 -o media_repo http://media.diekulturvermittlung.at | 87 -o media_repo http://media.diekulturvermittlung.at |
174 if link["type"] != "extern": | 170 if link["type"] != "extern": |
175 assert link["type"] == "local" | 171 assert link["type"] == "local" |
176 page = link["page"] | 172 page = link["page"] |
177 backlinks.append(page[1:] if page.startswith(":") else page) | 173 backlinks.append(page[1:] if page.startswith(":") else page) |
178 | 174 |
179 content = self.pages.get(id_) | 175 self.pages.get(id_) |
180 content_xhtml = self.processContent(self.pages.html(id_), backlinks, profile_jid) | 176 content_xhtml = self.processContent(self.pages.html(id_), backlinks, profile_jid) |
181 | 177 |
182 # XXX: title is already in content_xhtml and difficult to remove, so leave it | 178 # XXX: title is already in content_xhtml and difficult to remove, so leave it |
183 # title = content.split("\n")[0].strip(u"\ufeff= ") | 179 # title = content.split("\n")[0].strip(u"\ufeff= ") |
184 | 180 |
342 class DokuwikiImport(object): | 338 class DokuwikiImport(object): |
343 | 339 |
344 def __init__(self, host): | 340 def __init__(self, host): |
345 log.info(_("plugin Dokuwiki Import initialization")) | 341 log.info(_("plugin Dokuwiki Import initialization")) |
346 self.host = host | 342 self.host = host |
347 host.plugins['BLOG_IMPORT'].register('dokuwiki', self.DkImport, SHORT_DESC, LONG_DESC) | 343 self._blog_import = host.plugins['BLOG_IMPORT'] |
344 self._blog_import.register('dokuwiki', self.DkImport, SHORT_DESC, LONG_DESC) | |
348 | 345 |
349 def DkImport(self, client, location, options=None): | 346 def DkImport(self, client, location, options=None): |
350 """Import from DokuWiki to PubSub | 347 """Import from DokuWiki to PubSub |
351 | 348 |
352 @param location (unicode): DokuWiki site URL | 349 @param location (unicode): DokuWiki site URL |
354 - user (unicode): DokuWiki admin user | 351 - user (unicode): DokuWiki admin user |
355 - passwd (unicode): DokuWiki admin password | 352 - passwd (unicode): DokuWiki admin password |
356 - namespace (unicode): DokuWiki namespace to import | 353 - namespace (unicode): DokuWiki namespace to import |
357 - media_repo (unicode): New remote media repository | 354 - media_repo (unicode): New remote media repository |
358 """ | 355 """ |
359 options[OPT_HOST] = location | 356 options[self._blog_import.OPT_HOST] = location |
360 try: | 357 try: |
361 user = options["user"] | 358 user = options["user"] |
362 except KeyError: | 359 except KeyError: |
363 raise exceptions.DataError('parameter "user" is required') | 360 raise exceptions.DataError('parameter "user" is required') |
364 try: | 361 try: |
365 passwd = options["passwd"] | 362 passwd = options["passwd"] |
366 except KeyError: | 363 except KeyError: |
367 raise exceptions.DataError('parameter "passwd" is required') | 364 raise exceptions.DataError('parameter "passwd" is required') |
368 | 365 |
369 opt_upload_images = options.get(OPT_UPLOAD_IMAGES, None) | 366 opt_upload_images = options.get(self._blog_import.OPT_UPLOAD_IMAGES, None) |
370 try: | 367 try: |
371 media_repo = options["media_repo"] | 368 media_repo = options["media_repo"] |
372 if opt_upload_images: | 369 if opt_upload_images: |
373 options[OPT_UPLOAD_IMAGES] = False # force using --no-images-upload | 370 options[self._blog_import.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}") | 371 info_msg = _("DokuWiki media files will be *downloaded* to {temp_dir} - to finish the import you have to upload them *manually* to {media_repo}") |
375 except KeyError: | 372 except KeyError: |
376 media_repo = DEFAULT_MEDIA_REPO | 373 media_repo = DEFAULT_MEDIA_REPO |
377 if opt_upload_images: | 374 if opt_upload_images: |
378 info_msg = _("DokuWiki media files will be *uploaded* to the XMPP server. Hyperlinks to these media may not been updated though.") | 375 info_msg = _("DokuWiki media files will be *uploaded* to the XMPP server. Hyperlinks to these media may not been updated though.") |