diff sat/bridge/bridge_constructor/constructors/mediawiki/constructor.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/bridge/bridge_constructor/constructors/mediawiki/constructor.py	Wed Jun 27 07:51:29 2018 +0200
+++ b/sat/bridge/bridge_constructor/constructors/mediawiki/constructor.py	Wed Jun 27 20:14:46 2018 +0200
@@ -1,5 +1,5 @@
 #!/usr/bin/env python2
-#-*- coding: utf-8 -*-
+# -*- coding: utf-8 -*-
 
 # SàT: a XMPP client
 # Copyright (C) 2009-2018 Jérôme Poisson (goffi@goffi.org)
@@ -24,7 +24,6 @@
 
 
 class MediawikiConstructor(base_constructor.Constructor):
-
     def __init__(self, bridge_template, options):
         base_constructor.Constructor.__init__(self, bridge_template, options)
         self.core_template = "mediawiki_template.tpl"
@@ -35,10 +34,10 @@
 
         def anchor_link(match):
             link = match.group(1)
-            #we add anchor_link for [method_name] syntax:
+            # we add anchor_link for [method_name] syntax:
             if link in self.bridge_template.sections():
                 return "[[#%s|%s]]" % (link, link)
-            print ("WARNING: found an anchor link to an unknown method")
+            print("WARNING: found an anchor link to an unknown method")
             return link
 
         return re.sub(r"\[(\w+)\]", anchor_link, text)
@@ -51,12 +50,12 @@
         arg_doc = self.getArgumentsDoc(name)
         arg_default = self.getDefault(name)
         args_str = self.getArguments(sig_in)
-        args = args_str.split(', ') if args_str else []  # ugly but it works :)
+        args = args_str.split(", ") if args_str else []  # ugly but it works :)
         wiki = []
         for i in range(len(args)):
             if i in arg_doc:
                 name, doc = arg_doc[i]
-                doc = '\n:'.join(doc.rstrip('\n').split('\n'))
+                doc = "\n:".join(doc.rstrip("\n").split("\n"))
                 wiki.append("; %s: %s" % (name, self._addTextDecorations(doc)))
             else:
                 wiki.append("; arg_%d: " % i)
@@ -70,9 +69,13 @@
         """
         arg_doc = self.getArgumentsDoc(name)
         wiki = []
-        if 'return' in arg_doc:
-            wiki.append('\n|-\n! scope=row | return value\n|')
-            wiki.append('<br />\n'.join(self._addTextDecorations(arg_doc['return']).rstrip('\n').split('\n')))
+        if "return" in arg_doc:
+            wiki.append("\n|-\n! scope=row | return value\n|")
+            wiki.append(
+                "<br />\n".join(
+                    self._addTextDecorations(arg_doc["return"]).rstrip("\n").split("\n")
+                )
+            )
         return "\n".join(wiki)
 
     def generateCoreSide(self):
@@ -82,37 +85,49 @@
         sections.sort()
         for section in sections:
             function = self.getValues(section)
-            print ("Adding %s %s" % (section, function["type"]))
+            print("Adding %s %s" % (section, function["type"]))
             async_msg = """<br />'''This method is asynchronous'''"""
             deprecated_msg = """<br />'''<font color="#FF0000">/!\ WARNING /!\ : This method is deprecated, please don't use it !</font>'''"""
-            signature_signal = \
-            """\
+            signature_signal = (
+                """\
 ! scope=row | signature
 | %s
 |-\
-""" % function['sig_in']
-            signature_method = \
-            """\
+"""
+                % function["sig_in"]
+            )
+            signature_method = """\
 ! scope=row | signature in
 | %s
 |-
 ! scope=row | signature out
 | %s
 |-\
-""" % (function['sig_in'], function['sig_out'])
+""" % (
+                function["sig_in"],
+                function["sig_out"],
+            )
             completion = {
-                'signature': signature_signal if function['type'] == "signal" else signature_method,
-                'sig_out': function['sig_out'] or '',
-                'category': function['category'],
-                'name': section,
-                'doc': self.getDoc(section) or "FIXME: No description available",
-                'async': async_msg if "async" in self.getFlags(section) else "",
-                'deprecated': deprecated_msg if "deprecated" in self.getFlags(section) else "",
-                'parameters': self._wikiParameter(section, function['sig_in']),
-                'return': self._wikiReturn(section) if function['type'] == 'method' else ''}
+                "signature": signature_signal
+                if function["type"] == "signal"
+                else signature_method,
+                "sig_out": function["sig_out"] or "",
+                "category": function["category"],
+                "name": section,
+                "doc": self.getDoc(section) or "FIXME: No description available",
+                "async": async_msg if "async" in self.getFlags(section) else "",
+                "deprecated": deprecated_msg
+                if "deprecated" in self.getFlags(section)
+                else "",
+                "parameters": self._wikiParameter(section, function["sig_in"]),
+                "return": self._wikiReturn(section)
+                if function["type"] == "method"
+                else "",
+            }
 
-            dest = signals_part if function['type'] == "signal" else methods_part
-            dest.append("""\
+            dest = signals_part if function["type"] == "signal" else methods_part
+            dest.append(
+                """\
 == %(name)s ==
 ''%(doc)s''
 %(deprecated)s
@@ -126,28 +141,28 @@
 |
 %(parameters)s%(return)s
 |}
-""" % completion)
+"""
+                % completion
+            )
 
-        #at this point, signals_part, and methods_part should be filled,
-        #we just have to place them in the right part of the template
+        # at this point, signals_part, and methods_part should be filled,
+        # we just have to place them in the right part of the template
         core_bridge = []
         template_path = self.getTemplatePath(self.core_template)
         try:
             with open(template_path) as core_template:
                 for line in core_template:
-                    if line.startswith('##SIGNALS_PART##'):
+                    if line.startswith("##SIGNALS_PART##"):
                         core_bridge.extend(signals_part)
-                    elif line.startswith('##METHODS_PART##'):
+                    elif line.startswith("##METHODS_PART##"):
                         core_bridge.extend(methods_part)
-                    elif line.startswith('##TIMESTAMP##'):
-                        core_bridge.append('Generated on %s' % datetime.now())
+                    elif line.startswith("##TIMESTAMP##"):
+                        core_bridge.append("Generated on %s" % datetime.now())
                     else:
-                        core_bridge.append(line.replace('\n', ''))
+                        core_bridge.append(line.replace("\n", ""))
         except IOError:
-            print ("Can't open template file [%s]" % template_path)
+            print("Can't open template file [%s]" % template_path)
             sys.exit(1)
 
-        #now we write to final file
+        # now we write to final file
         self.finalWrite(self.core_dest, core_bridge)
-
-