]> Frank Brehm's Git Trees - pixelpark/create-terraform.git/commitdiff
Detection for existence of configuration file.
authorFrank Brehm <frank.brehm@pixelpark.com>
Wed, 25 Sep 2019 13:15:13 +0000 (15:15 +0200)
committerFrank Brehm <frank.brehm@pixelpark.com>
Wed, 25 Sep 2019 13:15:13 +0000 (15:15 +0200)
lib/cr_tf/__init__.py
lib/cr_tf/app.py

index 91409ddb560aa7af4a75275a45b06ba36ebc6c42..72c7bad37dd4e5b759d305c9d821a88f0de52614 100644 (file)
@@ -1,11 +1,13 @@
 #!/bin/env python3
 # -*- coding: utf-8 -*-
 
-__version__ = '1.3.0'
+__version__ = '1.3.1'
 
 MIN_VERSION_TERRAFORM = '0.12.0'
 MAX_VERSION_TERRAFORM = '0.12.99'
 
 MIN_VERSION_VSPHERE_PROVIDER = '1.11.0'
 
+CFGFILE_BASENAME = 'create-terraform.ini'
+
 # vim: ts=4 et list
index 358ef232e18f09a59d6adee350f3e6b3593d9696..1aeba33ac55bd201e76e26ee617fb2fa9bd685cc 100644 (file)
@@ -22,6 +22,7 @@ from pathlib import Path
 
 # Own modules
 from . import __version__ as __pkg_version__
+from . import CFGFILE_BASENAME
 
 from fb_tools.common import pp
 
@@ -42,7 +43,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.0.4'
+__version__ = '1.0.5'
 LOG = logging.getLogger(__name__)
 
 SIGNAL_NAMES = {
@@ -168,6 +169,7 @@ class CrTfApplication(BaseApplication):
         self.yaml_file = None
         self.config = None
         self.handler = None
+        self._cfg_dir = None
         self._cfg_file = None
 
         desc = _(
@@ -179,6 +181,12 @@ class CrTfApplication(BaseApplication):
             description=desc, terminal_has_colors=terminal_has_colors, initialized=False,
         )
 
+    # -------------------------------------------------------------------------
+    @property
+    def cfg_dir(self):
+        """Directory of the configuration file."""
+        return self._cfg_dir
+
     # -------------------------------------------------------------------------
     @property
     def cfg_file(self):
@@ -202,8 +210,20 @@ class CrTfApplication(BaseApplication):
 
         self.init_logging()
 
+        self._cfg_dir = self.base_dir.joinpath('etc')
+        self._cfg_file = self.cfg_dir.joinpath(CFGFILE_BASENAME)
+
         self.perform_arg_parser()
 
+        if not self.cfg_file.exists():
+            default_conf_file = self.cfg_dir.joinpath(CFGFILE_BASENAME + '.default')
+            msg = (_(
+                "Configuration file {f!r} does not exists. Please copy {d!r} to {f!r} and "
+                "fill out all necessary entries, e.g. the passwords and API keys.").format(
+                    f=str(self.cfg_file), d=str(default_conf_file)))
+            LOG.error(msg)
+            self.exit(1)
+
         self.config = CrTfConfiguration(
             appname=self.appname, verbose=self.verbose, base_dir=self.base_dir,
             config_file=self.cfg_file)
@@ -286,6 +306,7 @@ class CrTfApplication(BaseApplication):
 
         res = super(CrTfApplication, self).as_dict(short=short)
 
+        res['cfg_dir'] = self.cfg_dir
         res['cfg_file'] = self.cfg_file
         res['__pkg_version__'] = __pkg_version__
         res['config'] = None