from .xlate import XLATOR
-__version__ = '2.9.9'
+__version__ = '3.0.1'
LOG = logging.getLogger(__name__)
_ = XLATOR.gettext
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(
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):