-
Notifications
You must be signed in to change notification settings - Fork 87
Enhance ability to use template variables #650
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
5392d36
10b6e3a
666cdea
24b49bf
b275988
fc59ea0
aa23ce3
45c6ffb
b003c52
a966685
754e2da
d0eb0db
7424e13
52a1c9e
4beda25
6845ce3
880bebe
2ff052d
a525cb5
0c2e5c4
5365a1e
11fbbd4
06a3d2a
dc69b5f
0a6db56
40588ef
6d1ad63
f37de7e
03d0767
bc2a78f
3d5c2c3
dd5f764
efdd5e1
e885589
3f65bd2
fd288dd
d1bd7b5
7f11b80
f37bfb6
a41a5a3
ebe408e
6cd1786
d6847dc
7481e6d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| config.deactivate_tasks.sh |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,71 @@ | ||
| # | ||
| #----------------------------------------------------------------------- | ||
| # | ||
| # This file defines a function that returns the contents of a bash script/ | ||
| # function with all empty lines, comment lines, and leading and trailing | ||
| # whitespace removed. Arguments are as follows: | ||
| # | ||
| # fp: | ||
| # The relative or full path to the file containing the bash script or | ||
| # function. | ||
| # | ||
| # output_varname_contents: | ||
| # Name of the output variable that will contain the (processed) contents | ||
| # of the file. This is the output of the function. | ||
| # | ||
| #----------------------------------------------------------------------- | ||
| # | ||
| function get_bash_file_contents() { | ||
|
|
||
| { save_shell_opts; set -u +x; } > /dev/null 2>&1 | ||
|
|
||
| local valid_args=( \ | ||
| "fp" \ | ||
| "output_varname_contents" \ | ||
| ) | ||
| process_args valid_args "$@" | ||
| print_input_args "valid_args" | ||
| # | ||
| # Verify that the required arguments to this function have been specified. | ||
| # If not, print out an error message and exit. | ||
| # | ||
| if [ -z "$fp" ]; then | ||
| print_err_msg_exit "\ | ||
| The argument \"fp\" specifying the relative or full path to the file to | ||
| read was not specified in the call to this function: | ||
| fp = \"$fp\"" | ||
| fi | ||
|
|
||
| local contents \ | ||
| crnt_line | ||
| # | ||
| # Read in all lines in the file. In doing so: | ||
| # | ||
| # 1) Concatenate any line ending with the bash line continuation character | ||
| # (a backslash) with the following line. | ||
| # 2) Remove any leading and trailing whitespace. | ||
| # | ||
| # Note that these two actions are automatically performed by the "read" | ||
| # utility in the while-loop below. | ||
| # | ||
| contents="" | ||
| while read crnt_line; do | ||
| contents="${contents}${crnt_line} | ||
| " | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This line seems like it needs a line continuation, maybe?
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is actually correct; I tested it. It is just adding a newline after appending
This is a bit slower since it calls |
||
| done < "$fp" | ||
| # | ||
| # Strip out any comment and empty lines from contents. | ||
| # | ||
| contents=$( printf "${contents}" | \ | ||
| $SED -r -e "/^#.*/d" `# Remove comment lines.` \ | ||
| -e "/^$/d" `# Remove empty lines.` \ | ||
| ) | ||
| # | ||
| # Set output variables. | ||
| # | ||
| printf -v ${output_varname_contents} "${contents}" | ||
|
|
||
| { restore_shell_opts; } > /dev/null 2>&1 | ||
|
|
||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,110 @@ | ||
| # | ||
| #----------------------------------------------------------------------- | ||
| # | ||
| # This file defines a function that checks that all experiment variables | ||
| # set in the user-specified experiment configuration file are defined (by | ||
| # being assigned default values) in the default experiment configuration | ||
| # file. If a variable is found in the former that is not defined in the | ||
| # latter, this function exits with an error message. | ||
| # | ||
| # This check is performed in order to prevent the user from defining | ||
| # arbitrary variables in the user-specified configuration file; the | ||
| # latter should be used to specify only varaibles that have already been | ||
| # defined in the default configuration file. | ||
| # | ||
| # Arguments are as follows: | ||
| # | ||
| # default_config_fp: | ||
| # The relative or full path to the default experiment configuration file. | ||
| # | ||
| # config_fp: | ||
| # The relative or full path to the user-specified experiment configuration | ||
| # file. | ||
| # | ||
| #----------------------------------------------------------------------- | ||
| # | ||
| function check_expt_config_vars() { | ||
|
|
||
| . ${scrfunc_dir}/source_util_funcs.sh | ||
|
|
||
| { save_shell_opts; set -u +x; } > /dev/null 2>&1 | ||
|
|
||
| local valid_args=( \ | ||
| "default_config_fp" \ | ||
| "config_fp" \ | ||
| ) | ||
| process_args valid_args "$@" | ||
| print_input_args "valid_args" | ||
|
|
||
| local var_list_default \ | ||
| var_list_user \ | ||
| crnt_line \ | ||
| var_name \ | ||
| regex_search | ||
| # | ||
| # Get the list of variable definitions, first from the default experiment | ||
| # configuration file and then from the user-specified experiment | ||
| # configuration file. | ||
| # | ||
| get_bash_file_contents fp="${default_config_fp}" \ | ||
| output_varname_contents="var_list_default" | ||
|
|
||
| get_bash_file_contents fp="${config_fp}" \ | ||
| output_varname_contents="var_list_user" | ||
| # | ||
| # Loop through each line/variable in var_list_user. For each line, | ||
| # extract the the name of the variable that is being set (say VAR) and | ||
| # check that this variable is set somewhere in the default configuration | ||
| # file by verifying that a line that starts with "VAR=" exists in | ||
| # var_list_default. | ||
| # | ||
| while read crnt_line; do | ||
| # | ||
| # Note that a variable name will be found only if the equal sign immediately | ||
| # follows the variable name. | ||
| # | ||
| var_name=$( printf "%s" "${crnt_line}" | $SED -n -r -e "s/^([^ =\"]*)=.*/\1/p") | ||
|
|
||
| if [ -z "${var_name}" ]; then | ||
|
|
||
| print_info_msg " | ||
| The current line (crnt_line) of the user-specified experiment configuration | ||
| file (config_fp) does not contain a variable name (i.e. var_name is empty): | ||
| config_fp = \"${config_fp}\" | ||
| crnt_line = \"${crnt_line}\" | ||
| var_name = \"${var_name}\" | ||
| Skipping to next line." | ||
|
|
||
| else | ||
| # | ||
| # Use grep to search for the variable name (followed by an equal sign, | ||
| # all at the beginning of a line) in the list of variables in the default | ||
| # configuration file. | ||
| # | ||
| # Note that we use a herestring to input into grep the list of variables | ||
| # in the default configuration file. grep will return with a zero status | ||
| # if the specified string (regex_search) is not found in the default | ||
| # variables list and a nonzero status otherwise. Note also that we | ||
| # redirect the output of grep to null because we are only interested in | ||
| # its exit status. | ||
| # | ||
| regex_search="^${var_name}=" | ||
| grep "${regex_search}" <<< "${var_list_default}" > /dev/null 2>&1 || \ | ||
| print_err_msg_exit "\ | ||
| The variable (var_name) defined on the current line (crnt_line) of the | ||
| user-specified experiment configuration file (config_fp) does not appear | ||
| in the default experiment configuration file (default_config_fp): | ||
| config_fp = \"${config_fp}\" | ||
| default_config_fp = \"${default_config_fp}\" | ||
| crnt_line = \"${crnt_line}\" | ||
| var_name = \"${var_name}\" | ||
| Please assign a default value to this variable in the default configuration | ||
| file and rerun." | ||
|
|
||
| fi | ||
|
|
||
| done <<< "${var_list_user}" | ||
|
|
||
| { restore_shell_opts; } > /dev/null 2>&1 | ||
|
|
||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please consider using appropriate indentation level for all comments in the code. It's impossible to follow what the code is doing and the level of indentation when all comments start from the first column.
This request applies to all the new functions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, will do.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, done. Also did
check_expt_config_vars.sh. Feedback welcome!