Skip to content
Snippets Groups Projects
Commit 7d1c7334 authored by Karl-Hermann Wieners's avatar Karl-Hermann Wieners
Browse files

Unified handling of remove keywords in job configuration, added remove keyword...

Unified handling of remove keywords in job configuration, added remove keyword for namelist variables
parent 30198d72
No related branches found
No related tags found
No related merge requests found
...@@ -116,18 +116,24 @@ def format_value(value, indent): ...@@ -116,18 +116,24 @@ def format_value(value, indent):
return (',\n' + ' '*indent).join(lines) return (',\n' + ' '*indent).join(lines)
return format_atom(value) return format_atom(value)
def cut_remove_list(section, key):
remove_list = []
if key in section:
if isinstance(section[key], basestring):
remove_list = [section[key]]
else:
remove_list = section[key]
del section[key]
return remove_list
def format_namelist(section): def format_namelist(section):
'''Format config section as a namelist''' '''Format config section as a namelist'''
# Settings # Settings
base_indent = 4 base_indent = 4
# Create list of removed namelist groups # Create list of removed namelist groups.
remove_list = [] # Support old keyword for backward compatibility
if 'remove' in section: remove_list = cut_remove_list(section, '.remove')
if isinstance(section['remove'], basestring): remove_list += cut_remove_list(section, 'remove')
remove_list = [section['remove']]
else:
remove_list = section['remove']
del section['remove']
black_list = map(lambda x: x.replace(r'\*', '.*').replace(r'\?', '.')+'$', black_list = map(lambda x: x.replace(r'\*', '.*').replace(r'\?', '.')+'$',
map(lambda x: re.escape(x.lower()), remove_list)) map(lambda x: re.escape(x.lower()), remove_list))
# Format namelist groups that were not removed # Format namelist groups that were not removed
...@@ -136,21 +142,24 @@ def format_namelist(section): ...@@ -136,21 +142,24 @@ def format_namelist(section):
if isinstance(contents, dict): if isinstance(contents, dict):
group = group.lower() group = group.lower()
if not any(map(lambda x: re.match(x, group), black_list)): if not any(map(lambda x: re.match(x, group), black_list)):
# Create list of removed keys
remove_keys = cut_remove_list(contents, '.remove')
group_name = re.sub(r' .*$', '', group) group_name = re.sub(r' .*$', '', group)
lines.write('&'+group_name+'\n') lines.write('&'+group_name+'\n')
for key, value in contents.iteritems(): for key, value in contents.iteritems():
key = key.lower() if key not in remove_keys:
indent = base_indent + len(key) + 3 key = key.lower()
for line in contents.comments.get(key, []): indent = base_indent + len(key) + 3
if line: for line in contents.comments.get(key, []):
lines.write(' '*base_indent+ if line:
re.sub(r'^#', '!', line)+'\n') lines.write(' '*base_indent+
line = contents.inline_comments[key] re.sub(r'^#', '!', line)+'\n')
if not line: line = contents.inline_comments[key]
line = '' if not line:
line = re.sub(r'^#', ' !', line) line = ''
lines.write(' '*base_indent+key+' = '+ line = re.sub(r'^#', ' !', line)
format_value(value, indent)+line+'\n') lines.write(' '*base_indent+key+' = '+
format_value(value, indent)+line+'\n')
lines.write('/\n') lines.write('/\n')
return lines.getvalue() return lines.getvalue()
...@@ -243,16 +252,11 @@ if work_dir != data_dir: ...@@ -243,16 +252,11 @@ if work_dir != data_dir:
# Cut queue specific settings # Cut queue specific settings
job_dict = {} job_dict = {}
remove_list = [] remove_list = cut_remove_list(config['jobs'], '.remove')
remove_list += cut_remove_list(config['jobs'], 'remove')
for key, value in config['jobs'].iteritems(): for key, value in config['jobs'].iteritems():
if not isinstance(value, dict): if not isinstance(value, dict):
if key == 'remove': job_dict[key] = value
if isinstance(value, basestring):
remove_list = [value]
else:
remove_list = value
else:
job_dict[key] = value
del config['jobs'][key] del config['jobs'][key]
# Save configuration to buffer # Save configuration to buffer
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment