Skip to content

Commit

Permalink
Change flock command argument (#358)
Browse files Browse the repository at this point in the history
* refactor: use flock -x flag instead of -e; improve error handling in _execute_and_check_err function

* docs: update output doc string for _execute_and_check_err function
  • Loading branch information
dmuldrew authored Dec 18, 2020
1 parent f4a9f5b commit 4ea408c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
13 changes: 10 additions & 3 deletions powersimdata/data_access/csv_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,16 @@ def _execute_and_check_err(self, command, err_message):
:param str command: command to execute over ssh.
:param str err_message: error message to be raised.
:raises IOError: if command is not successfully executed.
:return: (*str*) -- standard output stream.
:return: (*list*) -- list of command output.
"""
stdin, stdout, stderr = self.data_access.execute_command(command)
if len(stderr.readlines()) != 0:
command_output = stdout.readlines()
command_error = stderr.readlines()
if len(command_error) != 0:
command_error = [
i.replace("\t", " ").replace("\n", "") for i in command_error
]
for ce in command_error:
print(ce)
raise IOError(err_message)
return stdout
return command_output
6 changes: 3 additions & 3 deletions powersimdata/data_access/scenario_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ def generate_scenario_id(self):
:return: (*str*) -- new scenario id.
"""
print("--> Generating scenario id")
command = "(flock -e 200; \
command = "(flock -x 200; \
id=$(awk -F',' 'END{print $1+1}' %s); \
echo $id, >> %s; \
echo $id) 200>%s" % (
Expand All @@ -108,8 +108,8 @@ def generate_scenario_id(self):
)

err_message = "Failed to generate id for new scenario"
stdout = self._execute_and_check_err(command, err_message)
scenario_id = stdout.readlines()[0].splitlines()[0]
command_output = self._execute_and_check_err(command, err_message)
scenario_id = command_output[0].splitlines()[0]
return scenario_id

def add_entry(self, scenario_info):
Expand Down

0 comments on commit 4ea408c

Please sign in to comment.