Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 20 additions & 2 deletions powersimdata/data_access/data_access.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,7 @@ def makedir(self, relative_path):

:param str relative_path: the path, without filename, relative to root
"""
full_path = posixpath.join(self.root, relative_path)
return self.execute_command(f"mkdir -p {full_path}")
raise NotImplementedError

def execute_command(self, command):
"""Execute a command locally at the data access.
Expand Down Expand Up @@ -180,6 +179,14 @@ def move_to(self, file_name, to_dir, change_name_to=None):
self.copy(src, dest)
self.remove(src)

def makedir(self, relative_path):
"""Create paths relative to the instance root

:param str relative_path: the path, without filename, relative to root
"""
target = os.path.join(self.root, relative_path)
os.makedirs(target, exist_ok=True)

def execute_command(self, command):
"""Execute a command locally at the data access.

Expand Down Expand Up @@ -395,6 +402,17 @@ def push(self, file_name, checksum, change_name_to=None):
print(e)
raise IOError("Failed to push file - most likely a conflict was detected.")

def makedir(self, relative_path):
"""Create paths relative to the instance root

:param str relative_path: the path, without filename, relative to root
:raises IOError: if command generated stderr
"""
full_path = posixpath.join(self.root, relative_path)
_, _, stderr = self.execute_command(f"mkdir -p {full_path}")
if len(stderr.readlines()) != 0:
raise IOError("Failed to create %s on server" % full_path)

def close(self):
"""Close the connection that was opened when the object was created."""
self.ssh.close()
Expand Down
12 changes: 2 additions & 10 deletions powersimdata/scenario/execute.py
Original file line number Diff line number Diff line change
Expand Up @@ -334,22 +334,14 @@ def __init__(self, data_access, scenario_info, grid, ct):
self.server_config = server_setup.PathConfig(server_setup.DATA_ROOT_DIR)
self.scenario_folder = "scenario_%s" % scenario_info["id"]

self.TMP_DIR = posixpath.join(
self.server_config.execute_dir(), self.scenario_folder
)
self.REL_TMP_DIR = posixpath.join(
server_setup.EXECUTE_DIR, self.scenario_folder
)

def create_folder(self):
"""Creates folder on server that will enclose simulation inputs.

:raises IOError: if folder cannot be created.
"""
"""Creates folder on server that will enclose simulation inputs."""
print("--> Creating temporary folder on server for simulation inputs")
_, _, stderr = self._data_access.makedir(self.TMP_DIR)
if len(stderr.readlines()) != 0:
raise IOError("Failed to create %s on server" % self.TMP_DIR)
self._data_access.makedir(self.REL_TMP_DIR)
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This previously worked since one path was a prefix of the other one. Just changed so it's consistent with the assumption in makedir that we are using a relative path.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we need to keep the TMP_DIR attribute defined in the constructor?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, it's not used anywhere now


def prepare_mpc_file(self):
"""Creates MATPOWER case file."""
Expand Down