diff sat/bridge/bridge_constructor/bridge_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/bridge_constructor.py	Wed Jun 27 07:51:29 2018 +0200
+++ b/sat/bridge/bridge_constructor/bridge_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)
@@ -23,23 +23,24 @@
 from sat.bridge.bridge_constructor import constructors, base_constructor
 import argparse
 from ConfigParser import SafeConfigParser as Parser
-from importlib  import import_module
+from importlib import import_module
 import os
 import os.path
 
-#consts
+# consts
 __version__ = C.APP_VERSION
 
 
 class BridgeConstructor(object):
-
     def importConstructors(self):
         constructors_dir = os.path.dirname(constructors.__file__)
         self.protocoles = {}
         for dir_ in os.listdir(constructors_dir):
-            init_path = os.path.join(constructors_dir, dir_, '__init__.py')
-            constructor_path = os.path.join(constructors_dir, dir_, 'constructor.py')
-            module_path = "sat.bridge.bridge_constructor.constructors.{}.constructor".format(dir_)
+            init_path = os.path.join(constructors_dir, dir_, "__init__.py")
+            constructor_path = os.path.join(constructors_dir, dir_, "constructor.py")
+            module_path = "sat.bridge.bridge_constructor.constructors.{}.constructor".format(
+                dir_
+            )
             if os.path.isfile(init_path) and os.path.isfile(constructor_path):
                 mod = import_module(module_path)
                 for attr in dir(mod):
@@ -55,27 +56,66 @@
 
     def parse_args(self):
         """Check command line options"""
-        parser = argparse.ArgumentParser(description=C.DESCRIPTION, formatter_class=argparse.RawDescriptionHelpFormatter)
+        parser = argparse.ArgumentParser(
+            description=C.DESCRIPTION,
+            formatter_class=argparse.RawDescriptionHelpFormatter,
+        )
 
-        parser.add_argument("--version", action="version", version= __version__)
-        default_protocole = C.DEFAULT_PROTOCOLE if C.DEFAULT_PROTOCOLE in self.protocoles else self.protocoles[0]
-        parser.add_argument("-p", "--protocole", choices=sorted(self.protocoles), default=default_protocole,
-            help="generate bridge using PROTOCOLE (default: %(default)s)") # (default: %s, possible values: [%s])" % (DEFAULT_PROTOCOLE, ", ".join(MANAGED_PROTOCOLES)))
-        parser.add_argument("-s", "--side", choices=("core", "frontend"), default="core",
-            help="which side of the bridge do you want to make ?") # (default: %default, possible values: [core, frontend])")
-        default_template = os.path.join(os.path.dirname(bridge_constructor.__file__), 'bridge_template.ini')
-        parser.add_argument("-t", "--template", type=file, default=default_template,
-            help="use TEMPLATE to generate bridge (default: %(default)s)")
-        parser.add_argument("-f", "--force", action="store_true",
-            help=("force overwritting of existing files"))
-        parser.add_argument("-d", "--debug", action="store_true",
-            help=("add debug information printing"))
-        parser.add_argument("--no-unicode", action="store_false", dest="unicode",
-            help=("remove unicode type protection from string results"))
-        parser.add_argument("--flags", nargs='+', default=[],
-            help=("constructors' specific flags"))
-        parser.add_argument("--dest-dir", default=C.DEST_DIR_DEFAULT,
-            help=("directory when the generated files will be written (default: %(default)s)"))
+        parser.add_argument("--version", action="version", version=__version__)
+        default_protocole = (
+            C.DEFAULT_PROTOCOLE
+            if C.DEFAULT_PROTOCOLE in self.protocoles
+            else self.protocoles[0]
+        )
+        parser.add_argument(
+            "-p",
+            "--protocole",
+            choices=sorted(self.protocoles),
+            default=default_protocole,
+            help="generate bridge using PROTOCOLE (default: %(default)s)",
+        )  # (default: %s, possible values: [%s])" % (DEFAULT_PROTOCOLE, ", ".join(MANAGED_PROTOCOLES)))
+        parser.add_argument(
+            "-s",
+            "--side",
+            choices=("core", "frontend"),
+            default="core",
+            help="which side of the bridge do you want to make ?",
+        )  # (default: %default, possible values: [core, frontend])")
+        default_template = os.path.join(
+            os.path.dirname(bridge_constructor.__file__), "bridge_template.ini"
+        )
+        parser.add_argument(
+            "-t",
+            "--template",
+            type=file,
+            default=default_template,
+            help="use TEMPLATE to generate bridge (default: %(default)s)",
+        )
+        parser.add_argument(
+            "-f",
+            "--force",
+            action="store_true",
+            help=("force overwritting of existing files"),
+        )
+        parser.add_argument(
+            "-d", "--debug", action="store_true", help=("add debug information printing")
+        )
+        parser.add_argument(
+            "--no-unicode",
+            action="store_false",
+            dest="unicode",
+            help=("remove unicode type protection from string results"),
+        )
+        parser.add_argument(
+            "--flags", nargs="+", default=[], help=("constructors' specific flags")
+        )
+        parser.add_argument(
+            "--dest-dir",
+            default=C.DEST_DIR_DEFAULT,
+            help=(
+                "directory when the generated files will be written (default: %(default)s)"
+            ),
+        )
 
         return parser.parse_args()
 
@@ -86,7 +126,7 @@
         try:
             template_parser.readfp(args.template)
         except IOError:
-            print ("The template file doesn't exist or is not accessible")
+            print("The template file doesn't exist or is not accessible")
             exit(1)
         constructor = self.protocoles[args.protocole](template_parser, args)
         constructor.generate(args.side)