LOG.info(_("Reading metadata files of environment {!r} ...").format(env))
- pattern = os.path.join(self.puppet_root_env_dir, env, 'modules', '*')
- if self.verbose > 2:
- LOG.debug("Globbing pattern for module directories: {!r}".format(pattern))
+ #pattern = os.path.join(self.puppet_root_env_dir, env, 'modules', '*')
+ #if self.verbose > 2:
+ # LOG.debug("Globbing pattern for module directories: {!r}".format(str(pattern)))
+
+ modules_dir = self.puppet_root_env_dir / env / 'modules'
- for module_dir in glob.glob(pattern):
+ #for module_dir in glob.glob(str(pattern)):
+ for module_dir in modules_dir.glob('*'):
module_info = self.get_meta_module_info(module_dir, env)
if module_info:
if self.verbose > 1:
def get_meta_module_info(self, module_dir, env):
if self.verbose > 1:
- LOG.debug("Get module information from {!r}.".format(module_dir))
+ LOG.debug("Get module information from {!r}.".format(str(module_dir)))
- if not os.path.exists(module_dir):
- LOG.warn(_("Directory {!r} does not exists.").format(module_dir))
+ if not module_dir.exists():
+ LOG.warn(_("Directory {!r} does not exists.").format(str(module_dir)))
return None
- if not os.path.isdir(module_dir):
- LOG.warn(_("Path {!r} is not a directory.").format(module_dir))
+ if not module_dir.is_dir():
+ LOG.warn(_("Path {!r} is not a directory.").format(str(module_dir)))
return None
- metadata_file = os.path.join(module_dir, 'metadata.json')
- if not os.path.exists(metadata_file):
- LOG.warn(_("Metadatafile {!r} does not exists.").format(metadata_file))
+ metadata_file = module_dir / 'metadata.json'
+ if not metadata_file.exists():
+ LOG.warn(_("Metadatafile {!r} does not exists.").format(str(metadata_file)))
return None
- if not os.path.isfile(metadata_file):
- LOG.warn(_("Metadatafile {!r} is not a regular file.").format(metadata_file))
+ if not metadata_file.is_file():
+ LOG.warn(_("Metadatafile {!r} is not a regular file.").format(str(metadata_file)))
return None
- if not os.access(metadata_file, os.R_OK):
- LOG.warn(_("No read access to metadatafile {!r}.").format(metadata_file))
+ if not os.access(str(metadata_file), os.R_OK):
+ LOG.warn(_("No read access to metadatafile {!r}.").format(str(metadata_file)))
return None
if self.verbose > 2:
- LOG.debug("Reading and evaluating {!r}.".format(metadata_file))
+ LOG.debug("Reading and evaluating {!r}.".format(str(metadata_file)))
json_data = None
try:
- with open(metadata_file, 'r', **self.open_args) as fh:
+ with open(str(metadata_file), 'r', **self.open_args) as fh:
json_data = json.load(fh)
except ValueError as e:
LOG.warn(_("Could not interprete {f!r} as a regular JSON file: {e}").format(
- f=metadata_file, e=e))
+ f=str(metadata_file), e=e))
return None
if not json_data:
- LOG.warn(_("Did not found any data in {!r}.").format(metadata_file))
+ LOG.warn(_("Did not found any data in {!r}.").format(str(metadata_file)))
return None
return ModuleInfo.init_from_json(
# -------------------------------------------------------------------------
def init_puppet_environments(self):
- LOG.debug("Collecting all Puppet environments in {!r}.".format(self.puppet_root_env_dir))
- pattern = os.path.join(self.puppet_root_env_dir, '*')
+ LOG.debug("Collecting all Puppet environments in {!r}.".format(
+ str(self.puppet_root_env_dir)))
+ pattern = os.path.join(str(self.puppet_root_env_dir), '*')
dirs = glob.glob(pattern)
self.environments = []
- for path in dirs:
- if os.path.isdir(path):
- env = os.path.basename(path)
+ for rpath in dirs:
+ path = pathlib.Path(rpath)
+ if path.is_dir():
+ env = path.name
self.environments.append(env)
self.environments.sort(key=str.lower)
def write_cache_file(self):
output_file = self.cachefile
- tmp_file = output_file + '.new'
+ tmp_file = pathlib.Path(str(output_file) + '.new')
fd = None
LOG.debug("Sorting found modules ...")
return
try:
- fd = os.open(tmp_file, os.O_CREAT | os.O_EXCL | os.O_WRONLY, 0o644)
+ fd = os.open(str(tmp_file), os.O_CREAT | os.O_EXCL | os.O_WRONLY, 0o644)
fcntl.flock(fd, fcntl.LOCK_EX | fcntl.LOCK_NB)
except OSError as e:
msg = _("Error on creating file {f!r}: {e}").format(f=tmp_file, e=e)
finally:
os.close(fd)
- if os.path.exists(output_file) and not os.geteuid():
- fstat = os.stat(output_file)
+ if output_file.exists() and not os.geteuid():
+ fstat = output_file.stat()
user = fstat.st_uid
try:
user = pwd.getpwuid(fstat.st_uid).pw_name
group = fstat.st_gid
LOG.debug("Chowning {f!r} to {u}:{g} ...".format(
f=tmp_file, u=user, g=group))
- os.chown(tmp_file, fstat.st_uid, fstat.st_gid)
+ os.chown(str(tmp_file), fstat.st_uid, fstat.st_gid)
- LOG.info(_("Renaming {src!r} => {tgt!r}.").format(src=tmp_file, tgt=output_file))
- os.rename(tmp_file, output_file)
+ LOG.info(_("Renaming {src!r} => {tgt!r}.").format(
+ src=str(tmp_file), tgt=(output_file)))
+ tmp_file.rename(output_file)
# =============================================================================