Skip to content

Commit

Permalink
Fix nesting output directory issue
Browse files Browse the repository at this point in the history
  • Loading branch information
rhinoella committed Jun 14, 2024
1 parent 639068c commit 1e5a2a6
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 15 deletions.
14 changes: 7 additions & 7 deletions gudpy/core/iterators.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,14 +102,14 @@ def applyCoefficientToAttribute(self, sample, coefficient):
"""
pass

def organiseOutput(self, gudrunFile, exclude=[]):
def organiseOutput(self, gudrunFile, exclude=[]) -> None:
"""
This organises the output of the iteration.
"""
outputHandler = handlers.GudrunOutputHandler(
gudrunFile=gudrunFile,
)
return outputHandler.organiseOutput(exclude=exclude)
outputHandler.organiseOutput(exclude=exclude)


class Radius(Iterator):
Expand Down Expand Up @@ -183,8 +183,8 @@ class Thickness(Iterator):
"""

def __init__(self, nTotal):
super().__init__(nTotal)
self.name = "Thickness"
super().__init__(nTotal)
self.iterationMode = IterationModes.THICKNESS

def applyCoefficientToAttribute(self, sample, coefficient):
Expand Down Expand Up @@ -231,8 +231,8 @@ class TweakFactor(Iterator):
"""

def __init__(self, nTotal):
super().__init__(nTotal)
self.name = "TweakFactor"
super().__init__(nTotal)
self.iterationMode = IterationModes.TWEAK_FACTOR

def performIteration(self, gudrunFile) -> GudrunFile:
Expand Down Expand Up @@ -285,8 +285,8 @@ class Density(Iterator):
"""

def __init__(self, nTotal):
super().__init__(nTotal)
self.name = "Density"
super().__init__(nTotal)
self.iterationMode = IterationModes.DENSITY

def applyCoefficientToAttribute(self, sample, coefficient):
Expand Down Expand Up @@ -374,8 +374,8 @@ def __init__(self, nTotal):
Input GudrunFile that we will be using for iterating.
"""
nTotal *= 2
super().__init__(nTotal)
self.name = "Inelasticity Subtraction"
super().__init__(nTotal)
self.iterationMode = IterationModes.INELASTICITY
# Does a default iteration first (no changes)
self.iterationType = "QIteration"
Expand Down Expand Up @@ -654,9 +654,9 @@ def __init__(
ratio=1,
components=[],
):
self.name = "Composition"
super().__init__(nTotal)
self.requireDefault = False
self.name = "Composition"
self.originalGudrunFile = gudrunFile
self.mode = mode
self.nCurrent = 0
Expand Down
12 changes: 6 additions & 6 deletions gudpy/core/output_file_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,24 +96,25 @@ def __init__(
self.overwrite = overwrite
self.parentDir = self.outputDir

# Append head to path
self.outputDir = os.path.join(self.outputDir, f"{head}")

# List of run samples
self.samples = []
# Directory where Gudrun files are outputted (temp)
self.gudrunDir = self.procDir
self.gudrunFile = gudrunFile
self.gudrunFile.outputFolder = self.outputDir

# Make sure it is a temporary directory
assert (self.gudrunDir.startswith(tempfile.gettempdir()))
# Temporary output dir paths
self.tempOutDir = os.path.join(self.gudrunDir, "Gudrun")
if head:
# Append head to path
self.outputDir = os.path.join(
self.outputDir, f"{head}")
self.tempOutDir = os.path.join(
self.tempOutDir, f"{head}")

self.gudrunFile.outputFolder = self.outputDir

# Files that have been copied
self.copiedFiles = []

Expand All @@ -139,10 +140,9 @@ def organiseOutput(self, exclude: list[str] = []):
if self.overwrite and os.path.exists(self.outputDir):
with tempfile.TemporaryDirectory() as tmp:
shutil.move(self.parentDir, os.path.join(tmp, "prev"))
os.makedirs(self.parentDir)

# Move over folders to output directory
shutil.move(self.tempOutDir, utils.uniquify(self.outputDir))
shutil.move(self.tempOutDir, self.outputDir)

def _createNormDir(self, dest: str):
"""
Expand Down
7 changes: 7 additions & 0 deletions gudpy/gudpy_gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,13 @@ def __init__(self, args):
super(GudPy, self).__init__(args)
self.gudpy = GudPyController()
self.aboutToQuit.connect(self.gudpy.cleanup)

if (sys.argv[1]):
self.gudpy.gudpy.loadFromProject(sys.argv[1])
self.gudpy.mainWidget.updateWidgets(self.gudpy.gudrunFile)
self.gudpy.mainWidget.setWindowTitle(
f"GudPy - {self.gudpy.gudpy.io.projectName}[*]")

sys.exit(self.exec())

def onException(self, cls, exception, traceback):
Expand Down
10 changes: 8 additions & 2 deletions gudpy/gui/widgets/core/worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import core.exception as exc
from core.gudrun_file import GudrunFile
from core.purge_file import PurgeFile
from core.iterators import Iterator
from core.iterators import Iterator, InelasticitySubtraction
from core import iterators, config

SUFFIX = ".exe" if os.name == "nt" else ""
Expand Down Expand Up @@ -153,9 +153,15 @@ def __init__(
self.gudrunObjects.append(worker)

def _outputChanged(self, output):
idx = (f"{self.iterator.name} {self.iterator.iterationCount}"
idx = (f"{self.iterator.name} {self.iterator.nCurrent}"
if self.iterator.nCurrent != 0
or not self.iterator.requireDefault else "Default run")

if isinstance(self.iterator, InelasticitySubtraction):
idx = (
f"{self.iterator.iterationType} {self.iterator.iterationCount}"
)

currentOutput = self.output.get(idx, "")
self.output[idx] = currentOutput + output
self.outputChanged.emit(output)
Expand Down
1 change: 1 addition & 0 deletions gudpy/test/test_gudpy_workflows.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ def testIterateByComposition(self):
gudpy.gudrunFile = g

gudpy.runPurge()

iterator = iterators.Composition(
gudrunFile=g,
nTotal=10,
Expand Down

0 comments on commit 1e5a2a6

Please sign in to comment.