Mercurial > libervia-backend
diff sat/plugins/plugin_blog_import_dokuwiki.py @ 2624:56f94936df1e
code style reformatting using black
author | Goffi <goffi@goffi.org> |
---|---|
date | Wed, 27 Jun 2018 20:14:46 +0200 |
parents | 26edcf3a30eb |
children | 003b8b4b56a7 |
line wrap: on
line diff
--- a/sat/plugins/plugin_blog_import_dokuwiki.py Wed Jun 27 07:51:29 2018 +0200 +++ b/sat/plugins/plugin_blog_import_dokuwiki.py Wed Jun 27 20:14:46 2018 +0200 @@ -21,6 +21,7 @@ from sat.core.i18n import _, D_ from sat.core.constants import Const as C from sat.core.log import getLogger + log = getLogger(__name__) from sat.core import exceptions from sat.tools import xml_tools @@ -33,14 +34,19 @@ import re import time import os.path + try: from dokuwiki import DokuWiki, DokuWikiError # this is a new dependency except ImportError: - raise exceptions.MissingModule(u'Missing module dokuwiki, please install it with "pip install dokuwiki"') + raise exceptions.MissingModule( + u'Missing module dokuwiki, please install it with "pip install dokuwiki"' + ) try: from PIL import Image # this is already needed by plugin XEP-0054 except: - raise exceptions.MissingModule(u"Missing module pillow, please download/install it from https://python-pillow.github.io") + raise exceptions.MissingModule( + u"Missing module pillow, please download/install it from https://python-pillow.github.io" + ) PLUGIN_INFO = { C.PI_NAME: "Dokuwiki import", @@ -49,12 +55,13 @@ C.PI_DEPENDENCIES: ["BLOG_IMPORT"], C.PI_MAIN: "DokuwikiImport", C.PI_HANDLER: "no", - C.PI_DESCRIPTION: _("""Blog importer for Dokuwiki blog engine.""") + C.PI_DESCRIPTION: _("""Blog importer for Dokuwiki blog engine."""), } SHORT_DESC = D_(u"import posts from Dokuwiki blog engine") -LONG_DESC = D_(u"""This importer handle Dokuwiki blog engine. +LONG_DESC = D_( + u"""This importer handle Dokuwiki blog engine. To use it, you need an admin access to a running Dokuwiki website (local or on the Internet). The importer retrieves the data using @@ -91,15 +98,17 @@ "souliane", and it imports them to sat profile dave's microblog node. Internal Dokuwiki media that were hosted on http://127.0.1.1 are now pointing to http://media.diekulturvermittlung.at. -""") +""" +) DEFAULT_MEDIA_REPO = "" DEFAULT_NAMESPACE = "/" DEFAULT_LIMIT = 100 # you might get a DBUS timeout (no reply) if it lasts too long class Importer(DokuWiki): - - def __init__(self, url, user, passwd, media_repo=DEFAULT_MEDIA_REPO, limit=DEFAULT_LIMIT): + def __init__( + self, url, user, passwd, media_repo=DEFAULT_MEDIA_REPO, limit=DEFAULT_LIMIT + ): """ @param url (unicode): DokuWiki site URL @@ -120,7 +129,7 @@ @param post(dict): parsed post data @return (unicode): post unique item id """ - return unicode(post['id']) + return unicode(post["id"]) def getPostUpdated(self, post): """Return the update date. @@ -128,7 +137,7 @@ @param post(dict): parsed post data @return (unicode): update date """ - return unicode(post['mtime']) + return unicode(post["mtime"]) def getPostPublished(self, post): """Try to parse the date from the message ID, else use "mtime". @@ -179,22 +188,23 @@ # title = content.split("\n")[0].strip(u"\ufeff= ") # build the extra data dictionary - mb_data = {"id": id_, - "published": published, - "updated": updated, - "author": profile_jid.user, - # "content": content, # when passed, it is displayed in Libervia instead of content_xhtml - "content_xhtml": content_xhtml, - # "title": title, - "allow_comments": "true", - } + mb_data = { + "id": id_, + "published": published, + "updated": updated, + "author": profile_jid.user, + # "content": content, # when passed, it is displayed in Libervia instead of content_xhtml + "content_xhtml": content_xhtml, + # "title": title, + "allow_comments": "true", + } # find out if the message access is public or restricted namespace = id_.split(":")[0] if namespace and namespace.lower() not in ("public", "/"): mb_data["group"] = namespace # roster group must exist - self.posts_data[id_] = {'blog': mb_data, 'comments':[[]]} + self.posts_data[id_] = {"blog": mb_data, "comments": [[]]} def process(self, client, namespace=DEFAULT_NAMESPACE): """Process a namespace or a single page. @@ -206,7 +216,9 @@ try: pages_list = self.pages.list(namespace) except DokuWikiError: - log.warning('Could not list Dokuwiki pages: please turn the "display_errors" setting to "Off" in the php.ini of the webserver hosting DokuWiki.') + log.warning( + 'Could not list Dokuwiki pages: please turn the "display_errors" setting to "Off" in the php.ini of the webserver hosting DokuWiki.' + ) return if not pages_list: # namespace is actually a page? @@ -220,7 +232,7 @@ for page in pages_list: self.processPost(page, profile_jid) count += 1 - if count >= self.limit : + if count >= self.limit: break return (self.posts_data.itervalues(), len(self.posts_data)) @@ -334,14 +346,12 @@ log.error("Cannot create DokuWiki media thumbnail %s" % dest) - class DokuwikiImport(object): - def __init__(self, host): log.info(_("plugin Dokuwiki Import initialization")) self.host = host - self._blog_import = host.plugins['BLOG_IMPORT'] - self._blog_import.register('dokuwiki', self.DkImport, SHORT_DESC, LONG_DESC) + self._blog_import = host.plugins["BLOG_IMPORT"] + self._blog_import.register("dokuwiki", self.DkImport, SHORT_DESC, LONG_DESC) def DkImport(self, client, location, options=None): """Import from DokuWiki to PubSub @@ -367,14 +377,22 @@ try: media_repo = options["media_repo"] if opt_upload_images: - options[self._blog_import.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}") + options[ + self._blog_import.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 opt_upload_images: - info_msg = _("DokuWiki media files will be *uploaded* to the XMPP server. Hyperlinks to these media may not been updated though.") + 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.") + 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"] @@ -386,7 +404,11 @@ limit = DEFAULT_LIMIT dk_importer = Importer(location, user, passwd, media_repo, limit) - 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) + 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