From 5a9e3eeabf9f447516958ac562d171ec8ffcc90b Mon Sep 17 00:00:00 2001 From: Frank Brehm Date: Fri, 13 Oct 2023 12:40:39 +0200 Subject: [PATCH] Making linter happy --- bin/create-terraform | 2 +- lib/cr_tf/app.py | 91 +++++++++++++++++++++++--------------------- setup.cfg | 11 +++++- 3 files changed, 59 insertions(+), 45 deletions(-) diff --git a/bin/create-terraform b/bin/create-terraform index b1fcf63..def2528 100755 --- a/bin/create-terraform +++ b/bin/create-terraform @@ -70,4 +70,4 @@ if app.handler: sys.exit(0) -# vim: tabstop=4 expandtab shiftwidth=4 softtabstop=4 +# vim: tabstop=4 expandtab shiftwidth=4 softtabstop=4 diff --git a/lib/cr_tf/app.py b/lib/cr_tf/app.py index 7ddb457..87832c6 100644 --- a/lib/cr_tf/app.py +++ b/lib/cr_tf/app.py @@ -19,22 +19,17 @@ import signal from pathlib import Path # Third party modules - -# Own modules -from . import __version__ as __pkg_version__ -from . import CFGFILE_BASENAME - from fb_tools.common import pp - from fb_tools.app import BaseApplication - from fb_tools.errors import ExpectedHandlerError, CommandNotFoundError - from fb_tools.config import ConfigError - from fb_tools.common import generate_password -from .errors import TerraformHandlerError, TerraformVSphereError +# Own modules +from . import __version__ as __pkg_version__ +from . import CFGFILE_BASENAME + +from .errors import TerraformHandlerError from .config import CrTfConfiguration @@ -47,7 +42,7 @@ from .xlate import __base_dir__ as __xlate_base_dir__ from .xlate import __mo_file__ as __xlate_mo_file__ from .xlate import XLATOR, LOCALE_DIR, DOMAIN -__version__ = '1.3.1' +__version__ = '1.3.2' LOG = logging.getLogger(__name__) SIGNAL_NAMES = { @@ -217,6 +212,43 @@ class CrTfApplication(BaseApplication): self._cfg_dir = self.base_dir / 'etc' self._cfg_file = self.base_dir.parent / CFGFILE_BASENAME + # ------------------------------------------------------------------------- + def _warn_about_missing_cfg(self): + + cur_dir = Path.cwd() + + default_conf_file = self.cfg_dir / (CFGFILE_BASENAME + '.default') + default_cfg_file_rel = os.path.relpath(str(default_conf_file), str(cur_dir)) + + cfg1 = self.base_dir.parent / CFGFILE_BASENAME + cfg1 = os.path.relpath(str(cfg1), str(cur_dir)) + + cfg2 = self.base_dir.parent / 'etc' / CFGFILE_BASENAME + cfg2 = os.path.relpath(str(cfg2), str(cur_dir)) + + cfg3 = self.cfg_dir / CFGFILE_BASENAME + cfg3 = os.path.relpath(str(cfg3), str(cur_dir)) + + # cfg_file_rel = os.path.relpath(str(self.cfg_file), str(cur_dir)) + msg = (_( + "Config file {f!r} not found, using defaults.\n" + "To avoid this message, you may copy {d!r} to {c1!r}, {c2!r} or {c3!r} " + "and fill out all necessary entries, e.g. the passwords and API keys.").format( + f=CFGFILE_BASENAME, d=default_cfg_file_rel, c1=cfg1, c2=cfg2, c3=cfg3)) + LOG.warn(msg) + + # ------------------------------------------------------------------------- + def _read_cfg(self): + + if self.cfg_file.exists(): + try: + self.config.read() + except ConfigError as e: + LOG.error(_("Error in configuration:") + " " + str(e)) + self.exit(1) + if self.verbose > 3: + LOG.debug(_("Read configuration:") + '\n' + pp(self.config.as_dict())) + # ------------------------------------------------------------------------- def post_init(self): """ @@ -227,7 +259,6 @@ class CrTfApplication(BaseApplication): This method could be overwritten by descendant classes, these methhods should allways include a call to post_init() of the parent class. - """ self.initialized = False @@ -239,26 +270,7 @@ class CrTfApplication(BaseApplication): self.perform_arg_parser() if not self.cfg_file.exists(): - cur_dir = Path(os.getcwd()) - default_conf_file = self.cfg_dir / (CFGFILE_BASENAME + '.default') - default_cfg_file_rel = os.path.relpath(str(default_conf_file), str(cur_dir)) - - cfg1 = self.base_dir.parent / CFGFILE_BASENAME - cfg1 = os.path.relpath(str(cfg1), str(cur_dir)) - - cfg2 = self.base_dir.parent / 'etc' / CFGFILE_BASENAME - cfg2 = os.path.relpath(str(cfg2), str(cur_dir)) - - cfg3 = self.cfg_dir / CFGFILE_BASENAME - cfg3 = os.path.relpath(str(cfg3), str(cur_dir)) - - cfg_file_rel = os.path.relpath(str(self.cfg_file), str(cur_dir)) - msg = (_( - "Config file {f!r} not found, using defaults.\n" - "To avoid this message, you may copy {d!r} to {c1!r}, {c2!r} or {c3!r} " - "and fill out all necessary entries, e.g. the passwords and API keys.").format( - f=CFGFILE_BASENAME, d=default_cfg_file_rel, c1=cfg1, c2=cfg2, c3=cfg3)) - LOG.warn(msg) + self._warn_about_missing_cfg() self.config = CrTfConfiguration( appname=self.appname, verbose=self.verbose, base_dir=self.base_dir, @@ -266,14 +278,7 @@ class CrTfApplication(BaseApplication): self.config.init_vsphere_defaults() - if self.cfg_file.exists(): - try: - self.config.read() - except ConfigError as e: - LOG.error(_("Error in configuration:") + " " + str(e)) - self.exit(1) - if self.verbose > 3: - LOG.debug(_("Read configuration:") + '\n' + pp(self.config.as_dict())) + self._read_cfg() if self.config.verbose > self.verbose: self.verbose = self.config.verbose @@ -518,7 +523,7 @@ class CrTfApplication(BaseApplication): need_nl = True msg = '\n' + _("Please input the {}.").format(self.colored( - _('vSphere user name'), 'AQUA')) + _('vSphere user name'), 'AQUA')) print(msg) self.handler.vsphere_user = input(self.colored(_('Name'), 'AQUA') + ': ') if not self.handler.vsphere_user: @@ -538,9 +543,9 @@ class CrTfApplication(BaseApplication): if need_nl: print('') prompt = self.colored(_("User password of {!r}").format( - self.handler.vsphere_user), 'AQUA') + self.handler.vsphere_user), 'AQUA') item = _('Password for user {u!r} of vSphere {n} on {h!r}').format( - u=self.handler.vsphere_user, n=vname, h=self.config.vsphere[vname].host) + u=self.handler.vsphere_user, n=vname, h=self.config.vsphere[vname].host) item = self.colored(item, 'AQUA') self.handler.vsphere_password = self.get_secret(prompt=prompt, item_name=item) if not self.handler.vsphere_password: diff --git a/setup.cfg b/setup.cfg index a9b7859..69c75d5 100644 --- a/setup.cfg +++ b/setup.cfg @@ -8,7 +8,7 @@ license = LGPL3+ platforms = posix provides = create_terraform classifiers = - Development Status :: 3 - Alpha + Development Status :: 4 - Beta Environment :: Console Intended Audience :: System Administrators License :: OSI Approved :: GNU Lesser General Public License v3 or later (LGPLv3+) @@ -19,6 +19,8 @@ classifiers = Programming Language :: Python :: 3.7 Programming Language :: Python :: 3.8 Programming Language :: Python :: 3.9 + Programming Language :: Python :: 3.10 + Programming Language :: Python :: 3.11 Topic :: System :: Systems Administration [options] @@ -55,4 +57,11 @@ statistics = 1 max-line-length = 99 +[flake8] + +max-line-length = 99 +max-complexity = 20 +ignore = E226,E302,E41,E402,B902 + + # vim: filetype=dosini -- 2.39.5