Mercurial > libervia-backend
diff sat/plugins/plugin_blog_import_dokuwiki.py @ 4037:524856bd7b19
massive refactoring to switch from camelCase to snake_case:
historically, Libervia (SàT before) was using camelCase as allowed by PEP8 when using a
pre-PEP8 code, to use the same coding style as in Twisted.
However, snake_case is more readable and it's better to follow PEP8 best practices, so it
has been decided to move on full snake_case. Because Libervia has a huge codebase, this
ended with a ugly mix of camelCase and snake_case.
To fix that, this patch does a big refactoring by renaming every function and method
(including bridge) that are not coming from Twisted or Wokkel, to use fully snake_case.
This is a massive change, and may result in some bugs.
author | Goffi <goffi@goffi.org> |
---|---|
date | Sat, 08 Apr 2023 13:54:42 +0200 |
parents | be6d91572633 |
children |
line wrap: on
line diff
--- a/sat/plugins/plugin_blog_import_dokuwiki.py Fri Apr 07 15:18:39 2023 +0200 +++ b/sat/plugins/plugin_blog_import_dokuwiki.py Sat Apr 08 13:54:42 2023 +0200 @@ -123,7 +123,7 @@ self.limit = limit self.posts_data = OrderedDict() - def getPostId(self, post): + def get_post_id(self, post): """Return a unique and constant post id @param post(dict): parsed post data @@ -131,7 +131,7 @@ """ return str(post["id"]) - def getPostUpdated(self, post): + def get_post_updated(self, post): """Return the update date. @param post(dict): parsed post data @@ -139,7 +139,7 @@ """ return str(post["mtime"]) - def getPostPublished(self, post): + def get_post_published(self, post): """Try to parse the date from the message ID, else use "mtime". The date can be extracted if the message ID looks like one of: @@ -162,16 +162,16 @@ return default return str(calendar.timegm(time_struct)) - def processPost(self, post, profile_jid): + def process_post(self, post, profile_jid): """Process a single page. @param post (dict): parsed post data @param profile_jid """ # get main information - id_ = self.getPostId(post) - updated = self.getPostUpdated(post) - published = self.getPostPublished(post) + id_ = self.get_post_id(post) + updated = self.get_post_updated(post) + published = self.get_post_published(post) # manage links backlinks = self.pages.backlinks(id_) @@ -182,7 +182,7 @@ backlinks.append(page[1:] if page.startswith(":") else page) self.pages.get(id_) - content_xhtml = self.processContent(self.pages.html(id_), backlinks, profile_jid) + content_xhtml = self.process_content(self.pages.html(id_), backlinks, profile_jid) # XXX: title is already in content_xhtml and difficult to remove, so leave it # title = content.split("\n")[0].strip(u"\ufeff= ") @@ -230,14 +230,14 @@ count = 0 for page in pages_list: - self.processPost(page, profile_jid) + self.process_post(page, profile_jid) count += 1 if count >= self.limit: break return (iter(self.posts_data.values()), len(self.posts_data)) - def processContent(self, text, backlinks, profile_jid): + def process_content(self, text, backlinks, profile_jid): """Do text substitutions and file copy. @param text (unicode): message content @@ -259,7 +259,7 @@ if re.match(r"^\w*://", link): # absolute URL to link directly continue if self.media_repo: - self.moveMedia(link, subs) + self.move_media(link, subs) elif link not in subs: subs[link] = urllib.parse.urljoin(self.url, link) @@ -267,7 +267,7 @@ text = text.replace(url, new_url) return text - def moveMedia(self, link, subs): + def move_media(self, link, subs): """Move a media from the DokuWiki host to the new repository. This also updates the hyperlinks to internal media files. @@ -304,17 +304,17 @@ return filepath = os.path.join(self.temp_dir, filename) - self.downloadMedia(url, filepath) + self.download_media(url, filepath) if thumb_width: filename = os.path.join("thumbs", thumb_width, filename) thumbnail = os.path.join(self.temp_dir, filename) - self.createThumbnail(filepath, thumbnail, thumb_width) + self.create_thumbnail(filepath, thumbnail, thumb_width) new_url = os.path.join(self.media_repo, filename) subs[link] = new_url - def downloadMedia(self, source, dest): + def download_media(self, source, dest): """Copy media to localhost. @param source (unicode): source url @@ -327,7 +327,7 @@ urllib.request.urlretrieve(source, dest) log.debug("DokuWiki media file copied to %s" % dest) - def createThumbnail(self, source, dest, width): + def create_thumbnail(self, source, dest, width): """Create a thumbnail. @param source (unicode): source file path @@ -348,13 +348,13 @@ class DokuwikiImport(object): def __init__(self, host): - log.info(_("plugin Dokuwiki Import initialization")) + 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.register("dokuwiki", self.dk_import, SHORT_DESC, LONG_DESC) - def DkImport(self, client, location, options=None): - """Import from DokuWiki to PubSub + def dk_import(self, client, location, options=None): + """import from DokuWiki to PubSub @param location (unicode): DokuWiki site URL @param options (dict, None): DokuWiki import parameters @@ -407,7 +407,7 @@ info_msg = info_msg.format( temp_dir=dk_importer.temp_dir, media_repo=media_repo, location=location ) - self.host.actionNew( + self.host.action_new( {"xmlui": xml_tools.note(info_msg).toXml()}, profile=client.profile ) d = threads.deferToThread(dk_importer.process, client, namespace)