from .puppetfile import PuppetfileError, Puppetfile
+from .module_meta_info import ModuleMetadata
+
from .forge.mod_dict import ForgeModuleDict
from .xlate import __module_dir__ as __xlate_module_dir__
raise BaseHookError(
_("Did not found environments in {!r}.").format(self.puppet_root_env_dir))
+ # -------------------------------------------------------------------------
+ def collect_local_modules(self):
+
+ for env in self.environments:
+ LOG.debug("Evaluating environment {!r} ..".format(env))
+ pfile_modules = self.read_puppetfile(env)
+ if pfile_modules:
+ for module_info in pfile_modules.values():
+ self.env_modules[env].append(module_info)
+ self.read_metadata_files(env)
+ if self.verbose > 2:
+ LOG.debug("ModuleInfoDict:\n{}".format(pp(self.env_modules[env].as_dict())))
+
+ # -------------------------------------------------------------------------
+ def read_metadata_files(self, env):
+
+ LOG.info(_("Reading metadata files of environment {!r} ...").format(env))
+
+ modules_dir = self.puppet_root_env_dir / env / 'modules'
+
+ for module_dir in modules_dir.glob('*'):
+ module_info = self.get_meta_module_info(module_dir, env)
+ if module_info:
+ if self.verbose > 1:
+ LOG.debug("Got infos about module {!r}".format(module_info.full_name))
+ elif self.verbose > 2:
+ LOG.debug("Got module info:\n{}".format(pp(module_info.as_dict())))
+ self.env_modules[env].merge(module_info)
+ else:
+ LOG.warn(_("Got no module info from directory {!r}.").format(module_dir))
+
+ # -------------------------------------------------------------------------
+ def get_meta_module_info(self, module_dir, env):
+
+ if self.verbose > 1:
+ LOG.debug("Get module information from {!r}.".format(str(module_dir)))
+
+ if not module_dir.exists():
+ LOG.warn(_("Directory {!r} does not exists.").format(str(module_dir)))
+ return None
+
+ if not module_dir.is_dir():
+ LOG.warn(_("Path {!r} is not a directory.").format(str(module_dir)))
+ return None
+
+ 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 metadata_file.is_file():
+ LOG.warn(_("Metadatafile {!r} is not a regular file.").format(str(metadata_file)))
+ return None
+ 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(str(metadata_file)))
+
+ json_data = None
+ try:
+ 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=str(metadata_file), e=e))
+ return None
+ if not json_data:
+ LOG.warn(_("Did not found any data in {!r}.").format(str(metadata_file)))
+ return None
+
+ metadata = ModuleMetadata.from_json_data(
+ json_data, appname=self.appname, verbose=self.verbose, base_dir=self.base_dir)
+ if self.verbose > 3:
+ LOG.debug("ModuleMetadata:\n{}".format(pp(metadata.as_dict())))
+ if self.verbose > 2:
+ LOG.debug("ModuleMetadata: got a {c} object:\n{s}".format(
+ c=metadata.__class__.__name__, s=metadata))
+
+ return ModuleInfo.init_from_json(
+ json_data, env, appname=self.appname, verbose=self.verbose, base_dir=self.base_dir)
+
# =============================================================================
if __name__ == "__main__":
self.collect_local_modules()
if self.do_forge:
self.get_forge_information()
-
- self.forge_modules.write_file()
+ self.forge_modules.write_file()
print()
d = datetime.datetime.now(LOCALTZ)
msg = _("[{}]: Finished.").format(dt)
self.print_out(msg)
- # -------------------------------------------------------------------------
- def collect_local_modules(self):
-
- for env in self.environments:
- LOG.debug("Evaluating environment {!r} ..".format(env))
- pfile_modules = self.read_puppetfile(env)
- if pfile_modules:
- for module_info in pfile_modules.values():
- self.env_modules[env].append(module_info)
- self.read_metadata_files(env)
- if self.verbose > 2:
- LOG.debug("ModuleInfoDict:\n{}".format(pp(self.env_modules[env].as_dict())))
-
# -------------------------------------------------------------------------
def get_forge_information(self):
return module_info
- # -------------------------------------------------------------------------
- def read_metadata_files(self, env):
-
- LOG.info(_("Reading metadata files of environment {!r} ...").format(env))
-
- modules_dir = self.puppet_root_env_dir / env / 'modules'
-
- for module_dir in modules_dir.glob('*'):
- module_info = self.get_meta_module_info(module_dir, env)
- if module_info:
- if self.verbose > 1:
- LOG.debug("Got infos about module {!r}".format(module_info.full_name))
- elif self.verbose > 2:
- LOG.debug("Got module info:\n{}".format(pp(module_info.as_dict())))
- self.env_modules[env].merge(module_info)
- else:
- LOG.warn(_("Got no module info from directory {!r}.").format(module_dir))
-
- # -------------------------------------------------------------------------
- def get_meta_module_info(self, module_dir, env):
-
- if self.verbose > 1:
- LOG.debug("Get module information from {!r}.".format(str(module_dir)))
-
- if not module_dir.exists():
- LOG.warn(_("Directory {!r} does not exists.").format(str(module_dir)))
- return None
-
- if not module_dir.is_dir():
- LOG.warn(_("Path {!r} is not a directory.").format(str(module_dir)))
- return None
-
- 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 metadata_file.is_file():
- LOG.warn(_("Metadatafile {!r} is not a regular file.").format(str(metadata_file)))
- return None
- 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(str(metadata_file)))
-
- json_data = None
- try:
- 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=str(metadata_file), e=e))
- return None
- if not json_data:
- LOG.warn(_("Did not found any data in {!r}.").format(str(metadata_file)))
- return None
-
- metadata = ModuleMetadata.from_json_data(
- json_data, appname=self.appname, verbose=self.verbose, base_dir=self.base_dir)
- if self.verbose > 3:
- LOG.debug("ModuleMetadata:\n{}".format(pp(metadata.as_dict())))
- if self.verbose > 2:
- LOG.debug("ModuleMetadata: got a {c} object:\n{s}".format(
- c=metadata.__class__.__name__, s=metadata))
-
- return ModuleInfo.init_from_json(
- json_data, env, appname=self.appname, verbose=self.verbose, base_dir=self.base_dir)
-
# =============================================================================