Skip to content

Commit

Permalink
Merge bc99a0e into 949810e
Browse files Browse the repository at this point in the history
  • Loading branch information
yakutovicha committed Sep 23, 2018
2 parents 949810e + bc99a0e commit 2be04c4
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 9 deletions.
7 changes: 2 additions & 5 deletions aiida/cmdline/templates/prepost.bash.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,14 @@

{{default_pre}}

#={{'='*50}}=#
#= {{'Post execution script'|center(48)}} =#
#={{'='*50}}=#

{{separator}}
{{default_post}}

#={{'='*50}}=#
{{('#= Lines starting with "#=" will be ignored! Pre and post execution scripts are executed on '
'the remote computer before and after execution of the code(s), respectively. AiiDA expects '
'valid bash code.')|wordwrap(50, wrapstring='\n#= ')}}
#
#=
#={{'='*50}}=#
#= {{'Summary of config so far'|center(48)}} =#
#={{'='*50}}=#
Expand Down
22 changes: 19 additions & 3 deletions aiida/cmdline/utils/multi_line_input.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"""
from __future__ import absolute_import
import click
from aiida.cmdline.utils import decorators, echo


def ensure_scripts(pre, post, summary):
Expand Down Expand Up @@ -31,12 +32,27 @@ def edit_pre_post(pre=None, post=None, summary=None):
template = env.get_template('prepost.bash.tpl')
summary = summary or {}
summary = {k: v for k, v in summary.items() if v}
content = template.render(default_pre=pre or '', default_post=post or '', summary=summary)

# Define a separator that will be splitting pre- and post- execution
# parts of the submission script
separator = "#====================================================#\n" \
"#= Post execution script =#\n" \
"#= I am acting as separator, do not modify me!!! =#\n" \
"#====================================================#\n"

content = template.render(default_pre=pre or '', separator=separator,
default_post=post or '', summary=summary)
mlinput = click.edit(content, extension='.bash')
if mlinput:
import re
stripped_input = re.sub(r'(^#.*$\n)+', '#', mlinput, flags=re.M).strip('#')
pre, post = [text.strip() for text in stripped_input.split('#')]

# Splitting the text in pre- and post- halfs
pre, post = mlinput.split(separator)

# Removing all the comments starting from '#=' in both pre- and post-
# parts
pre = re.sub(r'(^#=.*$\n)+', '', pre, flags=re.M).strip()
post = re.sub(r'(^#=.*$\n)+', '', post, flags=re.M).strip()
else:
pre, post = ('', '')
return pre, post
Expand Down
3 changes: 2 additions & 1 deletion aiida/cmdline/utils/test_multiline.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ def setUp(self):
## Sleep 1 is needed because on some filesystems (e.g. some pre 10.13 Mac) the
## filesystem returns the time with a precision of 1 second, and
## click uses the timestamp to decide if the file was re-saved or not.
editor_cmd = 'sleep 1 ; vim -c "%s/$/Test/g" -cwq' # appends Test to every line
editor_cmd = 'sleep 1 ; vim -c "g!/#/s/$/Test" -cwq' # appends Test to
# every line not containing '#' character
os.environ['EDITOR'] = editor_cmd
os.environ['VISUAL'] = editor_cmd
self.runner = CliRunner()
Expand Down

0 comments on commit 2be04c4

Please sign in to comment.