|
| 1 | +# Copyright Contributors to the OpenCue Project |
| 2 | +# |
| 3 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +# you may not use this file except in compliance with the License. |
| 5 | +# You may obtain a copy of the License at |
| 6 | +# |
| 7 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +# |
| 9 | +# Unless required by applicable law or agreed to in writing, software |
| 10 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +# See the License for the specific language governing permissions and |
| 13 | +# limitations under the License. |
| 14 | + |
| 15 | +"""Module for classes related to departments.""" |
| 16 | + |
| 17 | +from opencue_proto import department_pb2 |
| 18 | +from opencue.cuebot import Cuebot |
| 19 | +import opencue.wrappers.task |
| 20 | + |
| 21 | + |
| 22 | +class Department(object): |
| 23 | + """This class contains the grpc implementation related to a Department.""" |
| 24 | + |
| 25 | + def __init__(self, department=None): |
| 26 | + self.data = department |
| 27 | + self.stub = Cuebot.getStub('department') |
| 28 | + |
| 29 | + def addTask(self, shot, minCores): |
| 30 | + """Adds a task to the department and returns it. |
| 31 | +
|
| 32 | + :type shot: str |
| 33 | + :param shot: name of the shot the task is for |
| 34 | + :type minCores: float |
| 35 | + :param minCores: the minimum number of cores the task needs |
| 36 | + :rtype: opencue.wrappers.task.Task |
| 37 | + :return: the newly created task |
| 38 | + """ |
| 39 | + response = self.stub.AddTask( |
| 40 | + department_pb2.DeptAddTaskRequest( |
| 41 | + department=self.data, shot=shot, min_cores=minCores), |
| 42 | + timeout=Cuebot.Timeout) |
| 43 | + return opencue.wrappers.task.Task(response.task) |
| 44 | + |
| 45 | + def addTasks(self, taskMap): |
| 46 | + """Adds a map of tasks to the department and returns them as a list. |
| 47 | +
|
| 48 | + :type taskMap: dict<str, int> |
| 49 | + :param taskMap: map of shot names to minimum core units |
| 50 | + :rtype: list<opencue.wrappers.task.Task> |
| 51 | + :return: the newly created tasks |
| 52 | + """ |
| 53 | + response = self.stub.AddTasks( |
| 54 | + department_pb2.DeptAddTasksRequest(department=self.data, tmap=taskMap), |
| 55 | + timeout=Cuebot.Timeout) |
| 56 | + return [opencue.wrappers.task.Task(task) for task in response.tasks.tasks] |
| 57 | + |
| 58 | + def clearTaskAdjustments(self): |
| 59 | + """Clears all manual task adjustments to managed tasks. |
| 60 | +
|
| 61 | + This won't do anything unless the department is Track-It managed. |
| 62 | + """ |
| 63 | + self.stub.ClearTaskAdjustments( |
| 64 | + department_pb2.DeptClearTaskAdjustmentsRequest(department=self.data), |
| 65 | + timeout=Cuebot.Timeout) |
| 66 | + |
| 67 | + def clearTasks(self): |
| 68 | + """Clears all tasks from the department.""" |
| 69 | + self.stub.ClearTasks( |
| 70 | + department_pb2.DeptClearTasksRequest(department=self.data), |
| 71 | + timeout=Cuebot.Timeout) |
| 72 | + |
| 73 | + def disableTiManaged(self): |
| 74 | + """Disables Track-It management; this also clears all tasks.""" |
| 75 | + self.stub.DisableTiManaged( |
| 76 | + department_pb2.DeptDisableTiManagedRequest(department=self.data), |
| 77 | + timeout=Cuebot.Timeout) |
| 78 | + |
| 79 | + def enableTiManaged(self, tiTask, managedCores): |
| 80 | + """Enables Track-It management. |
| 81 | +
|
| 82 | + This will pull a task list from Track-It and keep it synced. |
| 83 | +
|
| 84 | + :type tiTask: str |
| 85 | + :param tiTask: name of the Track-It task to manage the department with |
| 86 | + :type managedCores: float |
| 87 | + :param managedCores: the number of cores to split up among the active tasks |
| 88 | + """ |
| 89 | + self.stub.EnableTiManaged( |
| 90 | + department_pb2.DeptEnableTiManagedRequest( |
| 91 | + department=self.data, ti_task=tiTask, managed_cores=managedCores), |
| 92 | + timeout=Cuebot.Timeout) |
| 93 | + |
| 94 | + def getTasks(self): |
| 95 | + """Returns the list of tasks for the department. |
| 96 | +
|
| 97 | + :rtype: list<opencue.wrappers.task.Task> |
| 98 | + :return: tasks of the department |
| 99 | + """ |
| 100 | + response = self.stub.GetTasks( |
| 101 | + department_pb2.DeptGetTasksRequest(department=self.data), |
| 102 | + timeout=Cuebot.Timeout) |
| 103 | + return [opencue.wrappers.task.Task(task) for task in response.tasks.tasks] |
| 104 | + |
| 105 | + def replaceTasks(self, taskMap): |
| 106 | + """Replaces a map of tasks; existing tasks are updated, new tasks are inserted. |
| 107 | +
|
| 108 | + :type taskMap: dict<str, int> |
| 109 | + :param taskMap: map of shot names to minimum core units |
| 110 | + :rtype: list<opencue.wrappers.task.Task> |
| 111 | + :return: the resulting tasks |
| 112 | + """ |
| 113 | + response = self.stub.ReplaceTasks( |
| 114 | + department_pb2.DeptReplaceTaskRequest(department=self.data, tmap=taskMap), |
| 115 | + timeout=Cuebot.Timeout) |
| 116 | + return [opencue.wrappers.task.Task(task) for task in response.tasks.tasks] |
| 117 | + |
| 118 | + def setManagedCores(self, managedCores): |
| 119 | + """Sets the minimum number of cores for the department to manage between its tasks. |
| 120 | +
|
| 121 | + :type managedCores: float |
| 122 | + :param managedCores: the number of cores to manage between the tasks |
| 123 | + """ |
| 124 | + self.stub.SetManagedCores( |
| 125 | + department_pb2.DeptSetManagedCoresRequest( |
| 126 | + department=self.data, managed_cores=managedCores), |
| 127 | + timeout=Cuebot.Timeout) |
| 128 | + |
| 129 | + def id(self): |
| 130 | + """Returns the unique id of the department. |
| 131 | +
|
| 132 | + :rtype: str |
| 133 | + :return: department id |
| 134 | + """ |
| 135 | + return self.data.id |
| 136 | + |
| 137 | + def name(self): |
| 138 | + """Returns the name of the department. |
| 139 | +
|
| 140 | + :rtype: str |
| 141 | + :return: department name |
| 142 | + """ |
| 143 | + return self.data.name |
0 commit comments