]> Frank Brehm's Git Trees - pixelpark/create-terraform.git/commitdiff
Fixing path actions
authorFrank Brehm <frank@brehm-online.com>
Fri, 18 Oct 2019 13:33:02 +0000 (15:33 +0200)
committerFrank Brehm <frank@brehm-online.com>
Fri, 18 Oct 2019 13:33:02 +0000 (15:33 +0200)
lib/cr_tf/handler.py

index c6d73003addd16fe71a23603929cd4b901f28dff..7b2ca8ad7744a63d70808dc220974ede5f9aa4f4 100644 (file)
@@ -61,7 +61,7 @@ from .terraform.disk import TerraformDisk
 
 from .xlate import XLATOR
 
-__version__ = '2.9.9'
+__version__ = '3.0.1'
 LOG = logging.getLogger(__name__)
 
 _ = XLATOR.gettext
@@ -1969,15 +1969,20 @@ class CreateTerraformHandler(BaseHandler):
         if self.verbose > 1:
             LOG.debug(_("Checking {!r} for a previous terraform configuration.").format(
                 str(self.project_dir)))
-        if os.path.exists('.terraform') and not os.path.isdir('.terraform'):
+
+        tf_path = self.project_dir / '.terraform'
+        if tf_path.exists() and not tf_path.is_dir():
             msg = _("In {d!r} there exists already {w!r}, but this is not a directory.").format(
                 d=str(self.project_dir), w='.terraform')
             raise ExpectedHandlerError(msg)
-        if os.path.exists('terraform.tfstate') and not os.path.isfile('terraform.tfstate'):
+
+        state_path = self.project_dir / 'terraform.tfstate'
+        if state_path.exists() and not state_path.is_file():
             msg = _("In {d!r} there exists already {w!r}, but this not a file.").format(
                 d=str(self.project_dir), w='terraform.tfstate')
             raise ExpectedHandlerError(msg)
-        if os.path.isdir('.terraform') and os.path.isfile('terraform.tfstate'):
+
+        if tf_path.is_dir() and state_path.is_file():
             msg = _(
                 "In directory {d!r} there are already existing both {w1!r} and {w2!r}. "
                 "Is this an old terraform project?").format(
@@ -1990,19 +1995,24 @@ class CreateTerraformHandler(BaseHandler):
         print()
         LOG.info(_("Cleaning project directory {!r}.").format(str(self.project_dir)))
 
-        files = glob.glob('*') + glob.glob('.terraform')
+        files = []
+        for path in self.project_dir.glob('*'):
+            files.append(path)
+        for path in self.project_dir.glob('.terraform'):
+            files.append(path)
+
         if not files:
             LOG.debug(_("Directory {!r} is already clean.").format(str(self.project_dir)))
             return
         for pfile in files:
-            if os.path.isdir(pfile):
-                LOG.debug(_("Removing recursive directory {!r} ...").format(pfile))
+            if pfile.is_dir():
+                LOG.debug(_("Removing recursive directory {!r} ...").format(str(pfile)))
                 if not self.simulate:
-                    shutil.rmtree(pfile)
+                    shutil.rmtree(str(pfile))
             else:
-                LOG.debug(_("Removing {!r} ...").format(pfile))
+                LOG.debug(_("Removing {!r} ...").format(str(pfile)))
                 if not self.simulate:
-                    os.remove(pfile)
+                    pfile.unlink()
 
     # --------------------------------------------------------------------------
     def create_terraform_files(self):