diff --git a/Dockerfile b/Dockerfile index a37ff7024..04b006451 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,7 +1,6 @@ FROM python:3.8.3 RUN apt-get update -RUN apt-get install gawk RUN ln -s /mnt/bes/pcm $HOME/ScenarioData COPY powersimdata/utility/templates /mnt/bes/pcm/ diff --git a/powersimdata/data_access/data_access.py b/powersimdata/data_access/data_access.py index a024dfec8..96e5d6e0a 100644 --- a/powersimdata/data_access/data_access.py +++ b/powersimdata/data_access/data_access.py @@ -144,14 +144,17 @@ def remove(self, pattern, confirm=True): :param str pattern: glob specifying files to remove :param bool confirm: prompt before executing command + :return: (*bool*) -- True if the operation is completed """ if confirm: confirmed = input(f"Delete '{pattern}'? [y/n] (default is 'n')") if confirmed.lower() != "y": print("Operation cancelled.") - return + return False self.fs.glob(pattern).remove() + self.local_fs.glob(pattern).remove() print("--> Done!") + return True def _check_file_exists(self, path, should_exist=True): """Check that file exists (or not) at the given path diff --git a/powersimdata/scenario/analyze.py b/powersimdata/scenario/analyze.py index eb6356b85..c2f51b82b 100644 --- a/powersimdata/scenario/analyze.py +++ b/powersimdata/scenario/analyze.py @@ -18,7 +18,7 @@ class Analyze(Ready): """ name = "analyze" - allowed = [] + allowed = ["delete"] exported_methods = { "get_averaged_cong", "get_congl", @@ -53,7 +53,7 @@ def refresh(self, scenario): def _set_allowed_state(self): """Sets allowed state.""" if self._scenario_status == "extracted": - self.allowed = ["delete", "move"] + self.allowed.append("move") def _set_ct_and_grid(self): """Sets change table and grid.""" diff --git a/powersimdata/scenario/delete.py b/powersimdata/scenario/delete.py index 7df554cd8..7d7e3c58c 100644 --- a/powersimdata/scenario/delete.py +++ b/powersimdata/scenario/delete.py @@ -1,4 +1,3 @@ -from powersimdata.data_access.data_access import LocalDataAccess from powersimdata.scenario.ready import Ready from powersimdata.utility import server_setup @@ -15,10 +14,7 @@ def delete_scenario(self, confirm=True): :param bool confirm: prompt before each batch """ - # Delete entry in scenario list scenario_id = self._scenario_info["id"] - self._scenario_list_manager.delete_entry(scenario_id) - self._execute_list_manager.delete_entry(scenario_id) print("--> Deleting scenario input data") target = self._data_access.join(*server_setup.INPUT_DIR, f"{scenario_id}_*") @@ -33,10 +29,9 @@ def delete_scenario(self, confirm=True): tmp_dir = self._data_access.tmp_folder(scenario_id) self._data_access.remove(f"{tmp_dir}/**", confirm=confirm) - print("--> Deleting input and output data on local machine") - local_data_access = LocalDataAccess() - target = local_data_access.join("data", "**", f"{scenario_id}_*") - local_data_access.remove(target, confirm=confirm) + print("--> Deleting entries in scenario and execute list") + self._scenario_list_manager.delete_entry(scenario_id) + self._execute_list_manager.delete_entry(scenario_id) # Delete attributes self._clean() diff --git a/powersimdata/scenario/execute.py b/powersimdata/scenario/execute.py index 374010e90..af9cc001c 100644 --- a/powersimdata/scenario/execute.py +++ b/powersimdata/scenario/execute.py @@ -17,7 +17,7 @@ class Execute(Ready): """ name = "execute" - allowed = [] + allowed = ["delete"] exported_methods = { "check_progress", "extract_simulation_output", diff --git a/powersimdata/scenario/tests/test_scenario.py b/powersimdata/scenario/tests/test_scenario.py index 309a26e42..f30d45770 100644 --- a/powersimdata/scenario/tests/test_scenario.py +++ b/powersimdata/scenario/tests/test_scenario.py @@ -1,6 +1,7 @@ import pytest from powersimdata.data_access.context import Context +from powersimdata.scenario.delete import Delete from powersimdata.scenario.scenario import Scenario from powersimdata.tests.mock_context import MockContext @@ -45,9 +46,32 @@ def test_scenario_workflow(monkeypatch): s.get_grid() s.get_ct() + rfs = s.data_access.fs + lfs = s.data_access.local_fs + tmp_dir = s.data_access.tmp_folder(1) + s.print_scenario_info() s.create_scenario() + scenario_list = s.get_scenario_table() + assert 1 == scenario_list.shape[0] + + for fs in (lfs, rfs): + assert fs.exists("data/input/1_ct.pkl") + # hack to use truncated profiles so the test runs quickly s.info["grid_model"] = "test_usa_tamu" s.prepare_simulation_input() + + tmp_files = rfs.listdir(tmp_dir) + assert len(tmp_files) > 0 + + s.change(Delete) + s.delete_scenario(confirm=False) + + for fs in (rfs, lfs): + assert not fs.exists(tmp_dir) + assert len(fs.listdir("data/input")) == 0 + + scenario_list = Scenario().get_scenario_table() + assert 0 == scenario_list.shape[0]