Have default NSV for modules submitted by yaml file

This commit is contained in:
Jakub Kadlčík
2017-04-18 08:23:38 +02:00
parent dd72504395
commit b0ae5f98ef
2 changed files with 16 additions and 3 deletions

View File

@@ -661,8 +661,21 @@ def record_component_builds(mmd, module, initial_batch = 1,
return batch
def submit_module_build_from_yaml(username, yaml, optional_params=None):
def submit_module_build_from_yaml(username, handle, optional_params=None):
yaml = handle.read()
mmd = load_mmd(yaml)
# Mimic the way how default values are generated for modules that are stored in SCM
# We can take filename as the module name as opposed to repo name,
# and also we can take numeric representation of current datetime
# as opposed to datetime of the last commit
dt = datetime.utcfromtimestamp(int(time.time()))
def_name = str(handle.filename.split(".")[0])
def_version = int(dt.strftime("%Y%m%d%H%M%S"))
mmd.name = mmd.name or def_name
mmd.stream = mmd.stream or "master"
mmd.version = mmd.version or def_version
return submit_module_build(username, None, mmd, None, yaml, optional_params)

View File

@@ -235,8 +235,8 @@ class YAMLFileHandler(BaseHandler):
self.validate_optional_params()
def post(self):
r = request.files["yaml"]
return submit_module_build_from_yaml(self.username, r.read(), optional_params=self.optional_params)
handle = request.files["yaml"]
return submit_module_build_from_yaml(self.username, handle, optional_params=self.optional_params)
def register_api_v1():