From 6f6775ab62dc15da3b81dc5093c9ed2167723618 Mon Sep 17 00:00:00 2001 From: Jason Marechal Date: Thu, 12 Oct 2023 10:23:47 +0200 Subject: [PATCH] Don't delete previous directory (useless) --- .../antares_xpansion/full_run_driver.py | 13 ++++----- .../problem_generator_driver.py | 27 ++++++++++--------- 2 files changed, 19 insertions(+), 21 deletions(-) diff --git a/src/python/antares_xpansion/full_run_driver.py b/src/python/antares_xpansion/full_run_driver.py index 27af0ff840..d10ef46bb0 100644 --- a/src/python/antares_xpansion/full_run_driver.py +++ b/src/python/antares_xpansion/full_run_driver.py @@ -1,13 +1,13 @@ - -from typing import List +import os import subprocess import sys +from pathlib import Path +from typing import List + from antares_xpansion.benders_driver import BendersDriver -from antares_xpansion.problem_generator_driver import ProblemGeneratorDriver from antares_xpansion.logger import step_logger +from antares_xpansion.problem_generator_driver import ProblemGeneratorDriver from antares_xpansion.study_output_cleaner import StudyOutputCleaner -import os -from pathlib import Path class FullRunDriver: @@ -29,9 +29,6 @@ def prepare_drivers(self, output_path: Path, """ problem generation step : getnames + lp_namer """ - # Pb Gen pre-step - self.problem_generation_driver.clear_old_log() - self.problem_generation_driver.is_relaxed = problem_generation_is_relaxed self.keep_mps = benders_keep_mps diff --git a/src/python/antares_xpansion/problem_generator_driver.py b/src/python/antares_xpansion/problem_generator_driver.py index 805425c6b6..09af5e0fd7 100644 --- a/src/python/antares_xpansion/problem_generator_driver.py +++ b/src/python/antares_xpansion/problem_generator_driver.py @@ -3,7 +3,6 @@ """ import os -import shutil import subprocess import sys from dataclasses import dataclass @@ -66,26 +65,30 @@ def launch(self, output_path: Path, is_relaxed: bool): """ problem generation step : getnames + lp_namer """ - self.clear_old_log() + self.logger.info("Problem Generation") self.output_path = output_path + self.create_lp_dir() + self.is_relaxed = is_relaxed self._lp_step() def set_output_path(self, output_path): - self._output_path = output_path - self.xpansion_output_dir = output_path.parent / \ - (output_path.stem + "-Xpansion") - self._lp_path = os.path.normpath( - os.path.join(self.xpansion_output_dir, 'lp')) + + if output_path.exists(): + self._output_path = output_path + self.xpansion_output_dir = output_path.parent / \ + (output_path.stem + "-Xpansion") + os.makedirs(self.xpansion_output_dir) + self._lp_path = os.path.normpath( + os.path.join(self.xpansion_output_dir, 'lp')) + else: + raise ProblemGeneratorDriver.OutputPathError( + f"{output_path} not found") def get_output_path(self): return self._output_path - def clear_old_log(self): - if (os.path.isfile(str(self.lp_namer_exe_path) + '.log')): - os.remove(str(self.lp_namer_exe_path) + '.log') - def _lp_step(self): """ copies area and interco files and launches the lp_namer @@ -101,8 +104,6 @@ def _lp_step(self): "ERROR: exited lpnamer with status %d" % returned_l.returncode) def create_lp_dir(self): - if os.path.isdir(self._lp_path): - shutil.rmtree(self._lp_path) os.makedirs(self._lp_path) def lp_namer_options(self):