Skip to content
This repository was archived by the owner on Oct 31, 2019. It is now read-only.
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 25 additions & 15 deletions src/puliclient/jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,7 @@ def __init__(self, taskGroup):
class TaskDecomposer(object):
"""
| Base class for Decomposer hierarchy.

| Implements a minimalist "addCommand" method.
"""

Expand All @@ -347,6 +348,7 @@ class DefaultTaskDecomposer(TaskDecomposer):
# DEFAULT FIELDS USED TO DECOMPOSE A TASK
START_LABEL = "start"
END_LABEL = "end"
STEP_LABEL = "step"
PACKETSIZE_LABEL = "packetSize"
FRAMESLIST_LABEL = "framesList"

Expand All @@ -368,10 +370,11 @@ def __init__(self, task):

start = task.arguments.get(self.START_LABEL, 1)
end = task.arguments.get(self.END_LABEL, 1)
step = task.arguments.get(self.STEP_LABEL, 1)
packetSize = task.arguments.get(self.PACKETSIZE_LABEL, 1)
framesList = task.arguments.get(self.FRAMESLIST_LABEL, "")

self.decompose(start=start, end=end, packetSize=packetSize, callback=self, framesList=framesList)
self.decompose(start=start, end=end, step=step, packetSize=packetSize, callback=self, framesList=framesList)

else:
# If arguments given but no standard behaviour, simply transmit task arguments to single command
Expand All @@ -393,14 +396,17 @@ def addCommand(self, packetStart, packetEnd):
cmdName = "%s_%s_%s" % (self.task.name, str(packetStart), str(packetEnd))
self.task.addCommand(cmdName, cmdArgs)

def decompose(self, start, end, packetSize, callback, framesList=""):
def decompose(self, start, end, step, packetSize, callback, framesList=""):
''' Method extracted from PuliActionHelper. Default behaviour for decompozing a task.

:param start: Integer representing the first frame
:param end: Integer representing the last frame
:param step: Integer representing the steps
:param packetSize: The number of frames to process in each command
:param callback: A specific callback given to replace default's "addCommand" if necessary
:param framesList: A string representing a list of frames

.. note:: packetSize has priority on step
'''
packetSize = int(packetSize)
if len(framesList) != 0:
Expand Down Expand Up @@ -430,20 +436,24 @@ def decompose(self, start, end, packetSize, callback, framesList=""):
start = int(start)
end = int(end)

length = end - start + 1
fullPacketCount, lastPacketCount = divmod(length, packetSize)

if length < packetSize:
callback.addCommand(start, end)
else:
for i in range(fullPacketCount):
packetStart = start + i * packetSize
packetEnd = packetStart + packetSize - 1
callback.addCommand(packetStart, packetEnd)
if lastPacketCount:
packetStart = start + (i + 1) * packetSize
callback.addCommand(packetStart, end)
if packetSize > 1:
length = end - start + 1
fullPacketCount, lastPacketCount = divmod(length, packetSize)

if length < packetSize:
callback.addCommand(start, end)
else:
for i in range(fullPacketCount):
packetStart = start + i * packetSize
packetEnd = packetStart + packetSize - 1
callback.addCommand(packetStart, packetEnd)
if lastPacketCount:
packetStart = start + (i + 1) * packetSize
callback.addCommand(packetStart, end)
elif step > 1:
frames = range(start, end, step)
for frame in frames:
callback.addCommand(frame, frame)

def _load(name, motherClass):
try:
Expand Down