From 8c2f2f58c2bb6cc3cc64b042c7c00a3c8ed19371 Mon Sep 17 00:00:00 2001 From: AxelCarayon <axel.carayon@gmail.com> Date: Tue, 1 Feb 2022 15:26:37 +0100 Subject: [PATCH] =?UTF-8?q?modification=20de=20la=20gestion=20de=20l'ex?= =?UTF-8?q?=C3=A9cution=20et=20suivi=20des=20changements=20pour=20les=20pa?= =?UTF-8?q?ram=C3=A8tres,=20inputs=20et=20outputs?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- loadExperiment.py | 3 ++- registerExperiment.py | 41 ++++++++++++++++++++++------------------- 2 files changed, 24 insertions(+), 20 deletions(-) diff --git a/loadExperiment.py b/loadExperiment.py index 4d4dea1..3d753fa 100644 --- a/loadExperiment.py +++ b/loadExperiment.py @@ -93,4 +93,5 @@ def run(repository, branch) -> None : print("The exepriment was reproduced with succes but some output files are differents.") else : print("The exepriment was reproduced with succes !") - \ No newline at end of file + +#TODO : laisser à l'utilisateur le temps de reproduire l'experience \ No newline at end of file diff --git a/registerExperiment.py b/registerExperiment.py index 2c1d72c..df348cf 100644 --- a/registerExperiment.py +++ b/registerExperiment.py @@ -3,7 +3,6 @@ import git import subprocess import yaml import hashlib -import collections import warnings EXPERIMENT_RESUME = "experimentResume.yaml" @@ -117,18 +116,6 @@ def askForCommandsFile() -> None: if not fileExists(commandsFile): raise Exception(f"{commandsFile} file does not exist") -def captureExperiment() -> None : - print("Capturing commands in terminal, when the experiment is done, type \"done\"") - inputs = [] - userInput = input() - while (userInput != "done"): - inputs.append(userInput) - process = subprocess.run(userInput, shell=True) - process.check_returncode() - userInput = input() - print(f"Done recording the experiment, writing commands in a {commandsFile} file") - registeringExperimentInputs(inputs) - def registeringExperimentInputs(inputs) -> None: with open(commandsFile, "w") as file: for input in inputs: @@ -160,10 +147,23 @@ def scanParameters() -> None: paramsFiles.append(f"{paramsFolder}{file}") def checkGeneratedFiles() -> None : - changesNotAdded = [ item.a_path for item in repository.index.diff(None) ] - untrackedFiles = repository.untracked_files - if collections.Counter(outputFiles + inputFiles) != collections.Counter(untrackedFiles + changesNotAdded): - raise Exception("There were files generated or modified outside the input and output folders") + editedFiles = [ item.a_path for item in repository.index.diff(None) ] + repository.untracked_files + outOfPlaceFiles = [] + logFile = open("outOfPlaceFiles.log","w") + for file in editedFiles: + if (outputFolder is not None and file.startswith(outputFolder)) and \ + (inputFolder is not None and file.startswith(inputFolder)) and \ + (paramsFolder is not None and file.startswith(paramsFolder)): + outOfPlaceFiles.append(file) + logFile.write(f"{file}\n") + + logFile.close() + if len(outOfPlaceFiles) == 0: + os.remove("outOfPlaceFiles.log") + else : + raise Exception("""Some files modified or created were not registered as input, output or parameter file. + Thoses files are logged in the file outOfPlaceFiles.log""") + def writeInYaml() -> None: with open(EXPERIMENT_RESUME, "r") as yamlFile: @@ -212,6 +212,7 @@ def genChecksums() -> list[dict]: checksums.append({file : genChecksum(file)}) return checksums + def run(folder) -> None : init(folder) repository.active_branch.checkout() @@ -223,7 +224,9 @@ def run(folder) -> None : askForCommandsFile() runExperiment() else: - captureExperiment() + done = "" + while(done != "done"): + done = input("Run your experiment and then type 'done' when you are done : ") if inputFolder != None : scanInputFiles() if outputFolder != None : @@ -232,4 +235,4 @@ def run(folder) -> None : scanParameters() checkGeneratedFiles() writeInYaml() - pushBranch() \ No newline at end of file + pushBranch() -- GitLab