From: Frank Brehm Date: Fri, 15 Mar 2019 12:48:39 +0000 (+0100) Subject: Splitting method ModuleMetadata.from_json_data() X-Git-Tag: 1.6.4^2~22 X-Git-Url: https://git.uhu-banane.net/?a=commitdiff_plain;h=1a2fb63e26ae9b69e1d77637298aec196b5cfa0f;p=pixelpark%2Fpuppetmaster-webhooks.git Splitting method ModuleMetadata.from_json_data() --- diff --git a/lib/webhooks/module_meta_info.py b/lib/webhooks/module_meta_info.py index 654f452..d63aadd 100644 --- a/lib/webhooks/module_meta_info.py +++ b/lib/webhooks/module_meta_info.py @@ -23,7 +23,7 @@ from fb_tools.obj import FbBaseObjectError, FbBaseObject from .xlate import XLATOR -__version__ = '0.5.4' +__version__ = '0.5.5' LOG = logging.getLogger(__name__) @@ -346,42 +346,46 @@ class ModuleMetadata(FbBaseObject): raise MetadataInitError(msg) metadata = cls(appname=appname, verbose=verbose, base_dir=base_dir) + metadata._apply_json_data(json_data) - metadata.name = json_data['name'] - metadata.version = json_data['version'] + return metadata + + # ------------------------------------------------------------------------- + def _apply_json_data(self, json_data): + + self.name = json_data['name'] + self.version = json_data['version'] if 'author' in json_data: - metadata.author = json_data['author'] + self.author = json_data['author'] else: - metadata.author = metadata.author - metadata.license = json_data['license'] - metadata.summary = json_data['summary'] - metadata.source = json_data['source'] + self.author = self.author + self.license = json_data['license'] + self.summary = json_data['summary'] + self.source = json_data['source'] for item in json_data['dependencies']: dep = ModuleDependency.from_data(item) - metadata.dependencies.append(dep) + self.dependencies.append(dep) if 'requirements' in json_data: for item in json_data['requirements']: req = ModuleDependency.from_data(item) - metadata.requirements.append(req) + self.requirements.append(req) if 'project_page' in json_data: - metadata.project_page = json_data['project_page'] + self.project_page = json_data['project_page'] if 'issues_url' in json_data: - metadata.issues_url = json_data['issues_url'] + self.issues_url = json_data['issues_url'] if 'operatingsystem_support' in json_data: for item in json_data['operatingsystem_support']: supp = ModuleOsSupport.from_data(item) - metadata.operatingsystem_support.append(supp) + self.operatingsystem_support.append(supp) if 'tags' in json_data: for tag in json_data['tags']: tg = str(tag).strip() if tg: - metadata.tags.append(tg) + self.tags.append(tg) - metadata.initialized = True - if verbose > 3: - LOG.debug("ModuleMetadata:\n{}".format(pp(metadata.as_dict()))) - - return metadata + self.initialized = True + if self.verbose > 3: + LOG.debug("ModuleMetadata:\n{}".format(pp(self.as_dict()))) # ------------------------------------------------------------------------- def __copy__(self):