modules.yaml : added hash_length as a new keyword

config :
- added `hash_length` under the modules section

EnvModules :
- take into consideration hash_length when constructing `file_name`
- added logic to warn and skip module file writing in case of file name clash
This commit is contained in:
alalazo 2016-06-30 12:56:47 +02:00
parent b71d430af6
commit 1b7eedbb7d
2 changed files with 19 additions and 2 deletions

View file

@ -328,6 +328,11 @@
'anyOf': [
{
'properties': {
'hash_length': {
'type': 'integer',
'minimum': 0,
'default': 7
},
'whitelist': {'$ref': '#/definitions/array_of_strings'},
'blacklist': {'$ref': '#/definitions/array_of_strings'},
'naming_scheme': {

View file

@ -188,6 +188,7 @@ def parse_config_options(module_generator):
#####
# Automatic loading loads
module_file_actions['hash_length'] = module_configuration.get('hash_length', 7)
module_file_actions['autoload'] = dependencies(
module_generator.spec, module_file_actions.get('autoload', 'none'))
# Prerequisites
@ -295,7 +296,9 @@ def use_name(self):
if constraint in self.spec:
suffixes.append(suffix)
# Always append the hash to make the module file unique
suffixes.append(self.spec.dag_hash())
hash_length = configuration.pop('hash_length', 7)
if hash_length != 0:
suffixes.append(self.spec.dag_hash(length=hash_length))
name = '-'.join(suffixes)
return name
@ -338,7 +341,7 @@ def blacklisted(self):
return False
def write(self):
def write(self, overwrite=False):
"""
Writes out a module file for this object.
@ -399,6 +402,15 @@ def write(self):
for line in self.module_specific_content(module_configuration):
module_file_content += line
# Print a warning in case I am accidentally overwriting
# a module file that is already there (name clash)
if not overwrite and os.path.exists(self.file_name):
message = 'Module file already exists : skipping creation\n'
message += 'file : {0.file_name}\n'
message += 'spec : {0.spec}'
tty.warn(message.format(self))
return
# Dump to file
with open(self.file_name, 'w') as f:
f.write(module_file_content)