from .obj import BaseObjectError
from .obj import BaseObject
-__version__ = '0.5.1'
+__version__ = '0.6.1'
LOG = logging.getLogger(__name__)
return module_info
+ # -------------------------------------------------------------------------
+ @classmethod
+ def init_from_data(cls, data, appname=None, verbose=0, base_dir=None):
+ """Reverse method of to_data()."""
+
+ if verbose > 3:
+ LOG.debug("Trying to init module_info from:\n{}".format(pp(data)))
+
+ if 'full_name' not in data:
+ LOG.warn("Did not found module name in data.")
+ return None
+
+ module_info = None
+
+ try:
+ module_info = cls(
+ appname=appname, verbose=verbose, base_dir=base_dir,
+ full_name=data['full_name'],
+ )
+ except ModuleInfoError as e:
+ LOG.warn("{c}: {e}".format(c=e.__class__.__name__, e=e))
+ return None
+
+ if 'full_name_orig' in data:
+ module_info._full_name_orig = data['full_name_orig']
+
+ if 'forge_version' in data:
+ module_info.forge_version = data['forge_version']
+
+ if 'forge_avail' in data:
+ module_info._full_name_orig = data['forge_avail']
+
+ if 'forge_homepage_url' in data:
+ module_info.forge_homepage_url = data['forge_homepage_url']
+
+ if 'forge_source' in data:
+ module_info.forge_source = data['forge_source']
+
+ if 'repo' in data:
+ module_info.repo = data['repo']
+
+ if 'ts_checked' in data:
+ module_info.ts_checked = data['ts_checked']
+
+ if 'local_versions' in data:
+ module_info.local_versions = copy.copy(data['local_versions'])
+
+ if 'expected_versions' in data:
+ module_info.expected_versions = copy.copy(data['expected_versions'])
+
+ if 'forge_releases' in data:
+ module_info.forge_releases = copy.copy(data['forge_releases'])
+
+ return module_info
+
# -------------------------------------------------------------------------
@classmethod
def init_from_puppetfile_line(cls, line, env, appname=None, verbose=0, base_dir=None):
LOG.debug("Reading {!r} ...".format(self.cache_file))
try:
with open(self.cache_file, 'r', **self.open_args) as fh:
- for struct in yaml.load_all(fh):
- data.append(struct)
+ for struct in yaml.load(fh):
+ module_info = ModuleInfo.init_from_data(
+ struct, appname=self.appname, verbose=self.verbose,
+ base_dir=self.base_dir)
+ if module_info:
+ data.append(module_info)
except yaml.YAMLError as e:
raise ShowModulesUncriticalError(
"Could not evaluate content of {f!r}: {e}".format(f=self.cache_file, e=e))