Skip to content
Snippets Groups Projects
Commit 6bcb2e13 authored by AxelCarayon's avatar AxelCarayon
Browse files

ajout des checksums

parent a7552066
Branches
No related tags found
No related merge requests found
...@@ -4,6 +4,7 @@ import subprocess ...@@ -4,6 +4,7 @@ import subprocess
import sys import sys
from git import repo from git import repo
import yaml import yaml
import hashlib
path = "./" path = "./"
...@@ -49,7 +50,7 @@ def searchForInputFolder() -> None: ...@@ -49,7 +50,7 @@ def searchForInputFolder() -> None:
global inputFolder global inputFolder
print("Searching for input folder...") print("Searching for input folder...")
if folderExists("inputs"): if folderExists("inputs"):
inputFolder = "inputs" inputFolder = "inputs/"
print(f"{path}{inputFolder} found !") print(f"{path}{inputFolder} found !")
else: else:
raise Exception(f"{path}/inputs folder does not exist") raise Exception(f"{path}/inputs folder does not exist")
...@@ -58,7 +59,7 @@ def searchForOutputFolder() -> None: ...@@ -58,7 +59,7 @@ def searchForOutputFolder() -> None:
global outputFolder global outputFolder
print("Searching for output folder...") print("Searching for output folder...")
if folderExists("outputs"): if folderExists("outputs"):
outputFolder = "outputs" outputFolder = "outputs/"
print(f"{path}{outputFolder} found !") print(f"{path}{outputFolder} found !")
else: else:
raise Exception(f"{path}/outputs folder does not exist") raise Exception(f"{path}/outputs folder does not exist")
...@@ -92,7 +93,6 @@ def scanInputFiles() -> None: ...@@ -92,7 +93,6 @@ def scanInputFiles() -> None:
inputFiles.append(file) inputFiles.append(file)
def scanOutputsGenerated() -> None: def scanOutputsGenerated() -> None:
print(outputFolder)
for file in os.listdir(outputFolder): for file in os.listdir(outputFolder):
outputFiles.append(file) outputFiles.append(file)
...@@ -103,7 +103,8 @@ def writeInYaml() -> None: ...@@ -103,7 +103,8 @@ def writeInYaml() -> None:
cur_yaml.update({"commands":commandsFile}) cur_yaml.update({"commands":commandsFile})
cur_yaml.update({"inputs":inputFiles}) cur_yaml.update({"inputs":inputFiles})
cur_yaml.update({"outputs":outputFiles}) cur_yaml.update({"outputs":outputFiles})
print(cur_yaml) checksums = {"checksums":genChecksums()}
cur_yaml.update(checksums)
with open('experimentResume.yaml', 'w') as yamlFile: with open('experimentResume.yaml', 'w') as yamlFile:
yaml.safe_dump(cur_yaml, yamlFile) yaml.safe_dump(cur_yaml, yamlFile)
...@@ -111,7 +112,6 @@ def branchExists(branchName) -> bool: ...@@ -111,7 +112,6 @@ def branchExists(branchName) -> bool:
return branchName in repository.references return branchName in repository.references
def pushBranch(version=1) -> None: def pushBranch(version=1) -> None:
print(experimentName)
while (branchExists(f"{experimentName}Experiment{version}")): while (branchExists(f"{experimentName}Experiment{version}")):
version += 1 version += 1
else: else:
...@@ -120,7 +120,19 @@ def pushBranch(version=1) -> None: ...@@ -120,7 +120,19 @@ def pushBranch(version=1) -> None:
repository.git.commit(m=f"{experimentName}Experiment{version}") repository.git.commit(m=f"{experimentName}Experiment{version}")
repository.git.push('--set-upstream', repository.remote().name, f"{experimentName}Experiment{version}") repository.git.push('--set-upstream', repository.remote().name, f"{experimentName}Experiment{version}")
repository.git.checkout(experimentName) repository.git.checkout(experimentName)
def genChecksum(file) -> str :
hash_md5 = hashlib.md5()
with open(file, "rb") as f:
for chunk in iter(lambda: f.read(4096), b""):
hash_md5.update(chunk)
return hash_md5.hexdigest()
def genChecksums() -> list[dict]:
checksums = []
for file in outputFiles:
checksums.append({file : genChecksum(outputFolder+file)})
return checksums
if (__name__ == "__main__"): if (__name__ == "__main__"):
if (len(sys.argv) <2): if (len(sys.argv) <2):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment