Skip to content

Commit

Permalink
Add enums to appropriate wrappers. (#392)
Browse files Browse the repository at this point in the history
* Add enums to appropriate wrappers. Fixes Issue #389

* adding enum unit tests
  • Loading branch information
Greg Denton committed Aug 5, 2019
1 parent b15d58d commit 75b080b
Show file tree
Hide file tree
Showing 15 changed files with 272 additions and 3 deletions.
6 changes: 4 additions & 2 deletions pycue/opencue/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@
from .wrappers.allocation import Allocation
from .wrappers.comment import Comment
from .wrappers.depend import Depend
from .wrappers.filter import Action
from .wrappers.filter import Filter
from .wrappers.filter import Matcher
from .wrappers.frame import Frame
from .wrappers.group import Group
from .wrappers.host import Host, NestedHost
Expand All @@ -62,8 +64,8 @@
filter_pb2, host_pb2, job_pb2, renderPartition_pb2, report_pb2, service_pb2, show_pb2,
subscription_pb2, task_pb2]

__wrappers = [Allocation, Comment, Depend, Filter, Frame, Group, Host, Job, Layer, NestedHost, Proc,
Show, Subscription, Task]
__wrappers = [Action, Allocation, Comment, Depend, Filter, Frame, Group, Host, Job, Layer, Matcher,
NestedHost, Proc, Show, Subscription, Task]


#
Expand Down
21 changes: 21 additions & 0 deletions pycue/opencue/wrappers/depend.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,33 @@
"""


import enum

from opencue.compiled_proto import depend_pb2
from opencue.cuebot import Cuebot


class Depend(object):

class DependType(enum.IntEnum):
JOB_ON_JOB = depend_pb2.JOB_ON_JOB
JOB_ON_LAYER = depend_pb2.JOB_ON_LAYER
JOB_ON_FRAME = depend_pb2.JOB_ON_FRAME
LAYER_ON_JOB = depend_pb2.LAYER_ON_JOB
LAYER_ON_LAYER = depend_pb2.LAYER_ON_LAYER
LAYER_ON_FRAME = depend_pb2.LAYER_ON_FRAME
FRAME_ON_JOB = depend_pb2.FRAME_ON_JOB
FRAME_ON_LAYER = depend_pb2.FRAME_ON_LAYER
FRAME_ON_FRAME = depend_pb2.FRAME_ON_FRAME
FRAME_BY_FRAME = depend_pb2.FRAME_BY_FRAME
PREVIOUS_FRAME = depend_pb2.PREVIOUS_FRAME
LAYER_ON_SIM_FRAME = depend_pb2.LAYER_ON_SIM_FRAME

class DependTarget(enum.IntEnum):
INTERNAL = depend_pb2.INTERNAL
EXTERNAL = depend_pb2.EXTERNAL
ANY_TARGET = depend_pb2.ANY_TARGET

def __init__(self, depend=None):
self.data = depend
self.stub = Cuebot.getStub('depend')
Expand Down
51 changes: 50 additions & 1 deletion pycue/opencue/wrappers/filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
"""


import enum

from opencue import Cuebot
from opencue.compiled_proto import filter_pb2
from opencue.compiled_proto import job_pb2
Expand All @@ -40,7 +43,12 @@


class Filter(object):
"""This class contains the ice implementation related to a spank Filter."""
"""This class contains the grpc implementation related to a Filter."""

class FilterType(enum.IntEnum):
MATCH_ANY = filter_pb2.MATCH_ANY
MATCH_ALL = filter_pb2.MATCH_ALL

def __init__(self, filter):
"""_Filter class initialization"""
self.data = filter
Expand Down Expand Up @@ -203,6 +211,27 @@ def id(self):


class Action(object):

class ActionType(enum.IntEnum):
MOVE_JOB_TO_GROUP = filter_pb2.MOVE_JOB_TO_GROUP
PAUSE_JOB = filter_pb2.PAUSE_JOB
SET_JOB_MIN_CORES = filter_pb2.SET_JOB_MIN_CORES
SET_JOB_MAX_CORES = filter_pb2.SET_JOB_MAX_CORES
STOP_PROCESSING = filter_pb2.STOP_PROCESSING
SET_JOB_PRIORITY = filter_pb2.SET_JOB_PRIORITY
SET_ALL_RENDER_LAYER_TAGS = filter_pb2.SET_ALL_RENDER_LAYER_TAGS
SET_ALL_RENDER_LAYER_MEMORY = filter_pb2.SET_ALL_RENDER_LAYER_MEMORY
SET_ALL_RENDER_LAYER_CORES = filter_pb2.SET_ALL_RENDER_LAYER_CORES
SET_MEMORY_OPTIMIZER = filter_pb2.SET_MEMORY_OPTIMIZER

class ActionValueType(enum.IntEnum):
GROUP_TYPE = filter_pb2.GROUP_TYPE
STRING_TYPE = filter_pb2.STRING_TYPE
INTEGER_TYPE = filter_pb2.INTEGER_TYPE
FLOAT_TYPE = filter_pb2.FLOAT_TYPE
BOOLEAN_TYPE = filter_pb2.BOOLEAN_TYPE
NONE_TYPE = filter_pb2.NONE_TYPE

def __init__(self, action=None):
self.data = action
self.stub = Cuebot.getStub('action')
Expand Down Expand Up @@ -295,6 +324,26 @@ def id(self):


class Matcher(object):

class MatchSubject(enum.IntEnum):
JOB_NAME = filter_pb2.JOB_NAME
SHOW = filter_pb2.SHOW
SHOT = filter_pb2.SHOT
USER = filter_pb2.USER
SERVICE_NAME = filter_pb2.SERVICE_NAME
PRIORITY = filter_pb2.PRIORITY
FACILITY = filter_pb2.FACILITY
LAYER_NAME = filter_pb2.LAYER_NAME

class MatchType(enum.IntEnum):
CONTAINS = filter_pb2.CONTAINS
DOES_NOT_CONTAIN = filter_pb2.DOES_NOT_CONTAIN
IS = filter_pb2.IS
IS_NOT = filter_pb2.IS_NOT
REGEX = filter_pb2.REGEX
BEGINS_WITH = filter_pb2.BEGINS_WITH
ENDS_WITH = filter_pb2.ENDS_WITH

def __init__(self, matcher=None):
self.data = matcher
self.stub = Cuebot.getStub('matcher')
Expand Down
23 changes: 23 additions & 0 deletions pycue/opencue/wrappers/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"""


import enum
import time

from opencue import Cuebot
Expand All @@ -28,6 +29,28 @@


class Frame(object):

class CheckpointState(enum.IntEnum):
DISABLED = job_pb2.DISABLED
ENABLED = job_pb2.ENABLED
COPYING = job_pb2.COPYING
COMPLETE = job_pb2.COMPLETE

class FrameExitStatus(enum.IntEnum):
SUCCESS = job_pb2.SUCCESS
NO_RETRY = job_pb2.NO_RETRY
SKIP_RETRY = job_pb2.SKIP_RETRY

class FrameState(enum.IntEnum):
WAITING = job_pb2.WAITING
SETUP = job_pb2.SETUP
RUNNING = job_pb2.RUNNING
SUCCEEDED = job_pb2.SUCCEEDED
DEPEND = job_pb2.DEPEND
DEAD = job_pb2.DEAD
EATEN = job_pb2.EATEN
CHECKPOINT = job_pb2.CHECKPOINT

def __init__(self, frame):
"""_Frame class initialization"""
self.data = frame
Expand Down
25 changes: 25 additions & 0 deletions pycue/opencue/wrappers/host.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"""


import enum
import os
import time

Expand All @@ -32,6 +33,30 @@


class Host(object):

class HardwareState(enum.IntEnum):
UP = host_pb2.UP
DOWN = host_pb2.DOWN
REBOOTING = host_pb2.REBOOTING
REBOOT_WHEN_IDLE = host_pb2.REBOOT_WHEN_IDLE
REPAIR = host_pb2.REPAIR

class HostTagType(enum.IntEnum):
MANUAL = host_pb2.MANUAL
HARDWARE = host_pb2.HARDWARE
ALLOC = host_pb2.ALLOC
HOSTNAME = host_pb2.HOSTNAME

class LockState(enum.IntEnum):
OPEN = host_pb2.OPEN
LOCKED = host_pb2.LOCKED
NIMBY_LOCKED = host_pb2.NIMBY_LOCKED

class ThreadMode(enum.IntEnum):
AUTO = host_pb2.AUTO
ALL = host_pb2.ALL
VARIABLE = host_pb2.VARIABLE

def __init__(self, host):
"""Host class initialization"""
self.data = host
Expand Down
9 changes: 9 additions & 0 deletions pycue/opencue/wrappers/job.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"""

import enum
import os
import time

Expand All @@ -36,6 +37,14 @@

class Job(object):
"""This class contains the ice implementation related to a job."""

class JobState(enum.IntEnum):
PENDING = job_pb2.PENDING
FINISHED = job_pb2.FINISHED
STARTUP = job_pb2.STARTUP
SHUTDOWN = job_pb2.SHUTDOWN
POSTED = job_pb2.POSTED

def __init__(self, job=None):
"""_Job class initialization"""
self.data = job
Expand Down
13 changes: 13 additions & 0 deletions pycue/opencue/wrappers/layer.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
implementation of a layer in opencue
"""

import enum

from opencue.compiled_proto import job_pb2
from opencue.cuebot import Cuebot
Expand All @@ -29,6 +30,18 @@


class Layer(object):

class LayerType(enum.IntEnum):
PRE = job_pb2.PRE
POST = job_pb2.POST
RENDER = job_pb2.RENDER
UTIL = job_pb2.UTIL

class Order(enum.IntEnum):
FIRST = job_pb2.FIRST
LAST = job_pb2.LAST
REVERSE = job_pb2.REVERSE

def __init__(self, layer):
self.data = layer
self.stub = Cuebot.getStub('layer')
Expand Down
10 changes: 10 additions & 0 deletions pycue/opencue/wrappers/proc.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
"""

import enum

from opencue.compiled_proto import host_pb2
from opencue.cuebot import Cuebot
import opencue.wrappers.frame
Expand All @@ -31,6 +33,14 @@

class Proc(object):

class RedirectType(enum.IntEnum):
JOB_REDIRECT = host_pb2.JOB_REDIRECT
GROUP_REDIRECT = host_pb2.GROUP_REDIRECT

class RunState(enum.IntEnum):
IDLE = host_pb2.IDLE
BOOKED = host_pb2.BOOKED

def __init__(self, proc):
self.data = proc
self.stub = Cuebot.getStub('proc')
Expand Down
13 changes: 13 additions & 0 deletions pycue/tests/wrappers/depend_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,5 +79,18 @@ def testIsInternalNeg(self, getStubMock):
self.assertFalse(dependNeg.isInternal())


class DependEnumTests(unittest.TestCase):

def testDependType(self):
self.assertEqual(opencue.api.Depend.DependType.JOB_ON_JOB,
opencue.compiled_proto.depend_pb2.JOB_ON_JOB)
self.assertEqual(opencue.api.Depend.DependType.JOB_ON_JOB, 0)

def testDependTarget(self):
self.assertEqual(opencue.api.Depend.DependTarget.ANY_TARGET,
opencue.compiled_proto.depend_pb2.ANY_TARGET)
self.assertEqual(opencue.api.Depend.DependTarget.ANY_TARGET, 2)


if __name__ == '__main__':
unittest.main()
34 changes: 34 additions & 0 deletions pycue/tests/wrappers/filter_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -512,5 +512,39 @@ def testIsNew(self, getStubMock):
self.assertTrue(matcherTrue.isNew())


class FilterEnumTests(unittest.TestCase):

def testFilterType(self):
self.assertEqual(opencue.api.Filter.FilterType.MATCH_ANY,
opencue.compiled_proto.filter_pb2.MATCH_ANY)
self.assertEqual(opencue.api.Filter.FilterType.MATCH_ANY, 0)


class ActionEnumTests(unittest.TestCase):

def testActionType(self):
self.assertEqual(opencue.api.Action.ActionType.MOVE_JOB_TO_GROUP,
opencue.compiled_proto.filter_pb2.MOVE_JOB_TO_GROUP)
self.assertEqual(opencue.api.Action.ActionType.MOVE_JOB_TO_GROUP, 0)

def testActionValueType(self):
self.assertEqual(opencue.api.Action.ActionValueType.INTEGER_TYPE,
opencue.compiled_proto.filter_pb2.INTEGER_TYPE)
self.assertEqual(opencue.api.Action.ActionValueType.INTEGER_TYPE, 2)


class MatcherEnumTests(unittest.TestCase):

def testMatchSubject(self):
self.assertEqual(opencue.api.Matcher.MatchSubject.JOB_NAME,
opencue.compiled_proto.filter_pb2.JOB_NAME)
self.assertEqual(opencue.api.Matcher.MatchSubject.JOB_NAME, 0)

def testMatchType(self):
self.assertEqual(opencue.api.Matcher.MatchType.IS,
opencue.compiled_proto.filter_pb2.IS)
self.assertEqual(opencue.api.Matcher.MatchType.IS, 2)


if __name__ == '__main__':
unittest.main()
18 changes: 18 additions & 0 deletions pycue/tests/wrappers/frame_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,5 +191,23 @@ def testRunTimeDone(self, getStubMock):
self.assertEqual(runningFrame.runTime(), expected)


class FrameEnumTests(unittest.TestCase):

def testCheckpointState(self):
self.assertEqual(opencue.api.Frame.CheckpointState.DISABLED,
opencue.compiled_proto.job_pb2.DISABLED)
self.assertEqual(opencue.api.Frame.CheckpointState.DISABLED, 0)

def testFrameExitStatus(self):
self.assertEqual(opencue.api.Frame.FrameExitStatus.NO_RETRY,
opencue.compiled_proto.job_pb2.NO_RETRY)
self.assertEqual(opencue.api.Frame.FrameExitStatus.NO_RETRY, 256)

def testFrameState(self):
self.assertEqual(opencue.api.Frame.FrameState.RUNNING,
opencue.compiled_proto.job_pb2.RUNNING)
self.assertEqual(opencue.api.Frame.FrameState.RUNNING, 2)


if __name__ == '__main__':
unittest.main()
22 changes: 22 additions & 0 deletions pycue/tests/wrappers/host_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,5 +272,27 @@ def testSetThreadMode(self, getStubMock):
timeout=mock.ANY)


class HostEnumTests(unittest.TestCase):

def testHardwareState(self):
self.assertEqual(opencue.api.Host.HardwareState.UP, opencue.compiled_proto.host_pb2.UP)
self.assertEqual(opencue.api.Host.HardwareState.UP, 0)

def testHostTagType(self):
self.assertEqual(opencue.api.Host.HostTagType.HARDWARE,
opencue.compiled_proto.host_pb2.HARDWARE)
self.assertEqual(opencue.api.Host.HostTagType.HARDWARE, 1)

def testLockState(self):
self.assertEqual(opencue.api.Host.LockState.NIMBY_LOCKED,
opencue.compiled_proto.host_pb2.NIMBY_LOCKED)
self.assertEqual(opencue.api.Host.LockState.NIMBY_LOCKED, 2)

def testThreadMode(self):
self.assertEqual(opencue.api.Host.ThreadMode.ALL,
opencue.compiled_proto.host_pb2.ALL)
self.assertEqual(opencue.api.Host.ThreadMode.ALL, 1)


if __name__ == '__main__':
unittest.main()
Loading

0 comments on commit 75b080b

Please sign in to comment.