From c9e081a78de1b44c5bdab28e806475540ff324e1 Mon Sep 17 00:00:00 2001 From: Jon Hagg Date: Wed, 21 Apr 2021 14:42:23 -0700 Subject: [PATCH 1/2] feat: change makedir implementation to be os agnostic --- powersimdata/data_access/data_access.py | 22 ++++++++++++++++++++-- powersimdata/scenario/execute.py | 9 ++------- 2 files changed, 22 insertions(+), 9 deletions(-) diff --git a/powersimdata/data_access/data_access.py b/powersimdata/data_access/data_access.py index 6f3807ee5..ad8093bdb 100644 --- a/powersimdata/data_access/data_access.py +++ b/powersimdata/data_access/data_access.py @@ -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. @@ -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. @@ -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() diff --git a/powersimdata/scenario/execute.py b/powersimdata/scenario/execute.py index 5036fb729..e054aabea 100644 --- a/powersimdata/scenario/execute.py +++ b/powersimdata/scenario/execute.py @@ -342,14 +342,9 @@ def __init__(self, data_access, scenario_info, grid, ct): ) 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) def prepare_mpc_file(self): """Creates MATPOWER case file.""" From 6c6a2b52793ac9144146d27d8fda5c0effe63d16 Mon Sep 17 00:00:00 2001 From: Jon Hagg Date: Wed, 21 Apr 2021 15:17:10 -0700 Subject: [PATCH 2/2] chore: remove unused attribute --- powersimdata/scenario/execute.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/powersimdata/scenario/execute.py b/powersimdata/scenario/execute.py index e054aabea..fffc1c381 100644 --- a/powersimdata/scenario/execute.py +++ b/powersimdata/scenario/execute.py @@ -334,9 +334,6 @@ 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 )