From 1591b9c5e7b47914374a5b1128a1f064cdd3bef2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Kadl=C4=8D=C3=ADk?= Date: Fri, 17 Feb 2017 00:14:30 +0100 Subject: [PATCH] Create method for loading modulemd object from yaml --- module_build_service/utils.py | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/module_build_service/utils.py b/module_build_service/utils.py index a11a16ea..82504c1c 100644 --- a/module_build_service/utils.py +++ b/module_build_service/utils.py @@ -287,12 +287,7 @@ def _fetch_mmd(url, allow_local_url = False): "Failed to remove temporary directory {!r}: {}".format( td, str(e))) - mmd = modulemd.ModuleMetadata() - try: - mmd.loads(yaml) - except Exception as e: - log.error('Invalid modulemd: %s' % str(e)) - raise UnprocessableEntity('Invalid modulemd: %s' % str(e)) + mmd = load_mmd(yaml) # If undefined, set the name field to VCS repo name. if not mmd.name and scm: @@ -308,6 +303,17 @@ def _fetch_mmd(url, allow_local_url = False): return mmd, scm, yaml + +def load_mmd(yaml): + mmd = modulemd.ModuleMetadata() + try: + mmd.loads(yaml) + except Exception as e: + log.error('Invalid modulemd: %s' % str(e)) + raise UnprocessableEntity('Invalid modulemd: %s' % str(e)) + return mmd + + def _scm_get_latest(pkg): try: # If the modulemd specifies that the 'f25' branch is what