diff --git a/ci/pylintrc_test b/ci/pylintrc_test index 1e71a142b..dc175b0b3 100644 --- a/ci/pylintrc_test +++ b/ci/pylintrc_test @@ -69,6 +69,7 @@ disable=duplicate-code, no-self-use, protected-access, raise-missing-from, + too-many-locals, too-many-public-methods, unused-argument, unused-variable, diff --git a/ci/run_python_tests.sh b/ci/run_python_tests.sh index 8e3b72e7e..a4797092f 100755 --- a/ci/run_python_tests.sh +++ b/ci/run_python_tests.sh @@ -22,6 +22,10 @@ python rqd/setup.py test # Some environments don't have pylint available, for ones that do they should pass this flag. if [[ "$1" == "--lint" ]]; then + cd pycue && python -m pylint --rcfile=../ci/pylintrc_main FileSequence && cd .. + cd pycue && python -m pylint --rcfile=../ci/pylintrc_main opencue --ignore=opencue/compiled_proto && cd .. + cd pycue && python -m pylint --rcfile=../ci/pylintrc_test tests && cd .. + cd pyoutline && PYTHONPATH=../pycue python -m pylint --rcfile=../ci/pylintrc_main outline && cd .. cd pyoutline && PYTHONPATH=../pycue python -m pylint --rcfile=../ci/pylintrc_test tests && cd .. diff --git a/pycue/FileSequence/FrameRange.py b/pycue/FileSequence/FrameRange.py index 1cce4a39f..6f565f26b 100644 --- a/pycue/FileSequence/FrameRange.py +++ b/pycue/FileSequence/FrameRange.py @@ -12,6 +12,12 @@ # See the License for the specific language governing permissions and # limitations under the License. +""" +Helper class for representing a frame range. + +It supports a complex syntax implementing features such as comma-separated frame ranges, +stepped frame ranges and more. See the FrameRange class for more detail. +""" from __future__ import division from __future__ import print_function @@ -25,11 +31,12 @@ class FrameRange(object): - """Represents a sequence of image frames.""" + """Represents a sequence of frame numbers.""" SINGLE_FRAME_PATTERN = re.compile(r'^(-?)\d+$') SIMPLE_FRAME_RANGE_PATTERN = re.compile(r'^(?P(-?)\d+)-(?P(-?)\d+)$') - STEP_PATTERN = re.compile(r'^(?P(-?)\d+)-(?P(-?)\d+)(?P[xy])(?P(-?)\d+)$') + STEP_PATTERN = re.compile( + r'^(?P(-?)\d+)-(?P(-?)\d+)(?P[xy])(?P(-?)\d+)$') INTERLEAVE_PATTERN = re.compile(r'^(?P(-?)\d+)-(?P(-?)\d+):(?P(-?)\d+)$') def __init__(self, frameRange): @@ -103,11 +110,20 @@ def getAll(self): return self.frameList def normalize(self): + """Sorts and deduplicates the sequence.""" self.frameList = list(set(self.frameList)) self.frameList.sort() @classmethod def parseFrameRange(cls, frameRange): + """ + Parse a string representation into a numerical sequence. + + :type frameRange: str + :param frameRange: String representation of the frame range. + :rtype: FrameRange + :return: FrameRange representing the numerical sequence. + """ singleFrameMatcher = re.match(cls.SINGLE_FRAME_PATTERN, frameRange) if singleFrameMatcher: return [int(frameRange)] @@ -116,7 +132,7 @@ def parseFrameRange(cls, frameRange): if simpleRangeMatcher: startFrame = int(simpleRangeMatcher.group('sf')) endFrame = int(simpleRangeMatcher.group('ef')) - return cls.getIntRange(startFrame, endFrame, (1 if endFrame >= startFrame else -1)) + return cls.__getIntRange(startFrame, endFrame, (1 if endFrame >= startFrame else -1)) rangeWithStepMatcher = re.match(cls.STEP_PATTERN, frameRange) if rangeWithStepMatcher: @@ -124,48 +140,49 @@ def parseFrameRange(cls, frameRange): endFrame = int(rangeWithStepMatcher.group('ef')) step = int(rangeWithStepMatcher.group('step')) stepSep = rangeWithStepMatcher.group('stepSep') - return cls.getSteppedRange(startFrame, endFrame, step, stepSep == 'y') + return cls.__getSteppedRange(startFrame, endFrame, step, stepSep == 'y') rangeWithInterleaveMatcher = re.match(cls.INTERLEAVE_PATTERN, frameRange) if rangeWithInterleaveMatcher: startFrame = int(rangeWithInterleaveMatcher.group('sf')) endFrame = int(rangeWithInterleaveMatcher.group('ef')) step = int(rangeWithInterleaveMatcher.group('step')) - return cls.getInterleavedRange(startFrame, endFrame, step) + return cls.__getInterleavedRange(startFrame, endFrame, step) raise ValueError('unrecognized frame range syntax ' + frameRange) @staticmethod - def getIntRange(start, end, step): + def __getIntRange(start, end, step): return list(range(start, end+(step // abs(step)), step)) @classmethod - def getSteppedRange(cls, start, end, step, inverseStep): - cls.validateStepSign(start, end, step) - steppedRange = cls.getIntRange(start, end, step) + def __getSteppedRange(cls, start, end, step, inverseStep): + cls.__validateStepSign(start, end, step) + steppedRange = cls.__getIntRange(start, end, step) if inverseStep: - fullRange = cls.getIntRange(start, end, (-1 if step < 0 else 1)) + fullRange = cls.__getIntRange(start, end, (-1 if step < 0 else 1)) return [frame for frame in fullRange if frame not in steppedRange] return steppedRange @classmethod - def getInterleavedRange(cls, start, end, step): - cls.validateStepSign(start, end, step) + def __getInterleavedRange(cls, start, end, step): + cls.__validateStepSign(start, end, step) interleavedFrames = OrderedDict() incrValue = step // abs(step) while abs(step) > 0: - interleavedFrames.update([(frame, None) for frame in cls.getIntRange(start, end, step)]) + interleavedFrames.update( + [(frame, None) for frame in cls.__getIntRange(start, end, step)]) start += incrValue step = int(step / 2.0) return list(interleavedFrames.keys()) @staticmethod - def validateStepSign(start, end, step): + def __validateStepSign(start, end, step): if step > 1 and end < start: raise ValueError( 'end frame may not be less than start frame when using a positive step') - elif step == 0: + if step == 0: raise ValueError('step cannot be zero') - elif step < 0 and end >= start: + if step < 0 and end >= start: raise ValueError( 'end frame may not be greater than start frame when using a negative step') diff --git a/pycue/FileSequence/FrameSet.py b/pycue/FileSequence/FrameSet.py index b4c45201c..5ff1629e4 100644 --- a/pycue/FileSequence/FrameSet.py +++ b/pycue/FileSequence/FrameSet.py @@ -12,6 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. +"""Module for `FileSequence.FrameSet`.""" from __future__ import absolute_import from __future__ import print_function @@ -23,7 +24,7 @@ class FrameSet(object): - """Represents a sequence of FrameRanges.""" + """Represents a sequence of `FileSequence.FrameRange`.""" def __init__(self, frameRange): """Construct a FrameSet object by parsing a spec. @@ -67,11 +68,20 @@ def getAll(self): return self.frameList def normalize(self): + """Sorts and dedeuplicates the sequence.""" self.frameList = list(set(self.frameList)) self.frameList.sort() @staticmethod def parseFrameRange(frameRange): + """ + Parses a string representation of a frame range into a FrameSet. + + :type frameRange: str + :param frameRange: String representation of the frame range. + :rtype: FrameSet + :return: The FrameSet representing the same sequence. + """ frameList = list() for frameRangeSection in frameRange.split(','): frameList.extend(FrameRange.parseFrameRange(frameRangeSection)) diff --git a/pycue/FileSequence/__init__.py b/pycue/FileSequence/__init__.py index 75ee7dd87..711e1dc83 100644 --- a/pycue/FileSequence/__init__.py +++ b/pycue/FileSequence/__init__.py @@ -1,3 +1,23 @@ +# Copyright Contributors to the OpenCue Project +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +""" +Top-level module of FileSequence. + +FileSequence contains helper classes for representing a job's frame range. +""" + from __future__ import absolute_import from __future__ import print_function from __future__ import division diff --git a/pycue/opencue/__init__.py b/pycue/opencue/__init__.py index 3b90531d1..2ceca5f53 100644 --- a/pycue/opencue/__init__.py +++ b/pycue/opencue/__init__.py @@ -12,6 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. +"""Top level of the opencue module.""" from __future__ import absolute_import from __future__ import print_function @@ -19,6 +20,7 @@ import logging +# pylint: disable=cyclic-import from .cuebot import Cuebot from . import api from . import wrappers @@ -26,7 +28,9 @@ from .exception import CueException from .exception import EntityNotFoundException +# pylint: disable=redefined-builtin from .util import id +# pylint: enable=redefined-builtin from .util import logPath from .util import proxy from .util import rep diff --git a/pycue/opencue/api.py b/pycue/opencue/api.py index b80ccce73..10dbed4cc 100644 --- a/pycue/opencue/api.py +++ b/pycue/opencue/api.py @@ -12,19 +12,12 @@ # See the License for the specific language governing permissions and # limitations under the License. +"""The OpenCue static API.""" - -""" -The opencue Static API. This is exported into the package namespace. - -Project: opencue Library -""" from __future__ import absolute_import from __future__ import print_function from __future__ import division -from . import search -from . import util from opencue.compiled_proto import comment_pb2 from opencue.compiled_proto import criterion_pb2 from opencue.compiled_proto import cue_pb2 @@ -42,6 +35,7 @@ from opencue.compiled_proto import subscription_pb2 from opencue.compiled_proto import task_pb2 from .cuebot import Cuebot +# pylint: disable=cyclic-import from .wrappers.allocation import Allocation from .wrappers.comment import Comment from .wrappers.depend import Depend @@ -60,11 +54,13 @@ from .wrappers.show import Show from .wrappers.subscription import Subscription from .wrappers.task import Task +from . import search +from . import util __protobufs = [comment_pb2, criterion_pb2, cue_pb2, department_pb2, depend_pb2, facility_pb2, - filter_pb2, host_pb2, job_pb2, renderPartition_pb2, report_pb2, service_pb2, show_pb2, - subscription_pb2, task_pb2] + filter_pb2, host_pb2, job_pb2, renderPartition_pb2, report_pb2, service_pb2, + show_pb2, subscription_pb2, task_pb2] __wrappers = [Action, Allocation, Comment, Depend, Filter, Frame, Group, Host, Job, Layer, Matcher, NestedHost, Proc, Show, Subscription, Task] @@ -319,7 +315,7 @@ def getJobs(**options): For example:: # returns only pipe jobs. - getJobs(show=["pipe"]) + getJobs(show=["pipe"]) Possible args: - job: job names - list @@ -391,8 +387,6 @@ def getJobNames(**options): """Returns a list of job names that match the search parameters. See getJobs for the job query options. - :type options: dict - :param options: a variable list of search criteria :rtype: list :return: List of matching str job names""" criteria = search.JobSearch.criteriaFromOptions(**options) @@ -557,15 +551,15 @@ def getHost(uniq): # Owners # @util.grpcExceptionParser -def getOwner(id): +def getOwner(owner_id): """Return an Owner object from the ID or name. - :type id: str - :param id: a unique owner identifier or name + :type owner_id: str + :param owner_id: a unique owner identifier or name :rtype: Owner :return: An Owner object""" return Owner(Cuebot.getStub('owner').GetOwner( - host_pb2.OwnerGetOwnerRequest(name=id), timeout=Cuebot.Timeout).owner) + host_pb2.OwnerGetOwnerRequest(name=owner_id), timeout=Cuebot.Timeout).owner) # # Filters @@ -640,12 +634,27 @@ def getAllocation(allocId): @util.grpcExceptionParser def deleteAllocation(alloc): + """Deletes an allocation. + + :type alloc: facility_pb2.Allocation + :param alloc: allocation to delete + :rtype: facility_pb2.AllocDeleteResponse + :return: empty response""" return Cuebot.getStub('allocation').Delete( facility_pb2.AllocDeleteRequest(allocation=alloc), timeout=Cuebot.Timeout) @util.grpcExceptionParser def allocSetBillable(alloc, is_billable): + """Sets an allocation billable or not. + + :type alloc: facility_pb2.Allocation + :param alloc: allocation to set + :type is_billable: bool + :param is_billable: whether alloc should be billable or not + :rtype: facility_pb2.AllocSetBillableResponse + :return: empty response + """ return Cuebot.getStub('allocation').SetBillable( facility_pb2.AllocSetBillableRequest(allocation=alloc, value=is_billable), timeout=Cuebot.Timeout) @@ -653,12 +662,28 @@ def allocSetBillable(alloc, is_billable): @util.grpcExceptionParser def allocSetName(alloc, name): + """Sets an allocation name. + + :type alloc: facility_pb2.Allocation + :param alloc: allocation to set + :type name: str + :param name: new name for the allocation + :rtype: facility_pb2.AllocSetNameResponse + :return: empty response""" return Cuebot.getStub('allocation').SetName( facility_pb2.AllocSetNameRequest(allocation=alloc, name=name), timeout=Cuebot.Timeout) @util.grpcExceptionParser def allocSetTag(alloc, tag): + """Sets an allocation tag. + + :type alloc: facility_pb2.Allocation + :param alloc: allocation to tag + :type tag: str + :param tag: new tag + :rtype: facility_pb2.AllocSetTagResponse + :return: empty response""" return Cuebot.getStub('allocation').SetTag( facility_pb2.AllocSetTagRequest(allocation=alloc, tag=tag), timeout=Cuebot.Timeout) diff --git a/pycue/opencue/cuebot.py b/pycue/opencue/cuebot.py index f3e97bb02..1211c9fe4 100644 --- a/pycue/opencue/cuebot.py +++ b/pycue/opencue/cuebot.py @@ -12,6 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. +"""Module for communicating with the Cuebot server(s).""" from __future__ import print_function from __future__ import division @@ -20,11 +21,12 @@ from builtins import object from random import shuffle import atexit -import grpc import logging import os import yaml +import grpc + from opencue.compiled_proto import comment_pb2 from opencue.compiled_proto import comment_pb2_grpc from opencue.compiled_proto import criterion_pb2 @@ -175,8 +177,9 @@ def setChannel(): # Test the connection Cuebot.getStub('cue').GetSystemStats( cue_pb2.CueGetSystemStatsRequest(), timeout=Cuebot.Timeout) + # pylint: disable=broad-except except Exception: - logger.warning('Could not establish grpc channel with {}.'.format(connectStr)) + logger.warning('Could not establish grpc channel with %s', connectStr) continue atexit.register(Cuebot.closeChannel) return None @@ -206,10 +209,9 @@ def setFacility(facility): :param facility: a facility named in the config file""" if facility not in list(config.get("cuebot.facility").keys()): default = config.get("cuebot.facility_default") - logger.warning("The facility '%s' does not exist, defaulting to %s"% - (facility, default)) + logger.warning("The facility '%s' does not exist, defaulting to %s", facility, default) facility = default - logger.debug("setting facility to: %s" % facility) + logger.debug("setting facility to: %s", facility) hosts = config.get("cuebot.facility")[facility] Cuebot.setHosts(hosts) @@ -221,7 +223,7 @@ def setHosts(hosts): :type hosts: list or str""" if isinstance(hosts, str): hosts = [hosts] - logger.debug("setting new server hosts to: %s" % hosts) + logger.debug("setting new server hosts to: %s", hosts) Cuebot.Hosts = hosts Cuebot.resetChannel() @@ -232,11 +234,12 @@ def setTimeout(timeout): :param timeout: The network connection timeout in millis. :type timeout: int """ - logger.debug("setting new server timeout to: %d" % timeout) + logger.debug("setting new server timeout to: %d", timeout) Cuebot.Timeout = timeout @classmethod def getProto(cls, name): + """Returns a proto class for the given name.""" proto = cls.PROTO_MAP.get(name) if proto is None: raise ValueError("Could not find proto for {}.".format(name)) @@ -244,6 +247,7 @@ def getProto(cls, name): @classmethod def getService(cls, name): + """Returns the service for the given name.""" service = cls.SERVICE_MAP.get(name) if service is None: raise ValueError("Could not find stub interface for {}.".format(name)) @@ -264,4 +268,5 @@ def getStub(cls, name): @staticmethod def getConfig(): + """Gets the Cuebot config object, originally read in from the config file on disk.""" return config diff --git a/pycue/opencue/exception.py b/pycue/opencue/exception.py index 5c31a6441..cc15a6902 100644 --- a/pycue/opencue/exception.py +++ b/pycue/opencue/exception.py @@ -12,12 +12,8 @@ # See the License for the specific language governing permissions and # limitations under the License. +"""Custom exception classes for API error handling.""" -""" -Project: opencue Library - -Module: exception.py - Provides opencue access to exceptions -""" from __future__ import print_function from __future__ import division from __future__ import absolute_import @@ -58,6 +54,7 @@ class CueInternalErrorException(CueException): failMsg = 'Server caught an internal exception. {details}' retryMsg = 'Server caught an internal exception, checking again...' + class ConnectionException(CueException): """Raised when unable to connect to grpc server.""" failMsg = 'Unable to contact grpc server. {details}' @@ -78,4 +75,3 @@ def getRetryCount(): grpc.StatusCode.INTERNAL: CueInternalErrorException, grpc.StatusCode.UNAVAILABLE: ConnectionException } - diff --git a/pycue/opencue/search.py b/pycue/opencue/search.py index 9e4776724..995cf6e51 100644 --- a/pycue/opencue/search.py +++ b/pycue/opencue/search.py @@ -12,11 +12,9 @@ # See the License for the specific language governing permissions and # limitations under the License. +"""Client side implementation of search criteria. -""" -Client side implementation of search criteria. -This module provides some easy factory -methods to do common search operations. It also exposes +This module provides some easy factory methods to do common search operations. It also exposes lower level RPC functionality for procedural searches. ============== @@ -33,7 +31,7 @@ s.shows.append("pipe") s.users.append("chambers") jobs = s.find() - + A procedural example searching by regular expression:: s = JobSearch() @@ -48,15 +46,16 @@ job.proxy.kill() """ + from __future__ import absolute_import from __future__ import print_function from __future__ import division - from builtins import object import logging import six +# pylint: disable=cyclic-import from opencue.compiled_proto import criterion_pb2 from opencue.compiled_proto import host_pb2 from opencue.compiled_proto import job_pb2 @@ -73,50 +72,56 @@ class BaseSearch(object): + """Base class for searching.""" + def __init__(self, **options): self.options = options def search(self): + """Executes the search using the options provided at initiation.""" return self.byOptions(**self.options) @classmethod def byOptions(cls, **options): + """Executes the search using the provided options.""" raise NotImplementedError class ProcSearch(BaseSearch): - """See: help(opencue.getProcs)""" - def __init__(self, **options): - super(ProcSearch, self).__init__(**options) + """Class for searching for procs. + + See: help(opencue.getProcs)""" @staticmethod def criteriaFromOptions(**options): + """Constructs a search criteria object for the given options.""" return _setOptions(host_pb2.ProcSearchCriteria(), options) @classmethod def byOptions(cls, **options): + """Executes the search using the given options.""" criteria = cls.criteriaFromOptions(**options) return Cuebot.getStub('proc').GetProcs( host_pb2.ProcGetProcsRequest(r=criteria), timeout=Cuebot.Timeout) class FrameSearch(BaseSearch): + """Class for searching for frames.""" page = 1 limit = 1000 change_date = 0 - def __init__(self, **options): - super(FrameSearch, self).__init__(**options) - @classmethod def criteriaFromOptions(cls, **options): + """Constructs a search criteria object for the given options.""" criteria = _setOptions(job_pb2.FrameSearchCriteria(), options) criteria.page = options.get('page', cls.page) criteria.limit = options.get('limit', cls.limit) criteria.change_date = options.get('change_date', cls.change_date) return criteria + # pylint: disable=arguments-differ @classmethod def byOptions(cls, job, **options): criteria = cls.criteriaFromOptions(**options) @@ -125,15 +130,16 @@ def byOptions(cls, job, **options): @classmethod def byRange(cls, job, val): + """Executes a search by frame range.""" cls.byOptions(job, frame_range=val) class HostSearch(BaseSearch): - def __init__(self, **options): - super(HostSearch, self).__init__(**options) + """Class for searching for hosts.""" @staticmethod def criteriaFromOptions(**options): + """Constructs a search criteria object for the given options.""" return _setOptions(host_pb2.HostSearchCriteria(), options) @classmethod @@ -145,31 +151,36 @@ def byOptions(cls, **options): @classmethod def byName(cls, val): + """Searches for a host by name.""" return cls.byOptions(name=val) @classmethod def byRegex(cls, val): + """Searches for a host by regular expression.""" return cls.byOptions(regex=val) @classmethod def byId(cls, val): + """Searches for a host by id.""" return cls.byOptions(id=val) @classmethod def byMatch(cls, val): + """Searches for a host by substring match.""" return cls.byOptions(substr=val) @classmethod def byAllocation(cls, val): + """Searches for a host by allocation.""" return cls.byOptions(alloc=val) class JobSearch(BaseSearch): - def __init__(self, **options): - super(JobSearch, self).__init__(**options) + """Class for searching for jobs.""" @staticmethod def criteriaFromOptions(**options): + """Constructs a search criteria object for the given options.""" return _setOptions(job_pb2.JobSearchCriteria(), options) @classmethod @@ -180,30 +191,37 @@ def byOptions(cls, **options): @classmethod def byName(cls, val): + """Searches for a job by name.""" return cls.byOptions(job=val) @classmethod def byId(cls, val): + """Searches for a job by id.""" return cls.byOptions(id=val) @classmethod def byRegex(cls, val): + """Searches for a job by regex.""" return cls.byOptions(regex=val) @classmethod def byMatch(cls, val): + """Searches for a job by substring match.""" return cls.byOptions(substr=val) @classmethod def byShow(cls, val): + """Searches for a job by show.""" return cls.byOptions(show=val) @classmethod def byShot(cls, val): + """Searches for a job by shot.""" return cls.byOptions(shots=val) @classmethod def byUser(cls, val): + """Searches for a job by user.""" return cls.byOptions(user=val) @@ -255,15 +273,17 @@ def _convert(val): criterion = getattr(criterion_pb2, "GreaterThan%sSearchCriterion" % searchTypeStr) return criterion(_convert(search[2:])) - elif search.startswith("lt"): + + if search.startswith("lt"): criterion = getattr(criterion_pb2, "LessThan%sSearchCriterion" % searchTypeStr) return criterion(_convert(search[2:])) - elif search.find("-") > -1: + + if search.find("-") > -1: criterion = getattr(criterion_pb2, "InRange%sSearchCriterion" % searchTypeStr) - min, max = search.split("-") - return criterion(_convert(min), _convert(max)) + min_range, max_range = search.split("-") + return criterion(_convert(min_range), _convert(max_range)) raise ValueError("Unable to parse this format: %s" % search) @@ -275,6 +295,7 @@ def _raiseIfNotType(searchOption, value, expectedType): def raiseIfNotList(searchOption, value): + """Raises an exception if the provided value is not a list.""" _raiseIfNotType(searchOption, value, list) diff --git a/pycue/opencue/util.py b/pycue/opencue/util.py index 63ee5fc36..1eb704696 100644 --- a/pycue/opencue/util.py +++ b/pycue/opencue/util.py @@ -12,12 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. - -""" -Project: opencue Library -Module: util.py -""" - +"""Utility methods used throughout the opencue module.""" from __future__ import absolute_import from __future__ import print_function @@ -26,12 +21,13 @@ from builtins import str import functools import future.utils -import grpc import logging import os -import six import time +import six +import grpc + import opencue logger = logging.getLogger('opencue') @@ -47,8 +43,10 @@ def _decorator(*args, **kwargs): try: return grpcFunc(*args, **kwargs) except grpc.RpcError as exc: + # pylint: disable=no-member code = exc.code() details = exc.details() or "No details found. Check server logs." + # pylint: enable=no-member exception = opencue.exception.EXCEPTION_MAP.get(code) if exception: if exception.retryable and triesRemaining >= 1: @@ -65,6 +63,7 @@ def _decorator(*args, **kwargs): return functools.wraps(grpcFunc)(_decorator) +# pylint: disable=redefined-builtin def id(value): """extract(entity) extracts a string unique ID from a opencue entity or @@ -73,14 +72,14 @@ def id(value): def _extract(item): try: return item.id() + # pylint: disable=bare-except except: pass return item if isinstance(value, (tuple, list, set)): return [_extract(v) for v in value] - else: - return _extract(value) + return _extract(value) @grpcExceptionParser @@ -99,8 +98,7 @@ def _proxy(idString): requestor = getattr(proto, "{cls}Get{cls}Request".format(cls=cls)) getMethod = getattr(opencue.Cuebot.getStub(cls.lower()), "Get{}".format(cls)) return getMethod(requestor(id=idString)) - else: - raise AttributeError('Could not find a proto for {}'.format(cls)) + raise AttributeError('Could not find a proto for {}'.format(cls)) def _proxies(entities): messages = [] @@ -113,10 +111,9 @@ def _proxies(entities): if hasattr(idOrObject, 'id'): return _proxy(idOrObject.id) - elif isinstance(idOrObject, six.string_types): + if isinstance(idOrObject, six.string_types): return _proxy(idOrObject) - else: - return _proxies(idOrObject) + return _proxies(idOrObject) def rep(entity): @@ -124,6 +121,7 @@ def rep(entity): Extracts a string repesentation of a opencue entity""" try: return entity.name + # pylint: disable=bare-except except: return str(entity) @@ -134,5 +132,4 @@ def logPath(job, frame=None): """ if frame: return os.path.join(job.data.log_dir, "%s.%s.rqlog" % (job.data.name, frame.data.name)) - else: - return job.data.log_dir + return job.data.log_dir diff --git a/pycue/opencue/version.py b/pycue/opencue/version.py index c353f0689..4c7df1636 100644 --- a/pycue/opencue/version.py +++ b/pycue/opencue/version.py @@ -12,5 +12,9 @@ # See the License for the specific language governing permissions and # limitations under the License. +"""Stores the API version.""" + +# TODO(bcipriano): This module can probably be removed and replaced with the newer +# VERSION file system. version = '5.0' diff --git a/pycue/opencue/wrappers/allocation.py b/pycue/opencue/wrappers/allocation.py index 2f7f52ec9..8539dbf4e 100644 --- a/pycue/opencue/wrappers/allocation.py +++ b/pycue/opencue/wrappers/allocation.py @@ -12,11 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. - -""" -allocation module -""" - +"""Module for classes related to OpenCue allocations.""" from opencue.compiled_proto import facility_pb2 from opencue.compiled_proto import host_pb2 @@ -33,16 +29,15 @@ def __init__(self, allocation=None): self.stub = Cuebot.getStub('allocation') def delete(self): - """Delete the record of the allocation from the cuebot""" + """Deletes the allocation.""" self.stub.Delete( facility_pb2.AllocDeleteRequest(allocation=self.data), - timeout=Cuebot.Timeout - ) + timeout=Cuebot.Timeout) def getHosts(self): - """Returns the list of hosts for this allocation. + """Returns the list of hosts for the allocation. - :rtype: list + :rtype: list :return: list of hosts """ hostSeq = self.stub.GetHosts(facility_pb2.AllocGetHostsRequest(allocation=self.data), @@ -50,34 +45,36 @@ def getHosts(self): return [opencue.wrappers.host.Host(h) for h in hostSeq.hosts] def getSubscriptions(self): - """Get the subscriptions of this allocation. + """Returns the subscriptions of the allocation. - :rtype: list + :rtype: list :return: a list of subscriptions """ subscriptionSeq = self.stub.GetSubscriptions( facility_pb2.AllocGetSubscriptionsRequest(allocation=self.data), timeout=Cuebot.Timeout).subscriptions - return [opencue.wrappers.subscription.Subscription(sub) for sub in subscriptionSeq.subscriptions] + return [opencue.wrappers.subscription.Subscription(sub) + for sub in subscriptionSeq.subscriptions] def reparentHosts(self, hosts): - """Moves the given hosts to the allocation + """Moves the given hosts into the allocation. :type hosts: list - :param hosts: The hosts to move to this allocation + :param hosts: the hosts to move to this allocation """ hostSeq = host_pb2.HostSeq() + # pylint: disable=no-member hostSeq.hosts.extend([host.data for host in hosts]) + # pylint: enable=no-member self.stub.ReparentHosts( facility_pb2.AllocReparentHostsRequest(allocation=self.data, hosts=hostSeq), - timeout=Cuebot.Timeout - ) - + timeout=Cuebot.Timeout) + def reparentHostIds(self, hostIds): - """Moves the given hosts to the allocation + """Moves the hosts identified by the given host ids into the allocation. :type hostIds: list - :param hostIds: The host ids to move to this allocation + :param hostIds: the host ids to move to this allocation """ hosts = [opencue.wrappers.host.Host(host_pb2.Host(id=hostId)) for hostId in hostIds] self.reparentHosts(hosts) @@ -85,7 +82,7 @@ def reparentHostIds(self, hostIds): def setName(self, name): """Sets a new name for the allocation. - :type name: str + :type name: str :param name: the new name """ self.stub.SetName( @@ -95,35 +92,34 @@ def setName(self, name): def setTag(self, tag): """Sets a new tag for the allocation. - :type name: str - :param name: the new tag + :type tag: str + :param tag: the new tag """ self.stub.SetTag( facility_pb2.AllocSetTagRequest(allocation=self.data, tag=tag), - timeout=Cuebot.Timeout - ) + timeout=Cuebot.Timeout) def id(self): - """Returns the id of the allocation + """Returns the id of the allocation. :rtype: str - :return: Allocation uuid + :return: the id of the allocation """ return self.data.id def name(self): - """Returns the name of the allocation + """Returns the name of the allocation. :rtype: str - :return: Allocation name + :return: the name of the allocation """ return self.data.name def tag(self): - """Returns the allocation tag + """Returns the tag of the allocation. :rtype: str - :return: Allocation tag + :return: the tag of the allocation """ return self.data.tag @@ -131,16 +127,15 @@ def totalCores(self): """Returns the total number of cores in the allocation. :rtype: float - :return: Total number of cores in the allocation + :return: total number of cores in the allocation """ return self.data.stats.cores def totalAvailableCores(self): - """Returns the total number of cores available for - booking in the allocation. + """Returns the total number of cores available for booking in the allocation. :rtype: float - :return: Total number of cores in the allocation + :return: total number of cores in the allocation """ return self.data.stats.available_cores @@ -148,26 +143,27 @@ def totalIdleCores(self): """Returns the total number of idle cores in the allocation. :rtype: float - :return: Total number of idle cores in the allocation + :return: total number of idle cores in the allocation """ return self.data.stats.idle_cores def totalRunningCores(self): """Returns the total number of running cores in the allocation. + Each 100 returned is the same as 1 physical core. :rtype: float - :return: Total number of running cores in the allocation + :return: total number of running cores in the allocation """ - # All core reserved return self.data.stats.running_cores def totalLockedCores(self): """Returns the total number of locked cores in the allocation. + Each 100 returned is the same as 1 physical core. :rtype: float - :return: Total number of locked cores in the allocation + :return: total number of locked cores in the allocation """ return self.data.stats.locked_cores @@ -175,7 +171,7 @@ def totalHosts(self): """Returns the total number of hosts in the allocation. :rtype: int - :return: Total number of hosts in the allocation + :return: total number of hosts in the allocation """ return self.data.stats.hosts @@ -183,13 +179,14 @@ def totalLockedHosts(self): """Returns the total number of locked hosts in the allocation. :rtype: int - :return: Total number of locked hosts in the allocation""" + :return: total number of locked hosts in the allocation + """ return self.data.stats.locked_hosts def totalDownHosts(self): """Returns the total number of down hosts in the allocation. :rtype: int - :return: Total number of down hosts in the allocation + :return: total number of down hosts in the allocation """ return self.data.stats.down_hosts diff --git a/pycue/opencue/wrappers/comment.py b/pycue/opencue/wrappers/comment.py index ad0dd53d6..e229ec283 100644 --- a/pycue/opencue/wrappers/comment.py +++ b/pycue/opencue/wrappers/comment.py @@ -12,14 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. - - -""" -Project: opencue - -Module: comment.py - comment object - -""" +"""Module for classes related to comments.""" from opencue.compiled_proto import comment_pb2 from opencue.cuebot import Cuebot @@ -33,52 +26,58 @@ def __init__(self, comment=None): self.stub = Cuebot.getStub('comment') def delete(self): - """Delete this comment""" - self.stub.Delete(comment_pb2.CommentDeleteRequest(comment=self.data), timeout=Cuebot.Timeout) + """Deletes this comment.""" + self.stub.Delete( + comment_pb2.CommentDeleteRequest(comment=self.data), timeout=Cuebot.Timeout) def save(self): - """Saves the current comment values""" + """Saves the current comment values.""" self.stub.Save(comment_pb2.CommentSaveRequest(comment=self.data), timeout=Cuebot.Timeout) def message(self): - """Message of the comment + """Returns the message of the comment. :rtype: str - :return: comment message""" + :return: comment message + """ return self.data.message def subject(self): - """Subject of the comment + """Returns the subject of the comment. :rtype: str - :return: comment subject""" + :return: comment subject + """ return self.data.subject def user(self): """Returns the username of the user who submitted the comment. :rtype: str - :return: Username of submitter""" + :return: username of the commenter + """ return self.data.user def timestamp(self): """Returns the timestamp for the comment as an epoch. :rtype: int - :return: The time the comment was submitted as an epoch""" + :return: the time the comment was submitted as an epoch + """ return self.data.timestamp def setMessage(self, message): - """Set a new message for the comment. + """Sets a new message for the comment. :type message: str - :param message: a new message""" + :param message: a new message + """ self.data.message = message def setSubject(self, subject): - """Set a new subject for the comment. + """Sets a new subject for the comment. :type subject: str - :param subject: a new subject""" + :param subject: a new subject + """ self.data.subject = subject - diff --git a/pycue/opencue/wrappers/deed.py b/pycue/opencue/wrappers/deed.py index dafb587c3..d29ec8854 100644 --- a/pycue/opencue/wrappers/deed.py +++ b/pycue/opencue/wrappers/deed.py @@ -12,45 +12,42 @@ # See the License for the specific language governing permissions and # limitations under the License. +"""Module for classes related to deeds.""" - -""" -Project: opencue - -Module: deed.py - deed object - -""" - -import opencue.wrappers.host from opencue.compiled_proto import host_pb2 from opencue.cuebot import Cuebot +# pylint: disable=cyclic-import +import opencue.wrappers.host +import opencue.wrappers.owner class Deed(object): """This class contains the grpc implementation related to a Deed.""" - def __init__(self, comment=None): - self.data = comment + def __init__(self, deed=None): + self.data = deed self.stub = Cuebot.getStub('comment') def delete(self): - """Delete this comment""" + """Deletes the deed.""" self.stub.Delete(host_pb2.DeedDeleteRequest(deed=self.data), timeout=Cuebot.Timeout) def getHost(self): - """Return the host for this deed. + """Returns the host for the deed. - :rtype: opencue.wrappers.host.Host Wrapper - :return: Host associated with this deed""" + :rtype: opencue.wrappers.host.Host + :return: deed host + """ return opencue.wrappers.host.Host( self.stub.GetHost(host_pb2.DeedGetHostRequest(deed=self.data), timeout=Cuebot.Timeout).host) def getOwner(self): - """Returns the owner for these settings. + """Returns the owner of the deed. - :rtype: opencue.wrappers.host.Host - :return: Owner of this deed""" + :rtype: opencue.wrappers.owner.Owner + :return: deed owner + """ return opencue.wrappers.owner.Owner( self.stub.GetOwner(host_pb2.DeedGetOwnerRequest(deed=self.data), timeout=Cuebot.Timeout).owner) @@ -58,43 +55,78 @@ def getOwner(self): def setBlackoutTime(self, startTime, stopTime): """Sets a blackout time for the host. - :type startTime: int - :param startTime: blackout start time - :type stopTime: int - :param stopTime: blackout stop time""" + :type startTime: int + :param startTime: blackout start time as an epoch + :type stopTime: int + :param stopTime: blackout stop time as an epoch + """ self.stub.SetBlackoutTime( - host_pb2.DeedSetBlackoutTimeRequest(deed=self.data, - start_time=startTime, - stop_time=stopTime), + host_pb2.DeedSetBlackoutTimeRequest( + deed=self.data, start_time=startTime, stop_time=stopTime), timeout=Cuebot.Timeout) def setBlackoutTimeEnabled(self, enabled): - """Enable/Disable blackout time without changing the times. + """Enable/disable the host blackout time without changing the times. - :type enabled: bool - :param enabled: enable/disable blackout time""" + :type enabled: bool + :param enabled: enable/disable blackout time + """ self.stub.SetBlackoutTimeEnabled( - host_pb2.DeedSetBlackoutTimeEnabledRequest(deed=self.data, - enabled=enabled), + host_pb2.DeedSetBlackoutTimeEnabledRequest(deed=self.data, enabled=enabled), timeout=Cuebot.Timeout) def id(self): + """Returns the id of the deed. + + :rtype: str + :return: deed id + """ return self.data.id def host(self): + """Returns the name of the host associated with the deed. + + :rtype: str + :return: name of the deed host + """ return self.data.host def owner(self): + """Returns the name of the owner of the deed. + + :rtype: str + :return: name of the deed owner + """ return self.data.owner def show(self): + """Returns the name of the show of the deed. + + :rtype: str + :return: name of the deed show + """ return self.data.show def blackout(self): + """Returns whether the blackout time is enabled. + + :rtype: bool + :return: whether the blackout is enabled + """ return self.data.blackout def blackoutStartTime(self): + """Returns the blackout start time as an epoch. + + :rtype: int + :return: blackout start time as an epoch + """ return self.data.blackout_start_time def blackoutStopTime(self): + """Returns the blackout end time as an epoch. + + :rtype: int + :return: blackout end time as an epoch + """ return self.data.blackout_stop_time diff --git a/pycue/opencue/wrappers/depend.py b/pycue/opencue/wrappers/depend.py index e4e9857e8..535589f5c 100644 --- a/pycue/opencue/wrappers/depend.py +++ b/pycue/opencue/wrappers/depend.py @@ -12,14 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. - - -""" -Project: opencue Library - -Module: depend.py - opencue Library implementation of a Depend -""" - +"""Module for classes related to dependencies.""" import enum @@ -31,6 +24,7 @@ class Depend(object): """This class contains the grpc implementation related to a Depend.""" class DependType(enum.IntEnum): + """Enum representing the type of dependency between subject and object.""" JOB_ON_JOB = depend_pb2.JOB_ON_JOB JOB_ON_LAYER = depend_pb2.JOB_ON_LAYER JOB_ON_FRAME = depend_pb2.JOB_ON_FRAME @@ -45,6 +39,7 @@ class DependType(enum.IntEnum): LAYER_ON_SIM_FRAME = depend_pb2.LAYER_ON_SIM_FRAME class DependTarget(enum.IntEnum): + """The type of target represented by this dependency.""" INTERNAL = depend_pb2.INTERNAL EXTERNAL = depend_pb2.EXTERNAL ANY_TARGET = depend_pb2.ANY_TARGET @@ -54,60 +49,116 @@ def __init__(self, depend=None): self.stub = Cuebot.getStub('depend') def satisfy(self): + """Satisfies the dependency. + + This sets any frames waiting on this dependency to the WAITING state. + """ self.stub.Satisfy( depend_pb2.DependSatisfyRequest(depend=self.data), timeout=Cuebot.Timeout) def unsatisfy(self): + """Unsatisfies the dependency. + + This makes the dependency active again and sets matching frames to DEPEND. + """ self.stub.Unsatisfy( depend_pb2.DependUnsatisfyRequest(depend=self.data), timeout=Cuebot.Timeout) def id(self): - """Returns the depdendency's unique id. Dependencies are one of the only - entities without a unique name so the unique ID is exposed to act - as the name. This is mainly to make command line tools easier to use. + """Returns the dependency's unique id. + + Dependencies are one of the only entities without a unique name so the unique ID is + exposed to act as the name. This is mainly to make command line tools easier to use. - :rtype: str - :return: the dependencies unique id""" + :rtype: str + :return: the dependency's unique id""" return self.data.id def isInternal(self): - """Returns true if the dependency is internal to the depender job, false if not. + """Returns whether the dependency is contained within a single job. - :rtype: bool - :returns: true""" + :rtype: bool + :return: whether the dependency is contained within a single job + """ if self.data.depend_er_job == self.data.depend_on_job: return True return False def type(self): + """Returns the type of dependency. + + :rtype: opencue.compiled_proto.depend_pb2.DependType + :return: dependency type + """ return self.data.type def target(self): - return self.data.target + """Returns the target of the dependency, either internal or external. - def chunkSize(self): - return self.data.chunk_size + :rtype: opencue.compiled_proto.depend_pb2.DependTarget + :return: dependency target type + """ + return self.data.target def anyFrame(self): + """Returns whether the depend is an any-frame depend. + + :rtype: bool + :return: whether the depend is an any-frame depend + """ return self.data.any_frame def isActive(self): + """Returns whether the depend is active. + + :rtype: bool + :return: whether the depend is active + """ return self.data.active def dependErJob(self): + """Returns the name of the job that is depending. + + :rtype: str + :return: name of the job that is depending""" return self.data.depend_er_job def dependErLayer(self): + """Returns the name of the layer that is depending. + + :rtype: str + :return: name of the layer that is depending + """ return self.data.depend_er_layer def dependErFrame(self): + """Returns the name of the frame that is depending. + + :rtype: str + :return: name of the frame that is depending + """ return self.data.depend_er_frame def dependOnJob(self): + """Returns the name of the job to depend on. + + :rtype: str + :return: name of the job to depend on + """ return self.data.depend_on_job def dependOnLayer(self): + """Returns the name of the layer to depend on. + + :rtype: str + :return: name of the layer to depend on + """ return self.data.depend_on_layer def dependOnFrame(self): + """Returns the name of the frame to depend on. + + :rtype: str + :return: name of the frame to depend on + """ return self.data.depend_on_frame diff --git a/pycue/opencue/wrappers/filter.py b/pycue/opencue/wrappers/filter.py index 81a6d109a..45e3949ca 100644 --- a/pycue/opencue/wrappers/filter.py +++ b/pycue/opencue/wrappers/filter.py @@ -12,15 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. - - -""" -Project: opencue Library - -Module: filter.py - opencue Library implementation of spank filter - -""" - +"""Classes for working with filters.""" import enum @@ -48,11 +40,12 @@ class Filter(object): """This class contains the grpc implementation related to a Filter.""" class FilterType(enum.IntEnum): + """The type of match used to determine if objects pass the filter.""" MATCH_ANY = filter_pb2.MATCH_ANY MATCH_ALL = filter_pb2.MATCH_ALL + # pylint: disable=redefined-builtin def __init__(self, filter=None): - """_Filter class initialization""" self.data = filter self.stub = Cuebot.getStub('filter') @@ -62,20 +55,21 @@ def __eq__(self, other): return self.data == other.data def delete(self): - """Deletes the filter""" + """Deletes the filter.""" self.stub.Delete(filter_pb2.FilterDeleteRequest(filter=self.data), timeout=Cuebot.Timeout) def createMatcher(self, subject, matchType, query): - """Creates a matcher for this filter + """Creates a matcher for the filter. :type subject: filter_pb2.MatchSubject.* - :param subject: The job attribute to match + :param subject: the job attribute to match :type matchType: filter_pb2.MatchType.* - :param matchType: The type of match to perform + :param matchType: the type of match to perform :type query: string - :param query: The value to match + :param query: the value to match :rtype: Matcher - :return: The new matcher object""" + :return: the new matcher object + """ matcher = MatcherData( subject=subject, type=matchType, @@ -86,14 +80,15 @@ def createMatcher(self, subject, matchType, query): timeout=Cuebot.Timeout).matcher) def createAction(self, actionType, value): - """Creates an action for this filter. + """Creates an action for the filter. :type actionType: filter_pb2.ActionType.* - :param actionType: The action to perform - :type value: Group or str, or int or bool - :param value: Value relevant to the type selected - :rtype: Action - :return: The new Action object""" + :param actionType: the action to perform + :type value: opencue.wrapper.group.Group / str / int / bool + :param value: value relevant to the type selected + :rtype: opencue.wrappers.filter.Action + :return: the new action + """ action = ActionData( type=actionType, group_value=None, @@ -126,48 +121,51 @@ def createAction(self, actionType, value): timeout=Cuebot.Timeout).action) def getActions(self): - """Returns the actions in this filter. + """Returns the filter actions. - :rtype: list - :return: A list of the actions in this filter""" + :rtype: list + :return: list of the filter actions + """ response = self.stub.GetActions(filter_pb2.FilterGetActionsRequest(filter=self.data), timeout=Cuebot.Timeout) return [Action(action) for action in response.actions.actions] def getMatchers(self): - """Returns the matchers in this filter. + """Returns the filter matchers. - :rtype: list - :return: A list of the matchers in this filter""" + :rtype: list + :return: list of the filter matchers + """ response = self.stub.GetMatchers(filter_pb2.FilterGetMatchersRequest(filter=self.data), timeout=Cuebot.Timeout) return [Matcher(matcher) for matcher in response.matchers.matchers] def lowerOrder(self): - """Lowers the order of this filter relative to the other filters""" + """Lowers the order of the filter relative to other filters.""" self.stub.LowerOrder(filter_pb2.FilterLowerOrderRequest(filter=self.data), timeout=Cuebot.Timeout) def raiseOrder(self): - """Raises the order of this filter relative to the other filters""" + """Raises the order of the filter relative to other filters.""" self.stub.RaiseOrder(filter_pb2.FilterRaiseOrderRequest(filter=self.data), timeout=Cuebot.Timeout) def orderFirst(self): - """Orders this filter above all the other filters""" + """Orders the filter above all other filters.""" self.stub.OrderFirst(filter_pb2.FilterOrderFirstRequest(filter=self.data), timeout=Cuebot.Timeout) def orderLast(self): - """Orders this filter below all the other filters""" + """Orders the filter below all other filters.""" self.stub.OrderLast(filter_pb2.FilterOrderLastRequest(filter=self.data), timeout=Cuebot.Timeout) def runFilterOnGroup(self, group): """Runs the filter on the group provided. - :type group: list - :param group: The group to run the filter on""" + :type group: opencue.wrapper.group.Group + :param group: group to run the filter on + """ self.stub.RunFilterOnGroup( filter_pb2.FilterRunFilterOnGroupRequest(filter=self.data, group=group.data), timeout=Cuebot.Timeout) @@ -176,7 +174,8 @@ def runFilterOnJobs(self, jobs): """Runs the filter on the list of jobs provided. :type jobs: list - :param jobs: The jobs to run the filter on""" + :param jobs: jobs to run the filter on + """ jobSeq = job_pb2.JobSeq(jobs=[job.data for job in jobs]) self.stub.RunFilterOnJobs( filter_pb2.FilterRunFilterOnJobsRequest(filter=self.data, jobs=jobSeq), @@ -186,47 +185,75 @@ def setEnabled(self, value): """Enables or disables the filter. :type value: bool - :param value: True to enable the filter and false to disable it""" + :param value: true to enable the filter and false to disable it + """ self.stub.SetEnabled(filter_pb2.FilterSetEnabledRequest(filter=self.data, enabled=value), timeout=Cuebot.Timeout) def setName(self, name): - """Sets the name of this filter. + """Sets the name of the filter. :type name: str - :param name: The new name for this filter""" + :param name: new filter name + """ self.stub.SetName(filter_pb2.FilterSetNameRequest(filter=self.data, name=name), timeout=Cuebot.Timeout) def setType(self, filterType): """Changes the filter type. - :type filterType: filter_pb2.FilterType - :param filterType: The new filter type""" + :type filterType: opencue.compiled_proto.filter_pb2.FilterType + :param filterType: the new filter type + """ self.stub.SetType(filter_pb2.FilterSetTypeRequest(filter=self.data, type=filterType), timeout=Cuebot.Timeout) def setOrder(self, order): + """Directly sets the order of the filter. + + :type order: int + :param order: the new filter order + """ self.stub.SetOrder(filter_pb2.FilterSetOrderRequest(filter=self.data, order=order), timeout=Cuebot.Timeout) def name(self): + """Returns the filter name. + + :rtype: str + :return: the filter name + """ return self.data.name def type(self): + """Returns the filter type. + + :rtype: opencue.compiled_proto.filter_pb2.FilterType + :return: the filter type + """ return self.data.type def order(self): + """Returns the current position of the filter. + + :rtype: float + :return: the current position of the filter""" return self.data.order def isEnabled(self): + """Returns whether the filter is enabled. + + :rtype: bool + :return: whether the filter is enabled + """ return self.data.enabled def id(self): """Returns the id of the filter. :rtype: str - :return: Filter uuid""" + :return: id of the filter + """ return self.data.id @@ -234,6 +261,7 @@ class Action(object): """This class contains the grpc implementation related to an Action.""" class ActionType(enum.IntEnum): + """Enum representing the type of Action to be performed.""" 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 @@ -246,6 +274,7 @@ class ActionType(enum.IntEnum): SET_MEMORY_OPTIMIZER = filter_pb2.SET_MEMORY_OPTIMIZER class ActionValueType(enum.IntEnum): + """Enum representing the type of the action's object.""" GROUP_TYPE = filter_pb2.GROUP_TYPE STRING_TYPE = filter_pb2.STRING_TYPE INTEGER_TYPE = filter_pb2.INTEGER_TYPE @@ -258,49 +287,89 @@ def __init__(self, action=None): self.stub = Cuebot.getStub('action') def getParentFilter(self): + """Returns the filter the action belongs to. + + :rtype: opencue.wrappers.filter.Filter + :return: the filter the action belongs to + """ response = self.stub.GetParentFilter( filter_pb2.ActionGetParentFilterRequest(action=self.data), - timeout=Cuebot.Timeout - ) + timeout=Cuebot.Timeout) return Filter(response.filter) def delete(self): + """Deletes the action.""" self.stub.Delete(filter_pb2.ActionDeleteRequest(action=self.data), timeout=Cuebot.Timeout) def commit(self): + """Commits any changes to the action to the database.""" if self.isNew(): raise Exception( "unable to commit action that has not been created, proxy does not exist") self.stub.Commit(filter_pb2.ActionCommitRequest(action=self.data), timeout=Cuebot.Timeout) def isNew(self): + """Returns whether the action has been initialized yet. + + :rtype: bool + :return: True if the action has been initialized with data from the database + """ return self.data is None def name(self): + """Returns the name of the action. + + :rtype: str + :return: name of the action + """ if self.value() is None: return "%s" % ActionType.Name(self.type()) - else: - return "%s %s" % (ActionType.Name(self.type()), self.value()) + return "%s %s" % (ActionType.Name(self.type()), self.value()) def value(self): + """Returns the value of the action; what will happen if the filter is matched. + + Type of value returned depends on the action's value_type. + + :rtype: str/int/float/bool + :return: value of the action + """ valueType = self.data.value_type if valueType == filter_pb2.GROUP_TYPE: return self.data.group_value - elif valueType == filter_pb2.STRING_TYPE: + if valueType == filter_pb2.STRING_TYPE: return self.data.string_value - elif valueType == filter_pb2.INTEGER_TYPE: + if valueType == filter_pb2.INTEGER_TYPE: return self.data.integer_value - elif valueType == filter_pb2.FLOAT_TYPE: + if valueType == filter_pb2.FLOAT_TYPE: return self.data.float_value - elif valueType == filter_pb2.BOOLEAN_TYPE: + if valueType == filter_pb2.BOOLEAN_TYPE: return self.data.boolean_value - else: - return None + return None def type(self): + """Returns the type of the action. + + An action's type determines what will happen if the action is triggered by its filter. + For example, if the type is GROUP_TYPE, the object which has triggered the filter will + be assigned to the group specified by the action's value. + + :rtype: filter_pb2.ActionValueType + :return: the type of the action + """ return self.data.type def setTypeAndValue(self, actionType, value): + """Sets a new type and value for the action. + + These fields should be set together as the value can be only be properly validated and + stored in the correct database field if the type is also known. + + :type actionType: filter_pb2.ActionValueType + :param actionType: the new type of the action + :type value: str/int/float/bool + :param value: the new value of the action + """ self.data.type = actionType if actionType == filter_pb2.MOVE_JOB_TO_GROUP: if not isinstance(value, job_pb2.Group): @@ -333,7 +402,7 @@ def setTypeAndValue(self, actionType, value): self.data.value_type = filter_pb2.NONE_TYPE else: - raise Exception("invalid action type: %s" % actionType) + raise Exception("invalid action type: %s" % actionType) self.commit() @@ -341,14 +410,20 @@ def id(self): """Returns the id of the action. :rtype: str - :return: Action uuid""" + :return: id of the action + """ return self.data.id class Matcher(object): - """This class contains the grpc implementation related to a Matcher.""" + """This class contains the grpc implementation related to a Matcher. + + Matchers belong to a single filter, and indicate the conditions where a given object will + satisfy that filter, i.e. if it will trigger the actions in that filter. + """ class MatchSubject(enum.IntEnum): + """Enum representing the type of the subject; the thing being matched.""" JOB_NAME = filter_pb2.JOB_NAME SHOW = filter_pb2.SHOW SHOT = filter_pb2.SHOT @@ -359,6 +434,7 @@ class MatchSubject(enum.IntEnum): LAYER_NAME = filter_pb2.LAYER_NAME class MatchType(enum.IntEnum): + """Enum representing the type of matching that will occur.""" CONTAINS = filter_pb2.CONTAINS DOES_NOT_CONTAIN = filter_pb2.DOES_NOT_CONTAIN IS = filter_pb2.IS @@ -372,16 +448,22 @@ def __init__(self, matcher=None): self.stub = Cuebot.getStub('matcher') def getParentFilter(self): + """Returns the filter the matcher belongs to. + + :rtype: opencue.wrappers.filter.Filter + :return: the filter the matcher belongs to + """ response = self.stub.GetParentFilter( filter_pb2.MatcherGetParentFilterRequest(matcher=self.data), - timeout=Cuebot.Timeout - ) + timeout=Cuebot.Timeout) return Filter(response.filter) def delete(self): + """Deletes the matcher.""" self.stub.Delete(filter_pb2.MatcherDeleteRequest(matcher=self.data), timeout=Cuebot.Timeout) def commit(self): + """Commits any changes to the matcher to the database.""" if self.isNew(): raise Exception( "unable to commit matcher that has not been created, proxy does not exist") @@ -389,36 +471,78 @@ def commit(self): self.stub.Commit(filter_pb2.MatcherCommitRequest(matcher=self.data), timeout=Cuebot.Timeout) def isNew(self): + """Returns whether the matcher has been initialized yet with data from the database. + + :rtype: bool + :return: True if the matcher has been initialized + """ return self.data is None def name(self): - return "%s %s %s" % (MatchSubject.Name(self.data.subject), MatchType.Name(self.data.type), self.data.input) + """Returns the name of the matcher. + + :rtype: str + :return: the name of the matcher + """ + return "%s %s %s" % ( + MatchSubject.Name(self.data.subject), MatchType.Name(self.data.type), self.data.input) def subject(self): + """Returns the subject of the matcher; the type of object to be matched. + + :rtype: filter_pb2.MatchSubject + :return: the subject of the matcher + """ return self.data.subject def type(self): + """Returns the type of the matcher; the kind of comparison used to determine a match. + + :rtype: filter_pb2.MatchType + :return: the type of the matcher + """ return self.data.type def input(self): + """Returns the input data of the matcher; the value to be matched against. + + :rtype: str + :return: input data of the matcher + """ return self.data.input def id(self): """Returns the id of the matcher. :rtype: str - :return: Matcher uuid""" + :return: id of the matcher + """ return self.data.id def setSubject(self, value): + """Sets a new subject for the matcher. + + :type value: str + :param value: new subject for the matcher + """ self.data.subject = value self.commit() def setType(self, value): + """Sets a new type for the matcher. + + :type value: filter_pb2.MatchType + :param value: new type for the matcher + """ self.data.type = value self.commit() def setInput(self, value): + """Set new input data for the matcher. + + :type value: str + :param value: new input data for the matcher + """ value = value.replace(" ", "") self.data.input = str(value) self.commit() diff --git a/pycue/opencue/wrappers/frame.py b/pycue/opencue/wrappers/frame.py index 3b79bed65..0455cbd7c 100644 --- a/pycue/opencue/wrappers/frame.py +++ b/pycue/opencue/wrappers/frame.py @@ -12,13 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. - -""" -Project: opencue Library - -Module: frame.py - opencue Library implementation of a frame -""" - +"""Module for classes related to frames.""" import enum import time @@ -33,17 +27,20 @@ class Frame(object): """This class contains the grpc implementation related to a Frame.""" class CheckpointState(enum.IntEnum): + """Possible states for a frame's checkpointing status, if it uses that.""" DISABLED = job_pb2.DISABLED ENABLED = job_pb2.ENABLED COPYING = job_pb2.COPYING COMPLETE = job_pb2.COMPLETE class FrameExitStatus(enum.IntEnum): + """Possible frame exit statuses.""" SUCCESS = job_pb2.SUCCESS NO_RETRY = job_pb2.NO_RETRY SKIP_RETRY = job_pb2.SKIP_RETRY class FrameState(enum.IntEnum): + """Possible frame states.""" WAITING = job_pb2.WAITING SETUP = job_pb2.SETUP RUNNING = job_pb2.RUNNING @@ -54,52 +51,54 @@ class FrameState(enum.IntEnum): CHECKPOINT = job_pb2.CHECKPOINT def __init__(self, frame=None): - """_Frame class initialization""" self.data = frame self.stub = Cuebot.getStub('frame') def eat(self): - """Eat frame""" + """Eats the frame.""" if self.data.state != job_pb2.FrameState.Value('EATEN'): self.stub.Eat(job_pb2.FrameEatRequest(frame=self.data), timeout=Cuebot.Timeout) def kill(self): - """Kill frame""" + """Kills the frame.""" if self.data.state == job_pb2.FrameState.Value('RUNNING'): self.stub.Kill(job_pb2.FrameKillRequest(frame=self.data), timeout=Cuebot.Timeout) def retry(self): - """Retry frame""" + """Retries the frame.""" if self.data.state != job_pb2.FrameState.Value('WAITING'): self.stub.Retry(job_pb2.FrameRetryRequest(frame=self.data), timeout=Cuebot.Timeout) def addRenderPartition(self, hostname, threads, max_cores, num_mem, max_gpu): - """Add a render partition to the frame. - @type hostname: str - @param hostname: hostname of the partition - @type threads: int - @param threads: number of threads of the partition - @type max_cores: int - @param max_cores: max cores enabled for the partition - @type num_mem: int - @param num_mem: amount of memory reserved for the partition - @type max_gpu: int - @param max_gpu: max gpu cores enabled for the partition + """Adds a render partition to the frame. + + :type hostname: str + :param hostname: hostname of the partition + :type threads: int + :param threads: number of threads of the partition + :type max_cores: int + :param max_cores: max cores enabled for the partition + :type num_mem: int + :param num_mem: amount of memory reserved for the partition + :type max_gpu: int + :param max_gpu: max gpu cores enabled for the partition """ - response = self.stub.AddRenderPartition( - job_pb2.FrameAddRenderPartitionRequest(frame=self.data, - host=hostname, - threads=threads, - max_cores=max_cores, - max_memory=num_mem, - max_gpu=max_gpu, - username=os.getenv("USER", "unknown"))) + self.stub.AddRenderPartition( + job_pb2.FrameAddRenderPartitionRequest( + frame=self.data, + host=hostname, + threads=threads, + max_cores=max_cores, + max_memory=num_mem, + max_gpu=max_gpu, + username=os.getenv("USER", "unknown"))) def getWhatDependsOnThis(self): """Returns a list of dependencies that depend directly on this frame. - :rtype: list - :return: List of dependencies that depend directly on this frame""" + :rtype: list + :return: list of dependencies that depend directly on this frame + """ response = self.stub.GetWhatDependsOnThis( job_pb2.FrameGetWhatDependsOnThisRequest(frame=self.data), timeout=Cuebot.Timeout) @@ -108,44 +107,48 @@ def getWhatDependsOnThis(self): def getWhatThisDependsOn(self): """Returns a list of dependencies that this frame depends on. - :rtype: list - :return: List of dependencies that this frame depends on""" + :rtype: list + :return: list of dependencies that this frame depends on + """ response = self.stub.GetWhatThisDependsOn( job_pb2.FrameGetWhatThisDependsOnRequest(frame=self.data), timeout=Cuebot.Timeout) return [opencue.wrappers.depend.Depend(dep) for dep in response.depends.depends] def createDependencyOnJob(self, job): - """Create and return a frame on job dependency. + """Creates and returns a frame-on-job dependency. :type job: opencue.wrappers.job.Job :param job: the job you want this frame to depend on :rtype: opencue.wrappers.depend.Depend - :return: The new dependency""" + :return: The new dependency + """ response = self.stub.CreateDependencyOnJob( job_pb2.FrameCreateDependencyOnJobRequest(frame=self.data, job=job.data), timeout=Cuebot.Timeout) return opencue.wrappers.depend.Depend(response.depend) def createDependencyOnLayer(self, layer): - """Create and return a frame on layer dependency. + """Creates and returns a frame-on-layer dependency. - :type layer: opencue.wrappers.layer.Layer + :type layer: opencue.wrappers.layer.Layer :param layer: the layer you want this frame to depend on :rtype: opencue.wrappers.depend.Depend - :return: The new dependency""" + :return: the new dependency + """ response = self.stub.CreateDependencyOnLayer( job_pb2.FrameCreateDependencyOnLayerRequest(frame=self.data, layer=layer.data), timeout=Cuebot.Timeout) return opencue.wrappers.depend.Depend(response.depend) def createDependencyOnFrame(self, frame): - """Create and return a frame on frame dependency. + """Creates and returns a frame-on-frame dependency. - :type frame: opencue.wrappers.frame.Frame + :type frame: opencue.wrappers.frame.Frame :param frame: the frame you want this frame to depend on :rtype: opencue.wrappers.depend.Depend - :return: The new dependency""" + :return: the new dependency + """ response = self.stub.CreateDependencyOnFrame( job_pb2.FrameCreateDependencyOnFrameRequest(frame=self.data, depend_on_frame=frame.data), @@ -159,134 +162,153 @@ def dropDepends(self, target): timeout=Cuebot.Timeout) def markAsWaiting(self): - """Mark the frame as waiting, similar to drop depends. The frame will be - able to run even if the job has an external dependency.""" + """Marks the frame as waiting; ready to run. + + Similar to dropDepends. The frame will be able to run even if the job has an external + dependency.""" self.stub.MarkAsWaiting( job_pb2.FrameMarkAsWaitingRequest(frame=self.data), timeout=Cuebot.Timeout) def setCheckpointState(self, checkPointState): - """Sets the checkPointState of the frame - :param checkPointState: job_pb.CheckpointState(Int) - :return: + """Sets the checkPointState of the frame. + + :type checkPointState: job_pb.CheckpointState + :param checkPointState: the checkpoint state of the frame """ self.stub.SetCheckpointState( - job_pb2.FrameSetCheckpointStateRequest(frame=self.data, state=checkPointState) - ) + job_pb2.FrameSetCheckpointStateRequest(frame=self.data, state=checkPointState)) def id(self): """Returns the id of the frame. + :rtype: str - :return: Frame uuid""" + :return: id of the frame + """ return self.data.id def name(self): """Returns the name of the frame. + :rtype: str - :return: Frame name""" + :return: name of the frame + """ return "%04d-%s" % (self.data.number, self.data.layer_name) def layer(self): """Returns the name of the layer name that the frame belongs to. :rtype: str - :return: Layer name""" + :return: name of the layer + """ return self.data.layer_name def frame(self): - """Returns the frames number as a padded string. + """Returns the frame number as a padded string. :rtype: str - :return: Frame number string""" + :return: frame number padded to 4 digits + """ return "%04d" % self.data.number def number(self): - """Returns the frames number. + """Returns the frame number, unpadded. :rtype: int - :return: Frame number""" + :return: frame number + """ return self.data.number def dispatchOrder(self): - """Returns the frames dispatch order. + """Returns the frame's dispatch order. :rtype: int - :return: Frame dispatch order""" + :return: frame dispatch order + """ return self.data.dispatch_order def startTime(self): """Returns the epoch timestamp of the frame's start time. :rtype: int - :return: Job start time in epoch""" + :return: frame start time as an epoch + """ return self.data.start_time def stopTime(self): """Returns the epoch timestamp of the frame's stop time. :rtype: int - :return: Frame stop time in epoch""" + :return: frame stop time as an epoch + """ return self.data.stop_time def resource(self): """Returns the most recent resource that the frame has started running on. + Ex: vrack999/1.0 = host/proc:cores :rtype: str - :return: Most recent running resource""" + :return: most recent running resource + """ return self.data.last_resource def retries(self): - """Returns the number of retries. + """Returns the number of times the frame has been retried. :rtype: int - :return: Number of retries""" + :return: number of retries + """ return self.data.retry_count def exitStatus(self): - """Returns the frame's exitStatus. + """Returns the frame's exit status. :rtype: int - :return: Frames last exit status""" + :return: last exit status of the frame + """ return self.data.exit_status def maxRss(self): """Returns the frame's maxRss. :rtype: long - :return: Max RSS in Kb""" + :return: max RSS in Kb + """ return self.data.max_rss def memUsed(self): """Returns the frame's currently used memory. :rtype: long - :return: Current used memory in Kb""" + :return: currently used memory in Kb + """ return self.data.used_memory def memReserved(self): """Returns the frame's currently reserved memory. :rtype: long - :return: Current used memory in Kb""" + :return: currently reserved memory in Kb + """ return self.data.reserved_memory def state(self): # call it status? """Returns the state of the frame. - :rtype: opencue.FrameState - :return: Frame state""" + :rtype: job_pb2.FrameState + :return: state of the frame + """ return self.data.state def runTime(self): """Returns the number of seconds that the frame has been (or was) running. :rtype: int - :return: Job runtime in seconds""" + :return: frame runtime in seconds + """ if self.data.start_time == 0: return 0 if self.data.stop_time == 0: return int(time.time() - self.data.start_time) - else: - return self.data.stop_time - self.data.start_time - + return self.data.stop_time - self.data.start_time diff --git a/pycue/opencue/wrappers/group.py b/pycue/opencue/wrappers/group.py index 1b02947ae..59685cc8b 100644 --- a/pycue/opencue/wrappers/group.py +++ b/pycue/opencue/wrappers/group.py @@ -12,11 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. - -""" -opencue group module -""" - +"""Modules for classes related to groups.""" from opencue import Cuebot from opencue.compiled_proto import job_pb2 @@ -31,41 +27,82 @@ def __init__(self, group=None): self.stub = Cuebot.getStub('group') def createSubGroup(self, name): + """Creates a subgroup under this group. + + :type name: str + :param name: name of the new subgroup + """ return Group(self.stub.CreateSubGroup( job_pb2.GroupCreateSubGroupRequest(group=self.data, name=name), timeout=Cuebot.Timeout).group) def delete(self): + """Deletes the group.""" self.stub.Delete(job_pb2.GroupDeleteRequest(group=self.data), timeout=Cuebot.Timeout) def setName(self, name): + """Sets the name of the group. + + :type name: str + :param name: new name for the group + """ self.stub.SetName(job_pb2.GroupSetNameRequest(group=self.data, name=name), timeout=Cuebot.Timeout) def setMaxCores(self, value): + """Sets the maximum cores of everything in the group. + + :type value: int + :param value: new maximum number of cores + """ self.stub.SetMaxCores(job_pb2.GroupSetMaxCoresRequest(group=self.data, max_cores=value), timeout=Cuebot.Timeout) def setMinCores(self, value): + """Sets the minimum cores of everything the group. + + :type value: int + :param value: new minimum number of cores + """ self.stub.SetMinCores(job_pb2.GroupSetMinCoresRequest(group=self.data, min_cores=value), timeout=Cuebot.Timeout) def setDefaultJobPriority(self, value): + """Sets the default job priority for everything in the group. + + :type value: int + :param value: new default priority + """ self.stub.SetDefaultJobPriority( job_pb2.GroupSetDefJobPriorityRequest(group=self.data, priority=value), timeout=Cuebot.Timeout) def setDefaultJobMinCores(self, value): + """Sets the default job minimum cores for everything in the group. + + :type value: int + :param value: new default job minimum cores + """ self.stub.SetDefaultJobMinCores( job_pb2.GroupSetDefJobMinCoresRequest(group=self.data, min_cores=value), timeout=Cuebot.Timeout) def setDefaultJobMaxCores(self, value): + """Sets the default job maximum cores for everything in the group. + + :type value: int + :param value: new default job maximum cores + """ self.stub.SetDefaultJobMaxCores( job_pb2.GroupSetDefJobMaxCoresRequest(group=self.data, max_cores=value), timeout=Cuebot.Timeout) def getGroups(self): + """Returns child groups of this group. + + :rtype: list + :return: list of child groups + """ response = self.stub.GetGroups(job_pb2.GroupGetGroupsRequest(group=self.data), timeout=Cuebot.Timeout) return [Group(g) for g in response.groups.groups] @@ -74,7 +111,8 @@ def getJobs(self): """Returns the jobs in this group. :rtype: list - :return: List of jobs in this group""" + :return: list of jobs in this group + """ response = self.stub.GetJobs(job_pb2.GroupGetJobsRequest(group=self.data), timeout=Cuebot.Timeout) return [opencue.wrappers.job.Job(j) for j in response.jobs.jobs] @@ -83,7 +121,8 @@ def reparentJobs(self, jobs): """Moves the given jobs into this group. :type jobs: list - :param jobs: The jobs to add to this group""" + :param jobs: The jobs to add to this group + """ jobsToReparent = [] for job in jobs: if isinstance(job, opencue.wrappers.job.NestedJob): @@ -94,10 +133,11 @@ def reparentJobs(self, jobs): timeout=Cuebot.Timeout) def reparentGroups(self, groups): - """Moves the given groups into this group. + """Moves the given groups to be subgroups of this group. :type groups: list - :param groups: The groups to move into""" + :param groups: the groups to make subgroups of this group + """ groupSeq = job_pb2.GroupSeq(groups=[group.data for group in groups]) self.stub.ReparentGroups( job_pb2.GroupReparentGroupsRequest(group=self.data, groups=groupSeq), @@ -106,95 +146,136 @@ def reparentGroups(self, groups): def reparentGroupIds(self, groupIds): """Moves the given group ids into this group. - :type groups: list - :param groups: The group ids to move into""" - groups = [opencue.wrappers.group.Group(job_pb2.Group(id=groupId)) for groupId in groupIds] + :type groupIds: list + :param groupIds: The group ids to make subgroups of this group + """ + groups = [Group(job_pb2.Group(id=groupId)) for groupId in groupIds] self.reparentGroups(groups) def setDepartment(self, name): - """Sets the group's department to the specified name. The department - name must be one of the allowed department names. All jobs in the group - will inherit the new department name. See AdminStatic for getting a list - of allowed department names. Department names are maintained by the - middle-tier group. - - :type name: string - :param name: a valid department name""" + """Sets the group's department to the specified name. + + The department name must be one of the allowed department names. All jobs in the group + will inherit the new department name. + + :type name: string + :param name: a valid department name + """ self.stub.SetDepartment(job_pb2.GroupSetDeptRequest(group=self.data, dept=name), timeout=Cuebot.Timeout) self.data.department = name def setGroup(self, parentGroup): - """Sets this group's parent to parentGroup. + """Sets this group's parent. :type parentGroup: opencue.wrappers.group.Group - :param parentGroup: Group to parent under""" - self.stub.SetGroup(job_pb2.GroupSetGroupRequest(group=self.data, - parent_group=parentGroup.data), - timeout=Cuebot.Timeout) + :param parentGroup: group to parent under + """ + self.stub.SetGroup( + job_pb2.GroupSetGroupRequest(group=self.data, parent_group=parentGroup.data), + timeout=Cuebot.Timeout) def id(self): """Returns the id of the group. :rtype: str - :return: Group uuid""" + :return: id of the group + """ return self.data.id def name(self): + """Returns the name of the group. + + :rtype: str + :return: name of the group""" return self.data.name def department(self): + """Returns the department of the group. + + :rtype: str + :return: department of the group + """ return self.data.department def defaultJobPriority(self): + """Returns the default job priority of the group. + + :rtype: int + :return: default job priority of the group + """ return self.data.default_job_priority def defaultJobMinCores(self): + """Returns the default job minimum cores of the group. + + :rtype: float + :return: default job min cores + """ return self.data.default_job_min_cores def defaultJobMaxCores(self): + """Returns the default job maximum cores of the group. + + :rtype: float + :return: default job max cores + """ return self.data.default_job_max_cores def maxCores(self): + """Returns the maximum cores of the group. + + :rtype: float + :return: max cores of the group + """ return self.data.max_cores def minCores(self): + """Returns the minimum cores of the group. + + :rtype: float + :return: min cores of the group + """ return self.data.min_cores def reservedCores(self): """Returns the total number of reserved cores for the group. - :rtype: int - :return: total numnber of frames""" + :rtype: float + :return: total number of reserved cores + """ return self.data.group_stats.reserved_cores def totalRunning(self): - """Returns the total number of running frames under this object. + """Returns the total number of running frames under this group. :rtype: int - :return: Total number of running frames""" + :return: total number of running frames + """ return self.data.group_stats.running_frames def totalDead(self): - """Returns the total number of deads frames under this object. + """Returns the total number of dead frames under this group. :rtype: int - :return: Total number of dead frames""" + :return: total number of dead frames + """ return self.data.group_stats.dead_frames def totalPending(self): - """Returns the total number of pending (dependent and waiting) frames - under this object. + """Returns the total number of pending (dependent and waiting) frames under this group. :rtype: int - :return: Total number of pending (dependent and waiting) frames""" + :return: total number of pending (dependent and waiting) frames + """ return self.data.group_stats.pending_frames def pendingJobs(self): """Returns the total number of running jobs. :rtype: int - :return: total number of running jobs""" + :return: total number of running jobs + """ return self.data.group_stats.pending_jobs @@ -207,19 +288,31 @@ def __init__(self, group): self.__children_init = False def createSubGroup(self, name): - """Create a sub group""" + """Creates a subgroup under this nested group. + + :type name: str + :param name: name of the new subgroup + """ return self.asGroup().createSubGroup(name) def children(self): - """returns jobs and groups in a single array""" + """Returns this group's jobs and child groups in a single array. + + :rtype: list + :return: list of all jobs and child groups in this group + """ if not self.__children_init: - self.__children.extend(self.groups) - self.__children.extend(self.jobs) + self.__children.extend(self.data.groups) + self.__children.extend(self.data.jobs) self.__children_init = True return self.__children def asGroup(self): - """returns a Group object from this NestedGroup""" + """Returns a Group object from this NestedGroup. + + :rtype: opencue.wrappers.group.Group + :return: Group version of this NestedGroup + """ return Group(job_pb2.Group( id=self.data.id, name=self.data.name, @@ -236,7 +329,7 @@ def asGroup(self): def hasParent(self): """Whether this NestedGroup has a parent group. - :rtype: bool + :rtype: bool :return: whether the group has a parent group. """ return self.data.HasField('parent') diff --git a/pycue/opencue/wrappers/host.py b/pycue/opencue/wrappers/host.py index 50128f35a..83dac252f 100644 --- a/pycue/opencue/wrappers/host.py +++ b/pycue/opencue/wrappers/host.py @@ -12,14 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. - -""" -Project: opencue Library - -Module: host.py - opencue Library implementation of a host - -""" - +"""Module for classes related to hosts.""" import enum import os @@ -29,6 +22,7 @@ from opencue.compiled_proto import comment_pb2 from opencue.compiled_proto import host_pb2 import opencue.wrappers.comment +# pylint: disable=cyclic-import import opencue.wrappers.proc @@ -36,6 +30,7 @@ class Host(object): """This class contains the grpc implementation related to a Host.""" class HardwareState(enum.IntEnum): + """Enum representing the hardware state of the host.""" UP = host_pb2.UP DOWN = host_pb2.DOWN REBOOTING = host_pb2.REBOOTING @@ -43,23 +38,25 @@ class HardwareState(enum.IntEnum): REPAIR = host_pb2.REPAIR class HostTagType(enum.IntEnum): + """Enum representing the type of a host tag.""" MANUAL = host_pb2.MANUAL HARDWARE = host_pb2.HARDWARE ALLOC = host_pb2.ALLOC HOSTNAME = host_pb2.HOSTNAME class LockState(enum.IntEnum): + """Enum representing whether the host is locked.""" OPEN = host_pb2.OPEN LOCKED = host_pb2.LOCKED NIMBY_LOCKED = host_pb2.NIMBY_LOCKED class ThreadMode(enum.IntEnum): + """Enum representing the thread mode of the host.""" AUTO = host_pb2.AUTO ALL = host_pb2.ALL VARIABLE = host_pb2.VARIABLE def __init__(self, host=None): - """Host class initialization""" self.data = host self.__id = host.id self.stub = Cuebot.getStub('host') @@ -69,13 +66,13 @@ def lock(self): self.stub.Lock(host_pb2.HostLockRequest(host=self.data), timeout=Cuebot.Timeout) def unlock(self): - """Unlocks the host and cancels any actions that were waiting for all - running frames to finish. - """ + """Unlocks the host. + + Cancels any actions that were waiting for all running frames to finish.""" self.stub.Unlock(host_pb2.HostUnlockRequest(host=self.data), timeout=Cuebot.Timeout) def delete(self): - """Delete the host from the cuebot""" + """Deletes the host from the cuebot""" self.stub.Delete(host_pb2.HostDeleteRequest(host=self.data), timeout=Cuebot.Timeout) def getProcs(self): @@ -103,8 +100,8 @@ def redirectToJob(self, procs, job): def getRenderPartitions(self): """Returns a list of render partitions associated with this host - :rtype: list - :return: A list of render partitions under this host + :rtype: list + :return: list of render partitions under this host """ response = self.stub.GetRenderPartitions(host_pb2.HostGetRenderPartitionsRequest( host=self.data), timeout=Cuebot.Timeout) @@ -112,9 +109,9 @@ def getRenderPartitions(self): return partitionSeq.render_partitions def rebootWhenIdle(self): - """Causes the host to no longer accept new frames and - when the machine is idle it will reboot. - """ + """Sets the machine to reboot once idle. + + The host will no longer accept new frames.""" self.stub.RebootWhenIdle(host_pb2.HostRebootWhenIdleRequest(host=self.data), timeout=Cuebot.Timeout) @@ -125,16 +122,16 @@ def reboot(self): def addTags(self, tags): """Adds tags to a host. - :type tags: list + :type tags: list :param tags: The tags to add """ self.stub.AddTags(host_pb2.HostAddTagsRequest(host=self.data, tags=tags), timeout=Cuebot.Timeout) def removeTags(self, tags): - """Remove tags from this host. + """Removes tags from this host. - :type tags: list + :type tags: list :param tags: The tags to remove """ self.stub.RemoveTags(host_pb2.HostRemoveTagsRequest(host=self.data, tags=tags), @@ -143,10 +140,10 @@ def removeTags(self, tags): def renameTag(self, oldTag, newTag): """Renames a tag. - :type oldTag: str - :param oldTag: The old tag to rename - :type newTag: str - :param newTag: The new name for the tag + :type oldTag: str + :param oldTag: old tag to rename + :type newTag: str + :param newTag: new name for the tag """ self.stub.RenameTag( host_pb2.HostRenameTagRequest(host=self.data, old_tag=oldTag, new_tag=newTag), @@ -155,19 +152,19 @@ def renameTag(self, oldTag, newTag): def setAllocation(self, allocation): """Sets the host to the given allocation. - :type allocation: opencue.wrappers.allocation.Allocation - :param allocation: An allocation object + :type allocation: opencue.wrappers.allocation.Allocation + :param allocation: allocation to put the host under """ self.stub.SetAllocation( host_pb2.HostSetAllocationRequest(host=self.data, allocation_id=allocation.id()), timeout=Cuebot.Timeout) def addComment(self, subject, message): - """Appends a comment to the hosts's comment list. + """Appends a comment to the host's comment list. - :type subject: str + :type subject: str :param subject: Subject data - :type message: str + :type message: str :param message: Message data """ comment = comment_pb2.Comment( @@ -180,32 +177,39 @@ def addComment(self, subject, message): timeout=Cuebot.Timeout) def getComments(self): - """returns the hosts comments""" + """Returns the host's comment list. + + :rtype: list + :return: the comment list of the host + """ response = self.stub.GetComments(host_pb2.HostGetCommentsRequest(host=self.data), timeout=Cuebot.Timeout) commentSeq = response.comments return [opencue.wrappers.comment.Comment(c) for c in commentSeq.comments] def setHardwareState(self, state): - """Sets the host's hardware state + """Sets the host hardware state. - :type state: host_pb2.HardwareState - :param state: state to set host to""" + :type state: host_pb2.HardwareState + :param state: state to set host to + """ self.stub.SetHardwareState( host_pb2.HostSetHardwareStateRequest(host=self.data, state=state), timeout=Cuebot.Timeout) def setOs(self, osName): """Sets the host operating system. - :type osName: string - :param osName: os value to set host to""" + + :type osName: string + :param osName: os value to set host to + """ self.stub.SetOs(host_pb2.HostSetOsRequest(host=self.data, os=osName), timeout=Cuebot.Timeout) def setThreadMode(self, mode): - """Set the thread mode to mode. + """Sets the host thread mode. - :type mode: host_pb2.ThreadMode + :type mode: host_pb2.ThreadMode :param mode: ThreadMode to set host to """ self.stub.SetThreadMode(host_pb2.HostSetThreadModeRequest(host=self.data, mode=mode), @@ -214,8 +218,8 @@ def setThreadMode(self, mode): def id(self): """Returns the id of the host. - :rtype: str - :return: Host uuid + :rtype: str + :return: id of the host """ if not hasattr(self, "__id"): self.__id = self.data.id @@ -224,23 +228,23 @@ def id(self): def name(self): """Returns the name of the host. - :rtype: str - :return: Host name + :rtype: str + :return: name of the host """ return self.data.name def isNimbyEnabled(self): """Returns true if nimby is enabled. - :rtype: bool + :rtype: bool :return: True if nimby is enabled """ return self.data.nimby_enabled def isUp(self): - """Returns True if the host is up. + """Returns True if the host hardware state indicates the machine is up. - :rtype: bool + :rtype: bool :return: True if the host is up """ return self.data.state == host_pb2.HardwareState.Value('UP') @@ -248,169 +252,191 @@ def isUp(self): def isLocked(self): """Returns True if the host is locked. - :rtype: bool + :rtype: bool :return: True if the host is locked """ return self.data.lock_state == host_pb2.LockState.Value('LOCKED') def isCommented(self): """Returns true if the host has a comment. - - :rtype: bool - :return: If the job has a comment + + :rtype: bool + :return: whether the host has a comment """ return self.data.has_comment def cores(self): - """ + """Returns the total number of cores the host has. + :rtype: float - :return: number of cores + :return: total number of host cores """ return self.data.cores def coresReserved(self): - """ + """Returns the number of cores the host has which are currently reserved. + :rtype: float :return: number of cores reserved """ return self.data.cores - self.data.idle_ores def coresIdle(self): - """ + """Returns the number of cores the host currently has idel. + :rtype: float :return: number of cores idle """ return self.data.idle_cores def mem(self): - """ - :rtype: int - :return: value of memory + """Returns the amount of memory the host has in kb. + + :rtype: int + :return: amount of memory in kb """ return self.data.memory def memReserved(self): - """ - :rtype: int - :return: value of memory reserved + """Returns the amount of memory the host has currently reserved. + + :rtype: int + :return: amount of memory reserved in kb """ return self.data.memory - self.data.idle_memory def memIdle(self): - """ - :rtype: int - :return: value of memory idle + """Returns the amount of memory the host currently has idle. + + :rtype: int + :return: amount of idle memory in kb """ return self.data.idle_memory def memUsed(self): - """ - :rtype: int - :return: value of memory used + """Returns the amount of memory the host currently has in use. + + :rtype: int + :return: amount of in-use memory in kb """ return self.data.total_memory - self.data.free_memory def memTotal(self): - """ - :rtype: int + """Returns the total amount of memory the host has. + + :rtype: int :return: total amount of memory on host """ return self.data.total_memory def memFree(self): - """ - :rtype: int - :return: amount of free memory + """Returns the amount of memory the host currently has free. + + :rtype: int + :return: amount of free memory in kb """ return self.data.free_memory def swapUsed(self): - """ - :rtype: int - :return: amount of swap used + """Returns the amount of swap space the host has in use. + + :rtype: int + :return: amount of swap used in kb """ return self.data.total_swap - self.data.free_swap def swapTotal(self): - """ - :rtype: int - :return: total amount of swap + """Returns the total amount of swap space the host has. + + :rtype: int + :return: total amount of swap space in kb """ return self.data.total_swap def swapFree(self): - """ - :rtype: int - :return: amount of free swap + """Returns the amount of free swap space the host has. + + :rtype: int + :return: amount of free swap space in kb """ return self.data.free_swap def mcpUsed(self): - """ - :rtype: int - :return: amount of mcp used + """Returns the amount of /mcp space the host is using. + + :rtype: int + :return: amount of mcp used in kb """ return self.mcpTotal() - self.mcpFree() def mcpTotal(self): - """ - :rtype: int - :return: total amount of mcp + """Returns the total amount of /mcp space the host has. + + :rtype: int + :return: total amount of mcp in kb """ return self.data.total_mcp def mcpFree(self): - """ - :rtype: int - :return: amount of mcp free + """Returns the amount of free /mcp space the host has. + + :rtype: int + :return: amount of mcp free in kb """ return self.data.free_mcp def load(self): - """Returns the load on the host - :rtype: int - :return: Host load average * 100 + """Returns the host load average. + + :rtype: int + :return: host load average * 100 """ return self.data.load def bootTime(self): - """ - :rtype: int - :return: Boot time epoch + """Returns the time the host was booted. + + :rtype: int + :return: host boot time as an epoch """ return self.data.boot_time def pingTime(self): - """ - :rtype: int - :return: Ping time epoch + """Returns the last time the host sent a status report. + + :rtype: int + :return: last ping time as an epoch """ return self.data.ping_time def pingLast(self): - """ - :rtype: int - :return: Seconds since last ping + """Returns the number of seconds since the last time the host sent a status report. + + :rtype: int + :return: seconds since last ping """ return int(time.time() - self.pingTime()) def tags(self): - """ - :rtype: list - :return: Tags applied to the host + """Returns the tags the host has. + + :rtype: list + :return: list of tags applied to the host """ return self.data.tags def state(self): - """ - :rtype: opencue.HardwareState - :return: the state of the host + """Returns the hardware state of the host. + + :rtype: host_pb2.HardwareState + :return: the hardware state of the host """ return self.data.state def lockState(self): - """ - :rtype: opencue.LockState + """Returns the lock state of the host. + + :rtype: host_pb2.LockState :return: the lock state of the host """ return self.data.lock_state @@ -431,6 +457,7 @@ def __init__(self, host): def children(self): """The procs running on this host. - :rtype: list - :return: The procs running on this host""" - return self.procs + :rtype: host_pb2.NestedProcSeq + :return: the procs running on this host + """ + return self.data.procs diff --git a/pycue/opencue/wrappers/job.py b/pycue/opencue/wrappers/job.py index 10a140ba8..eb977a280 100644 --- a/pycue/opencue/wrappers/job.py +++ b/pycue/opencue/wrappers/job.py @@ -12,14 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. - - -""" -Project: opencue Library - -Module: job.py - opencue Library implementation of a job - -""" +"""Module for classes related to jobs.""" import enum import os @@ -39,6 +32,7 @@ class Job(object): """This class contains the ice implementation related to a job.""" class JobState(enum.IntEnum): + """Enum representing the state of a job.""" PENDING = job_pb2.PENDING FINISHED = job_pb2.FINISHED STARTUP = job_pb2.STARTUP @@ -46,27 +40,28 @@ class JobState(enum.IntEnum): POSTED = job_pb2.POSTED def __init__(self, job=None): - """_Job class initialization""" self.data = job self.stub = Cuebot.getStub('job') + self.__frameStateTotals = {} def kill(self): - """Kills the job""" + """Kills the job.""" self.stub.Kill(job_pb2.JobKillRequest(job=self.data), timeout=Cuebot.Timeout) def pause(self): - """Pauses the job""" + """Pauses the job.""" self.stub.Pause(job_pb2.JobPauseRequest(job=self.data), timeout=Cuebot.Timeout) def resume(self): - """Resumes the job""" + """Resumes the job.""" self.stub.Resume(job_pb2.JobResumeRequest(job=self.data), timeout=Cuebot.Timeout) def killFrames(self, **request): """Kills all frames that match the FrameSearch. :type request: Dict - :param request: FrameSearch parameters""" + :param request: FrameSearch parameters + """ criteria = opencue.search.FrameSearch.criteriaFromOptions(**request) self.stub.KillFrames(job_pb2.JobKillFramesRequest(job=self.data, req=criteria), timeout=Cuebot.Timeout) @@ -75,7 +70,8 @@ def eatFrames(self, **request): """Eats all frames that match the FrameSearch. :type request: Dict - :param request: FrameSearch parameters""" + :param request: FrameSearch parameters + """ criteria = opencue.search.FrameSearch.criteriaFromOptions(**request) return self.stub.EatFrames(job_pb2.JobEatFramesRequest(job=self.data, req=criteria), timeout=Cuebot.Timeout) @@ -84,17 +80,18 @@ def retryFrames(self, **request): """Retries all frames that match the FrameSearch. :type request: Dict - :param request: FrameSearch parameters""" + :param request: FrameSearch parameters + """ criteria = opencue.search.FrameSearch.criteriaFromOptions(**request) return self.stub.RetryFrames(job_pb2.JobRetryFramesRequest(job=self.data, req=criteria), timeout=Cuebot.Timeout) def markdoneFrames(self, **request): - """Drops any dependency that requires any frame that matches the - FrameSearch. + """Drops any dependency that requires any frame that matches the FrameSearch. :type request: Dict - :param request: FrameSearch parameters""" + :param request: FrameSearch parameters + """ criteria = opencue.search.FrameSearch.criteriaFromOptions(**request) return self.stub.MarkDoneFrames( job_pb2.JobMarkDoneFramesRequest(job=self.data, req=criteria), @@ -104,33 +101,37 @@ def markAsWaiting(self, **request): """Changes the matching frames from the depend state to the waiting state. :type request: Dict - :param request: FrameSearch parameters""" + :param request: FrameSearch parameters + """ criteria = opencue.search.FrameSearch.criteriaFromOptions(**request) return self.stub.MarkAsWaiting( job_pb2.JobMarkAsWaitingRequest(job=self.data, req=criteria), timeout=Cuebot.Timeout) def setMinCores(self, minCores): - """Sets the minimum procs value. + """Sets the minimum number of cores the job needs. :type minCores: int - :param minCores: New minimum cores value""" + :param minCores: new minimum cores value + """ self.stub.SetMinCores(job_pb2.JobSetMinCoresRequest(job=self.data, val=minCores), timeout=Cuebot.Timeout) def setMaxCores(self, maxCores): - """Sets the maximum procs value. + """Sets the maximum number of cores the job will use. :type maxCores: int - :param maxCores: New maximum cores value""" + :param maxCores: new maximum cores value + """ self.stub.SetMaxCores(job_pb2.JobSetMaxCoresRequest(job=self.data, val=maxCores), timeout=Cuebot.Timeout) def setPriority(self, priority): - """Sets the priority number. + """Sets the job priority. :type priority: int - :param priority: New priority number""" + :param priority: new job priority number + """ self.stub.SetPriority(job_pb2.JobSetPriorityRequest(job=self.data, val=priority), timeout=Cuebot.Timeout) @@ -138,16 +139,18 @@ def setMaxRetries(self, maxRetries): """Sets the number of retries before a frame goes dead. :type maxRetries: int - :param maxRetries: New max retries""" + :param maxRetries: new max retries + """ self.stub.SetMaxRetries( job_pb2.JobSetMaxRetriesRequest(job=self.data, max_retries=maxRetries), timeout=Cuebot.Timeout) def getLayers(self): - """Returns the list of layers. + """Returns the list of layers in the job. - :rtype: list - :return: List of layers""" + :rtype: list + :return: list of layers in the job + """ response = self.stub.GetLayers(job_pb2.JobGetLayersRequest(job=self.data), timeout=Cuebot.Timeout) layerSeq = response.layers @@ -162,8 +165,9 @@ def getFrames(self, **options): frames = job.getFrames(show=["edu","beo"],user="jwelborn") frames = job.getFrames(show="edu",shot="bs.012") - :rtype: list - :return: List of frames""" + :rtype: list + :return: list of frames + """ criteria = opencue.search.FrameSearch.criteriaFromOptions(**options) response = self.stub.GetFrames(job_pb2.JobGetFramesRequest(job=self.data, req=criteria), timeout=Cuebot.Timeout) @@ -171,26 +175,24 @@ def getFrames(self, **options): return [opencue.wrappers.frame.Frame(frm) for frm in frameSeq.frames] def getUpdatedFrames(self, lastCheck, layers=None): - """Returns a list of updated state information for frames that have - changed since the last update time as well as the current state of the - job. If layer proxies are provided in the layers list, only frames from - those layers will be returned. + """Returns a list of state information for frames that have been recently updated. - UpdatedFrameCheckResult:: - - CueIce::JobState state = - int updated = - UpdatedFrameSeq updatedFrames = + This includes any frames that have changed since the last update time as well as the + current state of the job. If layer proxies are provided in the layers list, only frames + from those layers will be returned. :type lastCheck: int - :param lastCheck: Epoch when last updated + :param lastCheck: epoch when last updated :type layers: list - :param layers: List of layers to check, empty list checks all - :rtype: job_pb2.UpdatedFrameCheckResult - :return: Job state and a list of updatedFrames""" + :param layers: list of layers to check, empty list checks all + :rtype: job_pb2.JobGetUpdatedFramesResponse + :return: job state and a list of updated frames + """ if layers is not None: layerSeq = job_pb2.LayerSeq() + # pylint: disable=no-member layerSeq.layers.extend(layers) + # pylint: enable=no-member else: layerSeq = None return self.stub.GetUpdatedFrames( @@ -199,25 +201,29 @@ def getUpdatedFrames(self, lastCheck, layers=None): timeout=Cuebot.Timeout) def setAutoEating(self, value): - """If set to true, any frames that would become dead, will become eaten. + """Sets the job autoeat field. + + If set to true, any frames that would become dead will become eaten. :type value: bool - :param value: State of autoeat""" + :param value: whether job should autoeat + """ self.stub.SetAutoEat(job_pb2.JobSetAutoEatRequest(job=self.data, value=value), timeout=Cuebot.Timeout) def addRenderPartition(self, hostname, threads, max_cores, num_mem, max_gpu): - """Add a render partition to the job. - @type hostname: str - @param hostname: hostname of the partition - @type threads: int - @param threads: number of threads of the partition - @type max_cores: int - @param max_cores: max cores enabled for the partition - @type num_mem: int - @param num_mem: amount of memory reserved for the partition - @type max_gpu: int - @param max_gpu: max gpu cores enabled for the partition + """Adds a render partition to the job. + + :type hostname: str + :param hostname: hostname of the partition + :type threads: int + :param threads: number of threads of the partition + :type max_cores: int + :param max_cores: max cores enabled for the partition + :type num_mem: int + :param num_mem: amount of memory reserved for the partition + :type max_gpu: int + :param max_gpu: max gpu cores enabled for the partition """ self.stub.AddRenderPartition( job_pb2.JobAddRenderPartRequest(job=self.data, @@ -232,7 +238,8 @@ def getWhatDependsOnThis(self): """Returns a list of dependencies that depend directly on this job. :rtype: list - :return: List of dependencies that depend directly on this job""" + :return: list of dependencies that depend directly on this job + """ response = self.stub.GetWhatDependsOnThis( job_pb2.JobGetWhatDependsOnThisRequest(job=self.data), timeout=Cuebot.Timeout) @@ -243,7 +250,8 @@ def getWhatThisDependsOn(self): """Returns a list of dependencies that this job depends on. :rtype: list - :return: dependencies that this job depends on""" + :return: dependencies that this job depends on + """ response = self.stub.GetWhatThisDependsOn( job_pb2.JobGetWhatThisDependsOnRequest(job=self.data), timeout=Cuebot.Timeout) @@ -254,7 +262,8 @@ def getDepends(self): """Returns a list of all depends this job is involved with. :rtype: list - :return: all depends involved with this job""" + :return: all depends involved with this job + """ response = self.stub.GetDepends( job_pb2.JobGetDependsRequest(job=self.data), timeout=Cuebot.Timeout) @@ -262,46 +271,48 @@ def getDepends(self): return [opencue.wrappers.depend.Depend(dep) for dep in dependSeq.depends] def dropDepends(self, target): - """Drops the desired dependency target: - depend_pb2.DependTarget.AnyTarget - depend_pb2.DependTarget.External - depend_pb2.DependTarget.Internal + """Drops the desired dependency target. + :type target: depend_pb2.DependTarget - :param target: The desired dependency target to drop""" + :param target: the desired dependency target to drop + """ return self.stub.DropDepends(job_pb2.JobDropDependsRequest(job=self.data, target=target), timeout=Cuebot.Timeout) def createDependencyOnJob(self, job): - """Create and return a job on job dependency. + """Creates and returns a job-on-job dependency. :type job: opencue.wrappers.job.Job :param job: the job you want this job to depend on :rtype: opencue.wrappers.depend.Depend - :return: The new dependency""" + :return: the new dependency + """ response = self.stub.CreateDependencyOnJob( job_pb2.JobCreateDependencyOnJobRequest(job=self.data, on_job=job.data), timeout=Cuebot.Timeout) return opencue.wrappers.depend.Depend(response.depend) def createDependencyOnLayer(self, layer): - """Create and return a job on layer dependency. + """Create and return a job-on-layer dependency. :type layer: opencue.wrappers.layer.Layer :param layer: the layer you want this job to depend on :rtype: opencue.wrappers.Depend - :return: the new dependency""" + :return: the new dependency + """ response = self.stub.CreateDependencyOnLayer( job_pb2.JobCreateDependencyOnLayerRequest(job=self.data, layer=layer.data), timeout=Cuebot.Timeout) return opencue.wrappers.depend.Depend(response.depend) def createDependencyOnFrame(self, frame): - """Create and return a job on frame dependency. + """Creates and returns a job-on-frame dependency. :type frame: opencue.wrappers.frame.Frame :param frame: the frame you want this job to depend on :rtype: opencue.wrappers.depend.Depend - :return: the new dependency""" + :return: the new dependency + """ response = self.stub.CreateDependencyOnFrame( job_pb2.JobCreateDependencyOnFrameRequest(job=self.data, frame=frame.data), timeout=Cuebot.Timeout) @@ -322,9 +333,10 @@ def addComment(self, subject, message): """Appends a comment to the job's comment list. :type subject: str - :param subject: Subject data + :param subject: comment subject :type message: str - :param message: Message data""" + :param message: comment message body + """ comment = comment_pb2.Comment( user=os.getenv("USER", "unknown"), subject=subject, @@ -334,7 +346,11 @@ def addComment(self, subject, message): timeout=Cuebot.Timeout) def getComments(self): - """returns the jobs comments""" + """Returns the job's comment list. + + :rtype: list + :return: the job's comment list + """ response = self.stub.GetComments(job_pb2.JobGetCommentsRequest(job=self.data), timeout=Cuebot.Timeout) commentSeq = response.comments @@ -344,130 +360,151 @@ def setGroup(self, group): """Sets the job to a new group. :type group: opencue.wrappers.group.Group - :param group: the group you want the job to be in.""" + :param group: the group you want the job to be in + """ self.stub.SetGroup(job_pb2.JobSetGroupRequest(job=self.data, group_id=group.id()), timeout=Cuebot.Timeout) - def reorderFrames(self, range, order): + def reorderFrames(self, frame_range, order): """Reorders the specified frame range on this job. - :type range: string - :param range: The frame range to reorder + :type frame_range: string + :param frame_range: The frame range to reorder :type order: job_pb2.Order - :param order: First, Last or Reverse""" + :param order: First, Last or Reverse + """ self.stub.ReorderFrames( - job_pb2.JobReorderFramesRequest(job=self.data, range=range, order=order), + job_pb2.JobReorderFramesRequest(job=self.data, range=frame_range, order=order), timeout=Cuebot.Timeout) - def staggerFrames(self, range, stagger): + def staggerFrames(self, frame_range, stagger): """Staggers the specified frame range on this job. - :type range: string - :param range: The frame range to stagger + :type frame_range: string + :param frame_range: the frame range to stagger :type stagger: int - :param stagger: The amount to stagger by""" + :param stagger: the amount to stagger by + """ self.stub.StaggerFrames( - job_pb2.JobStaggerFramesRequest(job=self.data, range=range, stagger=stagger), + job_pb2.JobStaggerFramesRequest(job=self.data, range=frame_range, stagger=stagger), timeout=Cuebot.Timeout) def facility(self): - """Returns the facility that the job must run in""" + """Returns the facility that the job must run in. + + :rtype: str + :return: the job facility + """ return self.data.facility def id(self): - """Returns the uuid of the job. + """Returns the id of the job. :rtype: str - :return: Job uuid""" + :return: id of the job + """ return self.data.id def name(self): """Returns the name of the job. :rtype: str - :return: Job name""" + :return: name of the job + """ return self.data.name def show(self): - """Returns the show name. + """Returns the show name of the job. :rtype: str - :return: Show name""" + :return: show name of the job + """ return self.data.show def shot(self): - """Returns the shot name. + """Returns the shot name of the job. :rtype: str - :return: Shot name""" + :return: shot name of the job + """ return self.data.shot def logDir(self): - """Returns the path to the log files. + """Returns the path to the job log files. :rtype: str - :return: Path of log files""" + :return: path of job log files + """ return self.data.log_dir def uid(self): """Returns the uid of the person who owns the job. :rtype: Optional[int] - :return: Uid of job owner""" + :return: uid of job owner + """ return self.data.uid if self.data.HasField("uid") else None def user(self): """Returns the username of the person who owns the job. :rtype: str - :return: Username of job owner""" + :return: username of job owner + """ return self.data.user def username(self): """Returns the username of the person who owns the job. :rtype: str - :return: Username of job owner""" + :return: username of job owner""" return self.user() def state(self): """Returns the job state. - :rtype: JobState - :return: Job state""" + :rtype: job_pb2.JobState + :return: job state + """ return self.data.state def priority(self): """Returns the job priority. :rtype: int - :return: Job priority""" + :return: job priority + """ return self.data.priority def minCores(self): - """Returns the job's minProcs. + """Returns the minimum number of cores the job needs. :rtype: int - :return: Job's minCores""" + :return: job's min cores + """ return self.data.min_cores def maxCores(self): - """Returns the job's maxProcs. + """Returns the maximum number of cores the job will use. :rtype: int - :return: Job's maxProcs""" + :return: job's max cores + """ return self.data.max_cores def os(self): """Returns the job's operating system. - :rtype: str - :return: operating system name of the Job""" + :rtype: str + :return: operating system name of the job + """ return self.data.os + # pylint: disable=redefined-builtin def startTime(self, format=None): - """Returns the job start time in the desired format:: + """Returns the job start time in the desired format. + Examples: None => 1203634027 "%m/%d %H:%M" => 02/21 14:47 "%a %b %d %H:%M:%S %Y" => Thu Feb 21 14:47:07 2008 @@ -476,16 +513,18 @@ def startTime(self, format=None): https://docs.python.org/3/library/time.html :type format: str - :param format: Desired time format - :rtype: int - :return: Job start time in epoch""" + :param format: desired time format + :rtype: int/str + :return: job start time in epoch, or string version of that timestamp if format given""" if not format: return self.data.start_time return time.strftime(format, time.localtime(self.data.start_time)) + # pylint: disable=redefined-builtin def stopTime(self, format=None): - """Returns the job stop time in the desired format:: + """Returns the job stop time in the desired format. + Examples: None => 1203634027 "%m/%d %H:%M" => 02/21 14:47 "%a %b %d %H:%M:%S %Y" => Thu Feb 21 14:47:07 2008 @@ -494,9 +533,9 @@ def stopTime(self, format=None): https://docs.python.org/3/library/time.html :type format: str - :param format: Desired time format - :rtype: int - :return: Job stop time in epoch""" + :param format: desired time format + :rtype: int/str + :return: job stop time in epoch, or string version of that timestamp if format given""" if not format: return self.data.stop_time return time.strftime(format, time.localtime(self.data.stop_time)) @@ -505,271 +544,307 @@ def runTime(self): """Returns the number of seconds that the job has been (or was) running. :rtype: int - :return: Job runtime in seconds""" + :return: job runtime in seconds + """ if self.data.stop_time == 0: return int(time.time() - self.data.start_time) - else: - return self.data.stop_time - self.data.start_time + return self.data.stop_time - self.data.start_time def coreSecondsRemaining(self): - """Returns the estimated number of core seconds reeded to finish all - waiting frames. Does note take into account running frames. + """Returns the estimated number of core seconds needed to finish all waiting frames. + + Does not take into account running frames. :rtype: long - :return: core seconds remaining""" + :return: core seconds remaining + """ return self.data.job_stats.remaining_core_sec def age(self): """Returns the number of seconds since the job was launched. :rtype: int - :return: Seconds since the job was launched""" + :return: seconds since the job was launched + """ return int(time.time() - self.data.start_time) def isPaused(self): - """Returns true if the job is paused + """Returns true if the job is paused. + :rtype: bool - :return: Paused or not paused""" + :return: paused or not paused""" return self.data.is_paused def isAutoEating(self): """Returns true if the job is eating all frames that become dead. :rtype: bool - :return: If the job eating all frames that become dead""" + :return: if the job eating all frames that become dead + """ return self.data.auto_eat def isCommented(self): """Returns true if the job has a comment. :rtype: bool - :return: If the job has a comment""" + :return: if the job has a comment + """ return self.data.has_comment def setAutoEat(self, value): - """Changes the state of autoeating. When frames become eaten instead of dead. + """Sets a new autoeat value for the job. + + Autoeat means job frames, when they would become dead, are eaten instead. :type value: bool - :param value: The new state for autoEat""" + :param value: new state for autoeat + """ self.setAutoEating(value) self.data.auto_eat = value def coresReserved(self): - """Returns the number of reserved cores. + """Returns the number of reserved cores the job has. - :rtype: float - :return: total number of reserved cores""" + :rtype: float + :return: number of reserved cores + """ return self.data.job_stats.reserved_cores def totalFrames(self): - """Returns the total number of frames under this object. + """Returns the total number of frames the job has. :rtype: int - :return: Total number of frames""" + :return: total number of frames + """ return self.data.job_stats.total_frames def totalLayers(self): - """Returns the total number of frames under this object. + """Returns the total number of layers the job has. :rtype: int - :return: Total number of frames""" + :return: total number of layers + """ return self.data.job_stats.total_layers def dependFrames(self): - """Returns the total number of dependent frames under this object. + """Returns the total number of dependent frames the job has. :rtype: int - :return: Total number of dependent frames""" + :return: total number of dependent frames + """ return self.data.job_stats.depend_frames def succeededFrames(self): - """Returns the total number of succeeded frames under this object. + """Returns the total number of succeeded frames the job has. :rtype: int - :return: Total number of succeeded frames""" + :return: total number of succeeded frames + """ return self.data.job_stats.succeeded_frames def runningFrames(self): - """Returns the total number of running frames under this object. + """Returns the total number of running frames the job has. :rtype: int - :return: Total number of running frames""" + :return: total number of running frames + """ return self.data.job_stats.running_frames def deadFrames(self): - """Returns the total number of deads frames under this object. + """Returns the total number of deads frames the job has. :rtype: int - :return: Total number of dead frames""" + :return: total number of dead frames + """ return self.data.job_stats.dead_frames def waitingFrames(self): - """Returns the total number of waiting frames under this object. + """Returns the total number of waiting frames the job has. :rtype: int - :return: Total number of waiting frames""" + :return: total number of waiting frames + """ return self.data.job_stats.waiting_frames def eatenFrames(self): - """Returns the total number of eaten frames under this object. + """Returns the total number of eaten frames the job has. :rtype: int - :return: Total number of eaten frames""" + :return: total number of eaten frames + """ return self.data.job_stats.eaten_frames def pendingFrames(self): - """Returns the total number of pending (dependent and waiting) frames - under this object. + """Returns the total number of pending (dependent and waiting) frames the job has. :rtype: int - :return: Total number of pending (dependent and waiting) frames""" + :return: total number of pending (dependent and waiting) frames + """ return self.data.job_stats.pending_frames def frameStateTotals(self): - """Returns a dictionary of frame states and the number of frames in each - state. The states are available from opencue.FrameState.* + """Returns a dictionary of frame states and the number of frames in each state. + + The states are available from job_pb2.FrameState. - :rtype: dict - :return: total number of frames in each state""" - if not hasattr(self, "__frameStateTotals"): - self.__frameStateTotals = {} + :rtype: dict + :return: total number of frames in each state + """ + if not self.__frameStateTotals: + self.__frameStateTotals.clear() for state in job_pb2.FrameState.keys(): frameCount = getattr(self.data.job_stats, '{}_frames'.format(state.lower()), 0) self.__frameStateTotals[getattr(job_pb2, state)] = frameCount return self.__frameStateTotals def percentCompleted(self): - """Returns the percent that the object's frames are completed. + """Returns the percent that the job's frames are completed. :rtype: float - :return: Percentage of frame completion""" + :return: percentage of frame completion + """ try: return self.data.job_stats.succeeded_frames /\ float(self.data.job_stats.total_frames) * 100.0 - except: + except ZeroDivisionError: return 0 def group(self): """Returns the name of the group that the job is in. :rtype: str - :return: Jobs group name""" + :return: job group name + """ return self.data.group def avgFrameTime(self): """Returns the average completed frame time in seconds. :rtype: int - :return: Average completed frame time in seconds""" + :return: average completed frame time in seconds + """ return self.data.job_stats.avg_frame_sec def averageCoreTime(self): - """Returns the average frame time. + """Returns the average frame core time. :rtype: int - :return: Average frame time for entire job""" + :return: average frame core time for entire job + """ return self.data.job_stats.avg_core_sec def maxRss(self): - """Returns the highest amount of memory that any frame in this job used - in kB. Value is within 5% of the actual highest frame. + """Returns the highest amount of memory that any frame in this job used. + + Value is within 5% of the actual highest frame. :rtype: long - :return: Most memory used by any frame in kB""" + :return: most memory used by any frame in kB""" return self.data.job_stats.max_rss + class NestedJob(Job): """This class contains information and actions related to a nested job.""" def __init__(self, nestedJob=None): super(NestedJob, self).__init__(nestedJob) - ## job children are most likely empty but its possible to - ## populate this with NesterLayer objects. + # job children are most likely empty but its possible to + # populate this with NestedLayer objects. self.__children = [] def children(self): + """Returns all job children.""" return self.__children def kill(self): - """Kills the job""" + """Kills the job.""" self.asJob().kill() def pause(self): - """Pauses the job""" + """Pauses the job.""" self.asJob().pause() def resume(self): - """Resumes the job""" + """Resumes the job.""" self.asJob().resume() def killFrames(self, **request): """Kills all frames that match the FrameSearch. :type request: Dict - :param request: FrameSearch parameters""" + :param request: FrameSearch parameters + """ self.asJob().killFrames(**request) def eatFrames(self, **request): """Eats all frames that match the FrameSearch. :type request: Dict - :param request: FrameSearch parameters""" + :param request: FrameSearch parameters + """ self.asJob().eatFrames(**request) def retryFrames(self, **request): """Retries all frames that match the FrameSearch. :type request: Dict - :param request: FrameSearch parameters""" + :param request: FrameSearch parameters + """ self.asJob().retryFrames(**request) def markdoneFrames(self, **request): - """Drops any dependency that requires any frame that matches the - FrameSearch. + """Drops any dependency that requires any frame that matches the FrameSearch. :type request: Dict - :param request: FrameSearch parameters""" + :param request: FrameSearch parameters + """ self.asJob().markdoneFrames(**request) def markAsWaiting(self, **request): """Changes the matching frames from the depend state to the waiting state. :type request: Dict - :param request: FrameSearch parameters""" + :param request: FrameSearch parameters + """ self.asJob().markAsWaiting(**request) def setMinCores(self, minCores): - """Sets the minimum procs value. + """Sets the minimum cores value. :type minCores: int - :param minCores: New minimum cores value""" + :param minCores: new minimum cores value + """ self.asJob().setMinCores(minCores) def setMaxCores(self, maxCores): - """Sets the maximum procs value. + """Sets the maximum cores value. :type maxCores: int - :param maxCores: New maximum cores value""" + :param maxCores: new maximum cores value + """ self.asJob().setMaxCores(maxCores) def setPriority(self, priority): - """Sets the priority number. + """Sets the job priority. :type priority: int - :param priority: New priority number""" + :param priority: new priority number + """ self.asJob().setPriority(priority) def setMaxRetries(self, maxRetries): """Sets the number of retries before a frame goes dead. :type maxRetries: int - :param maxRetries: New max retries""" + :param maxRetries: new max retries + """ self.asJob().setMaxRetries(maxRetries) def getLayers(self): - """Returns the list of layers. + """Returns the list of job layers. :rtype: list - :return: List of layers""" + :return: list of layers in the job + """ return self.asJob().getLayers() def getFrames(self, **options): @@ -778,137 +853,149 @@ def getFrames(self, **options): frames = job.getFrames(show=["edu","beo"],user="jwelborn") frames = job.getFrames(show="edu",shot="bs.012") Allowed: offset, limit, states+, layers+. frameset, changedate + :rtype: list - :return: List of frames""" + :return: list of matching frames""" return self.asJob().getFrames(**options) def getUpdatedFrames(self, lastCheck, layers=None): - """Returns a list of updated state information for frames that have - changed since the last update time as well as the current state of the - job. If layer proxies are provided in the layers list, only frames from - those layers will be returned. - - UpdatedFrameCheckResult:: + """Returns a list of state information for frames that have been recently updated. - CueIce::JobState state = - int updated = - UpdatedFrameSeq updatedFrames = + This includes any frames that have changed since the last update time as well as the + current state of the job. If layer proxies are provided in the layers list, only frames + from those layers will be returned. :type lastCheck: int - :param lastCheck: Epoch when last updated - :type layers: list - :param layers: List of layers to check, empty list checks all - :rtype: UpdatedFrameCheckResult - :return: Job state and a list of updatedFrames""" + :param lastCheck: epoch when last updated + :type layers: list + :param layers: list of layers to check, empty list checks all + :rtype: job_pb2.JobGetUpdatedFramesResponse + :return: job state and a list of updated frames + """ return self.asJob().getUpdatedFrames(lastCheck, layers) def setAutoEating(self, value): """If set to true, any frames that would become dead, will become eaten. :type value: bool - :param value: State of autoeat""" + :param value: state of autoeat + """ self.asJob().setAutoEating(value) - def getWhatDependsOnThis(self): """Returns a list of dependencies that depend directly on this job. :rtype: list - :return: List of dependencies that depend directly on this job""" + :return: list of dependencies that depend directly on this job + """ return self.asJob().getWhatDependsOnThis() def getWhatThisDependsOn(self): """Returns a list of dependencies that this job depends on. :rtype: list - :return: dependencies that this job depends on""" + :return: dependencies that this job depends on + """ return self.asJob().getWhatThisDependsOn() def getDepends(self): """Returns a list of all depends this job is involved with. :rtype: list - :return: all depends involved with this job""" + :return: all depends involved with this job + """ return self.asJob().getDepends() def dropDepends(self, target): - """Drops the desired dependency target:: + """Drops the desired dependency target. depend_pb2.DependTarget.AnyTarget depend_pb2.DependTarget.External depend_pb2.DependTarget.Internal :type target: depend_pb2.DependTarget - :param target: The desired dependency target to drop""" + :param target: The desired dependency target to drop + """ return self.asJob().dropDepends(target) def createDependencyOnJob(self, job): - """Create and return a job on job dependency. + """Creates and returns a job-on-job dependency. :type job: opencue.wrappers.job.Job :param job: the job you want this job to depend on :rtype: opencue.wrappers.depend.Depend - :return: The new dependency""" - return self.asJob().createDependencyOnJOb(job) + :return: The new dependency + """ + return self.asJob().createDependencyOnJob(job) def createDependencyOnLayer(self, layer): - """Create and return a job on layer dependency. + """Creates and returns a job-on-layer dependency. :type layer: opencue.wrappers.layer.Layer :param layer: the layer you want this job to depend on :rtype: opencue.wrappers.depend.Depend - :return: the new dependency""" + :return: the new dependency + """ return self.asJob().createDependencyOnLayer(layer) def createDependencyOnFrame(self, frame): - """Create and return a job on frame dependency. + """Creates and returns a job-on-frame dependency. :type frame: opencue.wrappers.frame.Frame :param frame: the frame you want this job to depend on :rtype: opencue.wrappers.depend.Depend - :return: the new dependency""" + :return: the new dependency + """ return self.asJob().createDependencyOnFrame(frame) def addComment(self, subject, message): """Appends a comment to the job's comment list. :type subject: str - :param subject: Subject data + :param subject: comment subject :type message: str - :param message: Message data""" + :param message: comment message body + """ self.asJob().addComment(subject, message) def getComments(self): - """Returns the jobs comments.""" + """Returns the job's comment list.""" return self.asJob().getComments() def setGroup(self, group): """Sets the job to a new group. :type group: opencue.wrappers.group.Group - :param group: the group you want the job to be in.""" + :param group: the group you want the job to be in. + """ self.asJob().setGroup(group) - def reorderFrames(self, range, order): + def reorderFrames(self, frame_range, order): """Reorders the specified frame range on this job. - :type range: string - :param range: The frame range to reorder + :type frame_range: string + :param frame_range: The frame range to reorder :type order: job_pb2.Order - :param order: First, Last or Reverse""" - self.asJob().reorderFrames(range, order) + :param order: First, Last or Reverse + """ + self.asJob().reorderFrames(frame_range, order) - def staggerFrames(self, range, stagger): + def staggerFrames(self, frame_range, stagger): """Staggers the specified frame range on this job. - :type range: string - :param range: The frame range to stagger + :type frame_range: string + :param frame_range: the frame range to stagger :type stagger: int - :param stagger: The amount to stagger by""" - self.asJob().staggerFrames(range, stagger) + :param stagger: the amount to stagger by + """ + self.asJob().staggerFrames(frame_range, stagger) def asJob(self): - """Returns a Job object from this NestedJob""" + """Returns a Job object from this NestedJob. + + :rtype: opencue.wrappers.job.Job + :return: Job version of this NestedJob + """ return Job(job_pb2.Job( id=self.data.id, state=self.data.state, diff --git a/pycue/opencue/wrappers/layer.py b/pycue/opencue/wrappers/layer.py index dc33bc57a..7c33b68e7 100644 --- a/pycue/opencue/wrappers/layer.py +++ b/pycue/opencue/wrappers/layer.py @@ -12,35 +12,32 @@ # See the License for the specific language governing permissions and # limitations under the License. - -""" -opencue layer module - -implementation of a layer in opencue -""" +"""Module for classes related to job layers.""" import enum import os +import opencue.api from opencue.compiled_proto import job_pb2 from opencue.cuebot import Cuebot import opencue.search import opencue.wrappers.depend import opencue.wrappers.frame import opencue.wrappers.limit -import opencue.api class Layer(object): """This class contains the grpc implementation related to a Layer.""" class LayerType(enum.IntEnum): + """Represents the type of layer.""" PRE = job_pb2.PRE POST = job_pb2.POST RENDER = job_pb2.RENDER UTIL = job_pb2.UTIL class Order(enum.IntEnum): + """Represents the order of a layer.""" FIRST = job_pb2.FIRST LAST = job_pb2.LAST REVERSE = job_pb2.REVERSE @@ -50,51 +47,54 @@ def __init__(self, layer=None): self.stub = Cuebot.getStub('layer') def kill(self): - """Kill entire layer""" + """Kills the entire layer.""" return self.stub.KillFrames(job_pb2.LayerKillFramesRequest(layer=self.data), timeout=Cuebot.Timeout) def eat(self): - """Eat entire layer""" + """Eats the entire layer.""" return self.stub.EatFrames(job_pb2.LayerEatFramesRequest(layer=self.data), timeout=Cuebot.Timeout) def retry(self): - """Retry entire layer""" + """Retries the entire layer.""" return self.stub.RetryFrames(job_pb2.LayerRetryFramesRequest(layer=self.data), timeout=Cuebot.Timeout) def markdone(self): - """Drops any dependency that requires this layer or requires any frame - in the layer""" + """Drops any dependency that requires this layer or requires any frame in the layer.""" return self.stub.MarkdoneFrames(job_pb2.LayerMarkdoneFramesRequest(layer=self.data), timeout=Cuebot.Timeout) def addLimit(self, limit_id): - """Add a limit to the current layer.""" + """Adds a limit to the current layer.""" return self.stub.AddLimit(job_pb2.LayerAddLimitRequest(layer=self.data, limit_id=limit_id), timeout=Cuebot.Timeout) - + def dropLimit(self, limit_id): - """Remove a limit on the current layer.""" + """Removes a limit on the current layer.""" return self.stub.DropLimit( job_pb2.LayerDropLimitRequest(layer=self.data, limit_id=limit_id), timeout=Cuebot.Timeout) def enableMemoryOptimizer(self, value): - """Set enableMemoryOptimizer to the value. + """Enables or disables the memory optimizer. - :type value: bool - :param value: boolean to enable/disable memory optimizer""" + :type value: bool + :param value: whether memory optimizer is enabled + """ return self.stub.EnableMemoryOptimizer(job_pb2.LayerEnableMemoryOptimizerRequest( layer=self.data, value=value), timeout=Cuebot.Timeout) def getFrames(self, **options): - """Returns the list of up to 1000 frames from within the layer. + """Returns a list of up to 1000 frames from within the layer. + :type options: dict + :param options: FrameSearch options :rtype: list - :return: Sequence of Frame obejcts""" + :return: sequence of matching frames + """ criteria = opencue.search.FrameSearch.criteriaFromOptions(**options) response = self.stub.GetFrames(job_pb2.LayerGetFramesRequest(layer=self.data, s=criteria), timeout=Cuebot.Timeout) @@ -104,15 +104,17 @@ def getOutputPaths(self): """Return the output paths for this layer. :rtype: list - :return: list of output paths""" + :return: list of output paths + """ return self.stub.GetOutputPaths(job_pb2.LayerGetOutputPathsRequest(layer=self.data), timeout=Cuebot.Timeout).output_paths def setTags(self, tags): - """Sets the tags, TODO: update description of tag structure. + """Sets the layer tags. :type tags: list - :param tags: Layer tags""" + :param tags: layer tags + """ return self.stub.SetTags(job_pb2.LayerSetTagsRequest(layer=self.data, tags=tags), timeout=Cuebot.Timeout) @@ -120,17 +122,20 @@ def setMaxCores(self, cores): """Sets the maximum number of cores that this layer requires. :type cores: float - :param cores: Core units, 100 reserves 1 core""" + :param cores: Core units, 100 reserves 1 core + """ return self.stub.SetMaxCores( job_pb2.LayerSetMaxCoresRequest(layer=self.data, cores=cores/100.0), timeout=Cuebot.Timeout) def setMinCores(self, cores): """Sets the minimum number of cores that this layer requires. + Use 100 to reserve 1 core. :type cores: int - :param cores: Core units, 100 reserves 1 core""" + :param cores: core units, 100 reserves 1 core + """ return self.stub.SetMinCores( job_pb2.LayerSetMinCoresRequest(layer=self.data, cores=cores/100.0), timeout=Cuebot.Timeout) @@ -139,25 +144,28 @@ def setMinGpu(self, gpu): """Sets the minimum number of gpu memory that this layer requires. :type gpu: int - :param gpu: gpu value""" + :param gpu: gpu value + """ return self.stub.SetMinGpu( job_pb2.LayerSetMinGpuRequest(layer=self.data, gpu=gpu), timeout=Cuebot.Timeout) def setMinMemory(self, memory): - """Sets the minimum amount of memory that this layer requires. in Kb + """Sets the minimum amount of memory that this layer requires. :type memory: int - :param memory: Minimum Kb memory reserved by each frame""" + :param memory: Minimum Kb memory reserved by each frame + """ return self.stub.SetMinMemory( job_pb2.LayerSetMinMemoryRequest(layer=self.data, memory=memory), timeout=Cuebot.Timeout) def setThreadable(self, threadable): - """Set enableMemoryOptimizer to the value. + """Sets the threadable field. - :type threadable: bool - :param threadable: boolean to enable/disable threadable""" + :type threadable: bool + :param threadable: boolean to enable/disable threadable + """ return self.stub.SetThreadable(job_pb2.LayerSetThreadableRequest( layer=self.data, threadable=threadable), timeout=Cuebot.Timeout) @@ -179,17 +187,18 @@ def setTimeoutLLU(self, timeout_llu): timeout=Cuebot.Timeout) def addRenderPartition(self, hostname, threads, max_cores, num_mem, max_gpu): - """Add a render partition to the layer. - @type hostname: str - @param hostname: hostname of the partition - @type threads: int - @param threads: number of threads of the partition - @type max_cores: int - @param max_cores: max cores enabled for the partition - @type num_mem: int - @param num_mem: amount of memory reserved for the partition - @type max_gpu: int - @param max_gpu: max gpu cores enabled for the partition + """Adds a render partition to the layer. + + :type hostname: str + :param hostname: hostname of the partition + :type threads: int + :param threads: number of threads of the partition + :type max_cores: int + :param max_cores: max cores enabled for the partition + :type num_mem: int + :param num_mem: amount of memory reserved for the partition + :type max_gpu: int + :param max_gpu: max gpu cores enabled for the partition """ self.stub.AddRenderPartition( job_pb2.LayerAddRenderPartitionRequest(layer=self.data, @@ -204,7 +213,8 @@ def getWhatDependsOnThis(self): """Gets a list of dependencies that depend directly on this layer. :rtype: list - :return: List of dependencies that depend directly on this layer""" + :return: list of dependencies that depend directly on this layer + """ response = self.stub.GetWhatDependsOnThis( job_pb2.LayerGetWhatDependsOnThisRequest(layer=self.data), timeout=Cuebot.Timeout) @@ -212,10 +222,11 @@ def getWhatDependsOnThis(self): return [opencue.wrappers.depend.Depend(dep) for dep in dependSeq.depends] def getWhatThisDependsOn(self): - """Get a list of dependencies that this layer depends on. + """Returns a list of dependencies that this layer depends on. :rtype: list - :return: List of dependences that this layer depends on""" + :return: list of dependences that this layer depends on + """ response = self.stub.GetWhatThisDependsOn( job_pb2.LayerGetWhatThisDependsOnRequest(layer=self.data), timeout=Cuebot.Timeout) @@ -223,48 +234,52 @@ def getWhatThisDependsOn(self): return [opencue.wrappers.depend.Depend(dep) for dep in dependSeq.depends] def createDependencyOnJob(self, job): - """Create and return a layer on job dependency. + """Creates and returns a layer-on-job dependency. :type job: opencue.wrappers.job.Job :param job: the job you want this job to depend on :rtype: opencue.wrappers.depend.Depend - :return: the new dependency""" + :return: the new dependency + """ response = self.stub.CreateDependencyOnJob( job_pb2.LayerCreateDependOnJobRequest(layer=self.data, job=job.data), timeout=Cuebot.Timeout) return opencue.wrappers.depend.Depend(response.depend) def createDependencyOnLayer(self, layer): - """Create and return a layer on layer dependency. + """Creates and returns a layer-on-layer dependency. :type layer: opencue.wrappers.layer.Layer :param layer: the layer you want this layer to depend on :rtype: opencue.wrappers.depend.Depend - :return: the new dependency""" + :return: the new dependency + """ response = self.stub.CreateDependencyOnLayer( job_pb2.LayerCreateDependOnLayerRequest(layer=self.data, depend_on_layer=layer.data), timeout=Cuebot.Timeout) return opencue.wrappers.depend.Depend(response.depend) def createDependencyOnFrame(self, frame): - """Create and return a layer on frame dependency. + """Creates and returns a layer-on-frame dependency. :type frame: opencue.wrappers.frame.Frame :param frame: the frame you want this layer to depend on :rtype: opencue.wrappers.depend.Depend - :return: the new dependency""" + :return: the new dependency + """ response = self.stub.CreateDependencyOnFrame( job_pb2.LayerCreateDependOnFrameRequest(layer=self.data, frame=frame.data), timeout=Cuebot.Timeout) return opencue.wrappers.depend.Depend(response.depend) def createFrameByFrameDependency(self, layer): - """Create and return a frame by frame frame dependency. + """Creates and returns a frame-by-frame layer dependency. :param layer: the layer you want this layer to depend on :type layer: opencue.wrappers.layer.Layer :rtype: opencue.wrappers.depend.Depend - :return: the new dependency""" + :return: the new dependency + """ # anyframe is hard coded right now, this option should be moved # to LayerOnLayer for better efficiency. response = self.stub.CreateFrameByFrameDependency( @@ -285,220 +300,254 @@ def createFrameByFrameDependency(self, layer): # self.proxy.unbookProcs([a.proxy for a in subs], number, kill) def registerOutputPath(self, outputPath): - """Register an output with the given layer. The output paths are sent in the opencue email. + """Registers an output path for the layer. - :type outputPath: str - :param outputPath: Output path to register + Output paths are included in OpenCue alert emails. + + :type outputPath: str + :param outputPath: output path to register """ self.stub.RegisterOutputPath( job_pb2.LayerRegisterOutputPathRequest(layer=self.data, spec=outputPath), timeout=Cuebot.Timeout) - def reorderFrames(self, range, order): + def reorderFrames(self, frameRange, order): """Reorders the specified frame range on this layer. - :type range: string - :param range: The frame range to reorder + :type frameRange: string + :param frameRange: the frame range to reorder :type order: opencue.wrapper.layer.Layer.Order - :param order: First, Last or Reverse""" + :param order: First, Last or Reverse + """ self.stub.ReorderFrames( - job_pb2.LayerReorderFramesRequest(layer=self.data, range=range, order=order), + job_pb2.LayerReorderFramesRequest(layer=self.data, range=frameRange, order=order), timeout=Cuebot.Timeout) - def staggerFrames(self, range, stagger): + def staggerFrames(self, frameRange, stagger): """Staggers the specified frame range on this layer. - :type range: string - :param range: The frame range to stagger + :type frameRange: string + :param frameRange: the frame range to stagger :type stagger: int - :param stagger: The amount to stagger by""" + :param stagger: the amount to stagger by + """ self.stub.StaggerFrames( - job_pb2.LayerStaggerFramesRequest(layer=self.data, range=range, stagger=stagger), + job_pb2.LayerStaggerFramesRequest(layer=self.data, range=frameRange, stagger=stagger), timeout=Cuebot.Timeout) - + def getLimitDetails(self): - """Return the Limit objects for the given layer. + """Returns the Limit objects for the given layer. - :rtype: list - :return: The list of limits on this layer.""" + :rtype: list + :return: list of limits on this layer + """ return [opencue.wrappers.limit.Limit(limit) for limit in self.stub.GetLimits( job_pb2.LayerGetLimitsRequest(layer=self.data), timeout=Cuebot.Timeout).limits] def id(self): - """Returns the uuid of the layer. + """Returns the id of the layer. :rtype: str - :return: Layer uuid""" + :return: layer id + """ return self.data.id def name(self): """Returns the name of the layer. :rtype: str - :return: Layer name""" + :return: layer name + """ return self.data.name def range(self): - """Returns the frame range for the layer. + """Returns the frame range of the layer. :rtype: str - :return: Layer frame range""" + :return: layer frame range + """ return self.data.range def chunkSize(self): """Returns the number of frames per task. :rtype: int - :return: the chunks size""" + :return: layer chunk size + """ return self.data.chunk_size def tags(self): - """Returns the tags applied to the layer + """Returns the tags applied to the layer. + TODO: Document syntax :rtype: str - :return: Layer tags""" + :return: layer tags""" return self.data.tags def dispatchOrder(self): - """Returns the layers dispatch order. + """Returns the layer dispatch order. :rtype: int - :return: Layer dispatch order""" + :return: layer dispatch order + """ return self.data.dispatch_order def coresReserved(self): """Returns the number of cores reserved on this layer. :rtype: float - :return: cores reserved""" + :return: cores reserved + """ return self.data.layer_stats.reserved_cores def minCores(self): """Returns the minimum number of cores that frames in this layer require. :rtype: int - :return: Minimum number of cores required""" + :return: minimum number of cores required + """ return self.data.min_cores def minMemory(self): - """Returns the minimum about of memory that frames in this layer require. + """Returns the minimum amount of memory that frames in this layer require. :rtype: int - :return: Minimum Kb memory required by frames in this layer""" + :return: minimum kB of memory required by frames in this layer + """ return self.data.min_memory - + def limits(self): """Returns the limit names for this layer. :rtype: list - :return: Names of the limits on this layer.""" + :return: names of the limits on this layer + """ return self.data.limits def maxRss(self): - """Returns the highest amount of memory that any frame in this layer - used in kB. Value is within 5% of the actual highest frame. + """Returns the highest amount of memory that any frame in this layer used. + + Value is within 5% of the actual highest frame. :rtype: long - :return: Most memory used by any frame in this layer in kB""" + :return: most memory used by any frame in this layer in kB""" return self.data.layer_stats.max_rss def type(self): - """Returns the type of layer. Ex: Pre, Post, Render + """Returns the type of layer. - :rtype: opencue.LayerType - :return: Type of layer""" + Ex: Pre, Post, Render + + :rtype: job_pb2.LayerType + :return: type of layer + """ return self.data.type def totalFrames(self): - """Returns the total number of frames under this object. + """Returns the total number of frames in the layer. :rtype: int - :return: Total number of frames""" + :return: total number of frames + """ return self.data.layer_stats.total_frames def dependFrames(self): - """Returns the total number of dependent frames under this object. + """Returns the total number of dependent frames in the layer. :rtype: int - :return: Total number of dependent frames""" + :return: total number of dependent frames + """ return self.data.layer_stats.depend_frames def succeededFrames(self): - """Returns the total number of succeeded frames under this object. + """Returns the total number of succeeded frames in the layer. :rtype: int - :return: Total number of succeeded frames""" + :return: total number of succeeded frames + """ return self.data.layer_stats.succeeded_frames def runningFrames(self): - """Returns the total number of running frames under this object. + """Returns the total number of running frames in the layer. :rtype: int - :return: Total number of running frames""" + :return: total number of running frames + """ return self.data.layer_stats.running_frames def deadFrames(self): - """Returns the total number of deads frames under this object. + """Returns the total number of dead frames in the layer. :rtype: int - :return: Total number of dead frames""" + :return: total number of dead frames + """ return self.data.layer_stats.dead_frames def waitingFrames(self): - """Returns the total number of waiting frames under this object. + """Returns the total number of waiting frames in the layer. :rtype: int - :return: Total number of waiting frames""" + :return: total number of waiting frames + """ return self.data.layer_stats.waiting_frames def eatenFrames(self): - """Returns the total number of eaten frames under this object. + """Returns the total number of eaten frames in the layer. :rtype: int - :return: Total number of eaten frames""" + :return: total number of eaten frames + """ return self.data.layer_stats.eaten_frames def pendingFrames(self): - """Returns the total number of pending (dependent and waiting) frames - under this object. + """Returns the total number of pending (dependent and waiting) frames in the layer. :rtype: int - :return: Total number of pending (dependent and waiting) frames""" + :return: total number of pending (dependent and waiting) frames + """ return self.data.layer_stats.pending_frames def percentCompleted(self): - """Returns the percent that the object's frames are completed. + """Returns the percent that the layer's frames are completed. :rtype: float - :return: Percentage of frame completion""" + :return: percentage of frame completion + """ try: return self.data.layer_stats.succeeded_frames / \ float(self.data.layer_stats.total_frames) * 100.0 - except: + except ZeroDivisionError: return 0 def avgFrameTimeSeconds(self): """Returns the average frame completion time in seconds. :rtype: int - :return: Average frame completion time in seconds""" + :return: average frame completion time in seconds + """ return self.data.layer_stats.avg_frame_sec def avgCoreSeconds(self): """Returns the average core time used in seconds. :rtype: int - :return: Average core time in seconds""" + :return: average core time in seconds + """ return self.data.layer_stats.avg_core_sec def coreSecondsRemaining(self): - """Returns the estimated core time that is remnainining to complete - all waiting frames. + """Returns the estimated core time that is remaining to complete all waiting frames. :rtype: int - :return: the number of seconds of estimated core time remaining""" + :return: the number of seconds of estimated core time remaining + """ return self.data.layer_stats.remaining_core_sec def parent(self): + """Gets the parent of the layer; its job. + + :rtype: opencue.wrappers.job.Job + :return: the layer's parent job + """ return opencue.api.getJob(self.data.parent_id) diff --git a/pycue/opencue/wrappers/limit.py b/pycue/opencue/wrappers/limit.py index 309261cc6..89bddca35 100644 --- a/pycue/opencue/wrappers/limit.py +++ b/pycue/opencue/wrappers/limit.py @@ -12,13 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. - -""" -Project: opencue Library - -Module: limit.py - opencue Library implementation of a limit - -""" +"""Module for classes related to limits.""" from opencue import Cuebot from opencue.compiled_proto import limit_pb2 @@ -28,85 +22,104 @@ class Limit(object): """This class contains the grpc implementation related to a Limit.""" def __init__(self, limit=None): - """Limit class initialization""" self.data = limit self.stub = Cuebot.getStub('limit') def create(self): - """Create a new Limit from the current Limit object. - - :rtype: Limit - :return: The newly created Limit + """Creates a new Limit from the current Limit object. + + :rtype: opencue.wrappers.limit.Limit + :return: the newly created Limit """ return Limit(self.stub.Create( limit_pb2.LimitCreateRequest(name=self.name(), max_value=self.maxValue()), timeout=Cuebot.Timeout)) def delete(self): - """Delete the limit record""" + """Deletes the limit.""" self.stub.Delete(limit_pb2.LimitDeleteRequest(name=self.name()), timeout=Cuebot.Timeout) def find(self, name): - """Find an existing limit by it's name. - - :type name: str - :param name: Name of limit to find. - :rtype: opencue.wrappers.limit.Limit - :return: The limit found by name. + """Finds an existing limit by its name. + + :type name: str + :param name: name of limit to find + :rtype: opencue.wrappers.limit.Limit + :return: the limit found by name """ - return Limit(self.stub.Find(limit_pb2.LimitFindRequest(name=name), timeout=Cuebot.Timeout).limit) - - def get(self, id): - """Return an existing limit by it's id. - - :type id: str - :param id: Name of limit to find. - :rtype: opencue.wrappers.limit.Limit - :return: The limit found by id. + return Limit( + self.stub.Find(limit_pb2.LimitFindRequest(name=name), timeout=Cuebot.Timeout).limit) + + def get(self, limit_id): + """Returns an existing limit by its id. + + :type limit_id: str + :param limit_id: id of limit to find + :rtype: opencue.wrappers.limit.Limit + :return: the limit found by id. """ - return Limit(self.stub.Get(limit_pb2.LimitGetRequest(id=id), timeout=Cuebot.Timeout).limit) + return Limit( + self.stub.Get(limit_pb2.LimitGetRequest(id=limit_id), timeout=Cuebot.Timeout).limit) def rename(self, newName): - """Rename the current limit to the provided newName. - - :type newName: str - :param newName: Name to rename the limit to. + """Renames the limit. + + :type newName: str + :param newName: new limit name """ self.stub.Rename(limit_pb2.LimitRenameRequest(old_name=self.name(), new_name=newName), timeout=Cuebot.Timeout) self._update() def setMaxValue(self, maxValue): - """Set the max value of an existing limit. - - :type maxValue: int - :param maxValue: Max value number to set limit to. + """Sets the maximum value of an existing limit. + + :type maxValue: int + :param maxValue: new limit maximum """ - self.stub.SetMaxValue(limit_pb2.LimitSetMaxValueRequest(name=self.name(), max_value=maxValue), - timeout=Cuebot.Timeout) + self.stub.SetMaxValue( + limit_pb2.LimitSetMaxValueRequest(name=self.name(), max_value=maxValue), + timeout=Cuebot.Timeout) self._update() def _update(self): - """Update the current data object from the DB.""" + """Updates the current data object from the database.""" self.data = self.stub.Get(limit_pb2.LimitGetRequest(id=self.id()), timeout=Cuebot.Timeout) def id(self): + """Returns the limit id. + + :rtype: str + :return: the limit id + """ return self.data.id def name(self): + """Returns the limit name. + + :rtype: str + :return: the limit name + """ if hasattr(self.data, 'name'): return self.data.name - else: - return "" + return "" def maxValue(self): + """Returns the limit maximum. + + :rtype: int + :return: the limit maximum + """ if hasattr(self.data, 'max_value'): return self.data.max_value - else: - return -1 + return -1 def currentRunning(self): + """Returns the current amount of the limit in use. + + :rtype: int + :return: current limit usage + """ if hasattr(self.data, 'current_running'): return self.data.current_running - else: - return -1 + return -1 diff --git a/pycue/opencue/wrappers/owner.py b/pycue/opencue/wrappers/owner.py index f4ab9f21f..c7896d88a 100644 --- a/pycue/opencue/wrappers/owner.py +++ b/pycue/opencue/wrappers/owner.py @@ -12,81 +12,99 @@ # See the License for the specific language governing permissions and # limitations under the License. +"""Module for classes related to owners.""" -""" -Project: opencue Library - -Module: owner.py - opencue Library implementation of a owner - -""" - -import opencue.wrappers.deed -import opencue.wrappers.host from opencue import Cuebot from opencue.compiled_proto import host_pb2 +import opencue.wrappers.deed +import opencue.wrappers.host class Owner(object): """This class contains the grpc implementation related to an Owner.""" def __init__(self, owner=None): - """Host class initialization""" self.data = owner self.stub = Cuebot.getStub('owner') def delete(self): - """Delete the owner record""" + """Deletes the owner record.""" self.stub.Delete(host_pb2.OwnerDeleteRequest(owner=self.data), timeout=Cuebot.Timeout) def getDeeds(self): - """Return the list of deeds for the owner. + """Returns the list of deeds for the owner. - :rtype: List - :return: The list of deeds associated with this owner.""" + :rtype: list + :return: the list of deeds associated with this owner + """ response = self.stub.GetDeeds(host_pb2.OwnerGetDeedsRequest(owner=self.data), timeout=Cuebot.Timeout) return [opencue.wrappers.deed.Deed(deed) for deed in response.deeds.deeds] def getHosts(self): - """Get a list of all hosts this owner is responsible for. + """Returns a list of all hosts this owner is responsible for. - :rtype: List - :return: List of hosts the owned by this owner.""" + :rtype: list + :return: list of hosts owned by this owner + """ response = self.stub.GetHosts(host_pb2.OwnerGetHostsRequest(owner=self.data), timeout=Cuebot.Timeout) return [opencue.wrappers.host.Host(host) for host in response.hosts.hosts] def getOwner(self, name): - """Return an owner by name. + """Returns an owner by name. - :type: str - :param: Name of the owner - :rtype: opencue.wrappers.owner.Owner - :return: Owner that matches the specified name""" + :type name: str + :param name: Name of the owner + :rtype: opencue.wrappers.owner.Owner + :return: owner that matches the specified name + """ return Owner(self.stub.GetOwner(host_pb2.OwnerGetOwnerRequest(name=name), timeout=Cuebot.Timeout).owner) def setShow(self, show): - """Set the show for the owner. + """Sets the show for the owner. - :type: str - :param: name of the show""" + :type show: str + :param show: name of the show + """ self.stub.SetShow(host_pb2.OwnerSetShowRequest(owner=self.data, show=show), timeout=Cuebot.Timeout) def takeOwnership(self, host): - """Set the hosts new owner settings.""" + """Sets the hosts for the owner. + + :type host: str + :param host: the name of the host to take ownership of + """ self.stub.TakeOwnership(host_pb2.OwnerTakeOwnershipRequest(owner=self.data, host=host), timeout=Cuebot.Timeout) def hostCount(self): + """Returns the number of hosts owned by this owner. + + :rtype: int + :return: number of hosts owned by this owner + """ return self.data.host_count def id(self): + """Returns the owner id. + + :rtype: str + :return: the owner id""" return self.data.id def name(self): + """Returns the owner name. + + :rtype: str + :return: the owner name""" return self.data.name def show(self): + """Returns the name of the show of the owner. + + :rtype: str + :return: the name of the show of the owner""" return self.data.show diff --git a/pycue/opencue/wrappers/proc.py b/pycue/opencue/wrappers/proc.py index 14e5c44da..da8ab2fae 100644 --- a/pycue/opencue/wrappers/proc.py +++ b/pycue/opencue/wrappers/proc.py @@ -12,14 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. - - -""" -Project: opencue Library - -Module: proc.py - opencue Library implementation of a proc - -""" +"""Module for classes related to procs.""" import enum @@ -32,13 +25,18 @@ class Proc(object): - """This class contains the grpc implementation related to a Proc.""" + """This class contains the grpc implementation related to a Proc. + + A proc is a bookable unit of a host. Hosts may contain many procs; each proc can be assigned + a different frame to work on.""" class RedirectType(enum.IntEnum): + """Represents the type of a proc redirect.""" JOB_REDIRECT = host_pb2.JOB_REDIRECT GROUP_REDIRECT = host_pb2.GROUP_REDIRECT class RunState(enum.IntEnum): + """Represents the current state of a proc.""" IDLE = host_pb2.IDLE BOOKED = host_pb2.BOOKED @@ -47,50 +45,56 @@ def __init__(self, proc=None): self.stub = Cuebot.getStub('proc') def kill(self): - """Kill the frame running on this proc""" + """Kills the frame running on this proc.""" response = self.stub.Kill(host_pb2.ProcKillRequest(proc=self.data), timeout=Cuebot.Timeout) return response def unbook(self, kill=False): - """Unbook the current frame. If the value of kill is true, - the frame will be immediately killed. + """Unbooks the current frame from this proc. + + :type kill: bool + :param kill: if true, the frame will be immediately killed """ - response = self.stub.Unbook(host_pb2.ProcUnbookRequest(proc=self.data, kill=kill), - timeout=Cuebot.Timeout) + response = self.stub.Unbook( + host_pb2.ProcUnbookRequest(proc=self.data, kill=kill), timeout=Cuebot.Timeout) return response def getHost(self): - """Return the host this proc is allocated from. + """Returns the host this proc is allocated from. :rtype: opencue.wrappers.host.Host - :return: The host this proc is allocated from.""" + :return: the host this proc is allocated from + """ response = self.stub.GetHost(host_pb2.ProcGetHostRequest(proc=self.data), timeout=Cuebot.Timeout) return opencue.wrappers.host.Host(response.host) def getFrame(self): - """Return the frame this proc is running. + """Returns the frame this proc is running. :rtype: opencue.wrappers.frame.Frame - :return: The fame this proc is running.""" + :return: the frame this proc is running + """ response = self.stub.GetFrame(host_pb2.ProcGetFrameRequest(proc=self.data), timeout=Cuebot.Timeout) return opencue.wrappers.frame.Frame(response.frame) def getLayer(self): - """Return the layer this proc is running. + """Returns the layer this proc is running. :rtype: opencue.wrappers.layer.Layer - :return: The layer this proc is running.""" + :return: the layer this proc is running + """ response = self.stub.GetLayer(host_pb2.ProcGetLayerRequest(proc=self.data), timeout=Cuebot.Timeout) return opencue.wrappers.layer.Layer(response.layer) def getJob(self): - """Return the job this proc is running. + """Returns the job this proc is running. :rtype: opencue.wrappers.job.Job - :return: The job this proc is running.""" + :return: the job this proc is running + """ response = self.stub.GetJob(host_pb2.ProcGetJobRequest(proc=self.data), timeout=Cuebot.Timeout) return opencue.wrappers.job.Job(response.job) @@ -99,72 +103,87 @@ def id(self): """Returns the id of the proc. :rtype: str - :return: Proc uuid""" + :return: id of the proc + """ return self.data.id def name(self): """Returns the name of the proc. :rtype: str - :return: Proc name""" + :return: name of the proc + """ return self.data.name def jobName(self): - """Returns the job name of the frame running on the proc. + """Returns the name of the job of the frame running on the proc. :rtype: str - :return: Job name""" + :return: name of the current job""" return self.data.job_name def frameName(self): """Returns the name of the frame on the proc. :rtype: str - :return: Frame name""" + :return: name of the current frame + """ return self.data.frame_name def showName(self): - """Returns the name of the show whos frame is running on the proc. + """Returns the name of the show of the frame running on the proc. :rtype: str - :return: Frames show name""" + :return: name of the current show + """ return self.data.show_name def coresReserved(self): """The number of cores reserved for this frame. :rtype: float - :return: Cores reserved for the running frame""" + :return: cores reserved for the running frame + """ return self.data.reserved_cores def memReserved(self): """The amount of memory reserved for the running frame. :rtype: int - :return: Kb memory reserved for the running frame""" + :return: memory reserved for the running frame in kB + """ return self.data.reserved_memory def memUsed(self): """The amount of memory used by the running frame. :rtype: int - :return: Kb memory used by the running frame""" + :return: memory used by the running frame in kB + """ return self.data.used_memory - + def bookedTime(self): - """The last time this proc was assigned to a job in epoch seconds. - :rtype: int""" + """The last time this proc was booked to a job. + + :rtype: int + :return: last time booked as an epoch + """ return self.data.booked_time def dispatchTime(self): - """The last time this proc was assigned to a job in epoch seconds. - :rtype: int""" + """The last time this proc was dispatched work. + + :rtype: int + :return: last time dispatched as an epoch + """ return self.data.dispatch_time - + def isUnbooked(self): - """Returns true if this proc is unbooked. + """Returns whether this proc is unbooked. - :rtype: boolean""" + :rtype: bool + :return: whether the proc is unbooked + """ return self.data.unbooked @@ -173,9 +192,10 @@ class NestedProc(Proc): def __init__(self, nestedProc): super(NestedProc, self).__init__(nestedProc) - ## job children are most likely empty but its possible to - ## populate this with NestedLayer objects. + # job children are most likely empty but its possible to + # populate this with NestedLayer objects. self.__children = [] def children(self): + """Returns children of the proc.""" return self.__children diff --git a/pycue/opencue/wrappers/service.py b/pycue/opencue/wrappers/service.py index 35e8c5db6..acacb233a 100644 --- a/pycue/opencue/wrappers/service.py +++ b/pycue/opencue/wrappers/service.py @@ -12,14 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. - - -""" -Project: opencue Library - -Module: service.py - opencue Library implementation of a service - -""" +"""Module for classes related to services.""" import grpc @@ -35,18 +28,21 @@ def __init__(self, service=None): self.stub = Cuebot.getStub('service') def create(self): + """Creates a service in the database using the current instance data.""" response = self.stub.CreateService( service_pb2.ServiceCreateServiceRequest(data=self.data), timeout=Cuebot.Timeout) return Service(response.service) def delete(self): + """Deletes the service.""" return self.stub.Delete( service_pb2.ServiceDeleteRequest(service=self.data), timeout=Cuebot.Timeout) @staticmethod def getDefaultServices(): + """Returns the default services.""" response = Cuebot.getStub('service').GetDefaultServices( service_pb2.ServiceGetDefaultServicesRequest(), timeout=Cuebot.Timeout) @@ -54,17 +50,25 @@ def getDefaultServices(): @staticmethod def getService(name): + """Returns a service by name. + + :type name: str + :param name: service name to find + """ try: response = Cuebot.getStub('service').GetService( service_pb2.ServiceGetServiceRequest(name=name), timeout=Cuebot.Timeout) except grpc.RpcError as e: + # pylint: disable=no-member if e.code() == grpc.StatusCode.NOT_FOUND: return None + # pylint: enable=no-member raise e return Service(response.service) def update(self): + """Updates the service database record with the current instance data.""" return self.stub.Update( service_pb2.ServiceUpdateRequest(service=self.data), timeout=Cuebot.Timeout) @@ -73,102 +77,118 @@ def id(self): """Returns the id of the service. :rtype: str - :return: Frame uuid""" + :return: service id + """ return self.data.id def name(self): """Returns the name of the service. :rtype: str - :return: service name""" + :return: service name + """ return self.data.name def setName(self, name): - """Set the name field of the message. + """Sets the service name. :type: string - :param: name to set""" + :param: new service name + """ self.data.name = name def threadable(self): - """Returns if the service is threadable. + """Returns whether the service is threadable. :rtype: bool - :return: is service threadable""" + :return: whether service is threadable + """ return self.data.threadable def setThreadable(self, threadable): - """Set the threadabel field of the message. + """Sets the threadable field of the service. - :type: bool - :param: whether or not the service should be threadable""" + :type: bool + :param: whether or not the service should be threadable + """ self.data.threadable = threadable def minCores(self): - """Returns the min_cores of the service. + """Returns the minimum cores of the service. :rtype: int - :return: min_cores""" + :return: min cores + """ return self.data.min_cores def setMinCores(self, minCores): - """Set the minCores field of the message. + """Sets the minimum cores of the service. :type: int - :param: min_cores""" + :param: new min cores + """ self.data.min_cores = minCores def maxCores(self): - """Returns the max_cores of the service. + """Returns the maximum cores of the service. :rtype: int - :return: max_cores""" + :return: max cores + """ return self.data.max_cores def setMaxCores(self, maxCores): - """Set the maxCores field of the message. + """Sets the maximum cores of the service. :type: int - :param: max_cores""" + :param: new max cores + """ self.data.max_cores = maxCores def minMemory(self): - """Returns the min_memory of the service. + """Returns the minimum memory of the service. :rtype: int - :return: min_memory""" + :return: min memory + """ return self.data.min_memory def setMinMemory(self, minMemory): - """Set the minMemory field of the message. + """Sets the minimum memory field of the service. :type: int - :param: min_memory""" + :param: new min memory + """ self.data.min_memory = minMemory def minGpu(self): - """Returns the min_gpu of the service. + """Returns the minimum gpu of the service. :rtype: int - :return: min_gpu""" + :return: min gpu + """ return self.data.min_gpu def setMinGpu(self, minGpu): - """Set the minGpu field of the message. + """Sets the minimum gpu of the service. :type: int - :param: min_gpu""" + :param: new min gpu + """ self.data.min_gpu = minGpu def tags(self): """Returns the list of tags for the service. :rtype: list - :return: tags""" + :return: list of service tags + """ return self.data.tags def setTags(self, tags): - """Clear and set the tags. - :type: list - :param: list of tags to set""" + """Clears and sets the service tags. + + :type: list + :param: new list of service tags + """ self.data.tags[:] = tags diff --git a/pycue/opencue/wrappers/show.py b/pycue/opencue/wrappers/show.py index 8ab4fce15..750d05645 100644 --- a/pycue/opencue/wrappers/show.py +++ b/pycue/opencue/wrappers/show.py @@ -12,14 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. - - -""" -Project: opencue Library - -Module: show.py - opencue Library implementation of a show - -""" +"""Module for classes related to shows.""" from opencue.compiled_proto import show_pb2 from opencue.cuebot import Cuebot @@ -36,28 +29,31 @@ def __init__(self, show=None): self.stub = Cuebot.getStub('show') def createOwner(self, user): - """Creates a new owner. + """Creates a new owner for the show. - :type user: str + :type user: str :param user: user name - :rtype: Owner - :return: The created owner object + :rtype: host_pb2.Owner + :return: the created owner object """ response = self.stub.CreateOwner(show_pb2.ShowCreateOwnerRequest(show=self.data, name=user), timeout=Cuebot.Timeout) return response.owner def createSubscription(self, allocation, size, burst): - """Creates a new subscription. - - :type allocation: opencue.wrappers.allocation.Allocation - :param allocation: Allocation object - :type size: float - :param size: Allocation size - :type burst: float - :param burst: Allocation burst - :rtype: Subscription - :return: The created subscription object + """Creates a new subscription for the show. + + A subscription links a show to an allocation, and determines how many cores the show + can utilize within that allocation. + + :type allocation: opencue.wrappers.allocation.Allocation + :param allocation: allocation to subscribe to + :type size: float + :param size: number of cores the show is allowed to use consistently + :type burst: float + :param burst: number of cores the show is allowed to burst to + :rtype: opencue.wrappers.subscription.Subscription + :return: the created subscription object """ response = self.stub.CreateSubscription(show_pb2.ShowCreateSubscriptionRequest( show=self.data, allocation_id=allocation.id(), size=size, burst=burst), @@ -65,36 +61,36 @@ def createSubscription(self, allocation, size, burst): return opencue.wrappers.subscription.Subscription(response.subscription) def delete(self): - """Delete this show""" + """Deletes this show.""" self.stub.Delete(show_pb2.ShowDeleteRequest(show=self.data), timeout=Cuebot.Timeout) def createServiceOverride(self, data): """Creates a Service Override at the show level. - :type data: opencue.wrapper.service.Service - :param data: Service.data object + :type data: service_pb2.Service + :param data: service data, typically from opencue.wrappers.service.Service.data """ - self.stub.CreateServiceOverride(show_pb2.ShowCreateServiceOverrideRequest( - show=self.data, service=data), - timeout=Cuebot.Timeout) + self.stub.CreateServiceOverride( + show_pb2.ShowCreateServiceOverrideRequest(show=self.data, service=data), + timeout=Cuebot.Timeout) def getServiceOverride(self, serviceName): - """ - Returns a service override for a show + """Returns a service override for a show. + :type serviceName: str :param serviceName: name of the service for the show + :rtype: service_pb2.ServiceOverride :return: service override object """ - serviceOverride = self.stub.GetServiceOverride(show_pb2.ShowGetServiceOverrideRequest( - show=self.data, name=serviceName), - timeout=Cuebot.Timeout).service_override - return serviceOverride + return self.stub.GetServiceOverride( + show_pb2.ShowGetServiceOverrideRequest(show=self.data, name=serviceName), + timeout=Cuebot.Timeout).service_override def getServiceOverrides(self): """Returns a list of service overrides on the show. - :rtype: list - :return: a list of service override objects + :rtype: list + :return: list of service overrides on the show """ serviceOverrideSeq = self.stub.GetServiceOverrides( show_pb2.ShowGetServiceOverridesRequest(show=self.data), @@ -102,22 +98,25 @@ def getServiceOverrides(self): return serviceOverrideSeq.service_overrides def getSubscriptions(self): - """Returns a list of all subscriptions. + """Returns a list of all subscriptions the show has. - :rtype: list - :return: A list of subscription objects + :rtype: list + :return: list of the show's subscriptions """ - response = self.stub.GetSubscriptions(show_pb2.ShowGetSubscriptionRequest( - show=self.data), - timeout=Cuebot.Timeout) + response = self.stub.GetSubscriptions( + show_pb2.ShowGetSubscriptionRequest(show=self.data), timeout=Cuebot.Timeout) subscriptionSeq = response.subscriptions - return [opencue.wrappers.subscription.Subscription(subs) for subs in subscriptionSeq.subscriptions] + return [opencue.wrappers.subscription.Subscription(subs) + for subs in subscriptionSeq.subscriptions] - def findSubscription(self, name): + @staticmethod + def findSubscription(name): """Returns the matching subscription. - :rtype: opencue.wrappers.subscription.Subscription - :return: The matching subscription + :type name: str + :param name: name of subscription to find + :rtype: opencue.wrappers.subscription.Subscription + :return: the matching subscription """ subscriptions = opencue.wrappers.subscription.Subscription() return subscriptions.find(name) @@ -125,31 +124,29 @@ def findSubscription(self, name): def getFilters(self): """Returns the job filters for this show. - :rtype: list - :return: List of Filter wrapper objects for this show. + :rtype: list + :return: list of filters for this show """ - response = self.stub.GetFilters(show_pb2.ShowGetFiltersRequest( - show=self.data), - timeout=Cuebot.Timeout) + response = self.stub.GetFilters( + show_pb2.ShowGetFiltersRequest(show=self.data), timeout=Cuebot.Timeout) filterSeq = response.filters return [opencue.wrappers.filter.Filter(filter) for filter in filterSeq.filters] def setActive(self, value): - """Set the active state of this show to value. + """Sets whether this show is active. - :type value: bool - :param value: boolean value to set active state to + :type value: bool + :param value: whether the show is active """ self.stub.SetActive(show_pb2.ShowSetActiveRequest(show=self.data, value=value), timeout=Cuebot.Timeout) def setDefaultMaxCores(self, maxcores): - """Sets the default maximum number of cores - that new jobs are launched with. + """Sets the default maximum number of cores that new jobs are launched with. - :type: float - :param: value to set maxCores to - :rtype: show_pb2.ShowSetDefaultMaxCoresResponse + :type maxcores: float + :param maxcores: new maximum number of cores for new jobs + :rtype: show_pb2.ShowSetDefaultMaxCoresResponse :return: response is empty """ response = self.stub.SetDefaultMaxCores(show_pb2.ShowSetDefaultMaxCoresRequest( @@ -158,12 +155,11 @@ def setDefaultMaxCores(self, maxcores): return response def setDefaultMinCores(self, mincores): - """Sets the default minimum number of cores - all new jobs are launched with. + """Sets the default minimum number of cores new jobs are launched with. - :type: float - :param: value to set minCores to - :rtype: show_pb2.ShowSetDefaultMinCoresResponse + :type mincores: float + :param mincores: new minimum number of cores for new jobs + :rtype: show_pb2.ShowSetDefaultMinCoresResponse :return: response is empty """ response = self.stub.SetDefaultMinCores(show_pb2.ShowSetDefaultMinCoresRequest( @@ -172,34 +168,34 @@ def setDefaultMinCores(self, mincores): return response def findFilter(self, name): - """Find the filter by name. + """Finds a filter by name. - :type: string - :param: name of filter to find - :rtype: opencue.wrappers.filter.Filter - :return: filter wrapper of found filter + :type name: string + :param name: name of filter to find + :rtype: opencue.wrappers.filter.Filter + :return: matching filter """ response = self.stub.FindFilter(show_pb2.ShowFindFilterRequest( show=self.data, name=name), timeout=Cuebot.Timeout) return opencue.wrappers.filter.Filter(response.filter) def createFilter(self, name): - """Create a filter on the show. + """Creates a filter on the show. - :type: string - :param: Name of the filter to create - :rtype: show_pb2.ShowCreateFilterResponse - :return: response is empty + :type name: str + :param name: name of the filter to create + :rtype: opencue.wrappers.filter.Filter + :return: the new filter object """ response = self.stub.CreateFilter(show_pb2.ShowCreateFilterRequest( show=self.data, name=name), timeout=Cuebot.Timeout) return opencue.wrappers.filter.Filter(response.filter) def getGroups(self): - """Get the groups for this show. + """Gets the groups for the show. - :rtype: list - :return: list of group wrappers for this show + :rtype: list + :return: list of groups for this show """ response = self.stub.GetGroups(show_pb2.ShowGetGroupsRequest( show=self.data), @@ -208,10 +204,10 @@ def getGroups(self): return [opencue.wrappers.group.Group(grp) for grp in groupSeq.groups] def getJobWhiteboard(self): - """Get the whiteboard for the show. + """Gets the whiteboard for the show. - :rtype: NestedGroup - :return: gRPC NestedGroup whiteboard for the show + :rtype: job_pb2.NestedGroup + :return: NestedGroup whiteboard for the show """ response = self.stub.GetJobWhiteboard(show_pb2.ShowGetJobWhiteboardRequest( show=self.data), @@ -219,10 +215,10 @@ def getJobWhiteboard(self): return response.whiteboard def getRootGroup(self): - """Get the root group for the show. + """Gets the root group for the show. - :rtype: opencue.wrappers.group.Group - :return: Group wrapper of the root group + :rtype: opencue.wrappers.group.Group + :return: the root group """ response = self.stub.GetRootGroup(show_pb2.ShowGetRootGroupRequest( show=self.data), @@ -230,12 +226,12 @@ def getRootGroup(self): return opencue.wrappers.group.Group(response.group) def enableBooking(self, value): - """Enable booking on the show. + """Enables or disables booking on the show. - :type: Boolean - :param: Whether or not to enable booking - :rtype: show_pb2.ShowEnableBookingResponse - :return: Response is empty + :type value: bool + :param value: whether to enable booking + :rtype: show_pb2.ShowEnableBookingResponse + :return: response is empty """ response = self.stub.EnableBooking(show_pb2.ShowEnableBookingRequest( show=self.data, @@ -244,12 +240,12 @@ def enableBooking(self, value): return response def enableDispatching(self, value): - """Enable dispatching on the show. + """Enables or disables dispatching on the show. - :type: Boolean - :param: Whether or not to enable booking - :rtype: show_pb2.ShowEnableDispatchingResponse - :return: Response is empty + :type value: bool + :param value: whether to enable booking + :rtype: show_pb2.ShowEnableDispatchingResponse + :return: response is empty """ response = self.stub.EnableDispatching(show_pb2.ShowEnableDispatchingRequest( show=self.data, @@ -258,39 +254,39 @@ def enableDispatching(self, value): return response def id(self): - """Returns the id of the show. + """Returns the show id. - :rtype: str - :return: Frame uuid + :rtype: str + :return: id of the show """ return self.data.id def name(self): - """Returns the name of the show. + """Returns the show name. - :rtype: str - :return: Show name + :rtype: str + :return: name of the show """ return self.data.name def pendingJobs(self): - """Total number of pending jobs. + """Returns the total number of pending jobs on the show. - :rtype: int - :return: the total number of pending jobs + :rtype: int + :return: total number of pending jobs """ return self.data.show_stats.pending_jobs def pendingFrames(self): - """Total number of running frames currently in the queue. + """Returns the total number of running frames currently in the queue. - :rtype: int + :rtype: int :return: the total number of pending frames """ return self.data.show_stats.pending_frames def runningFrames(self): - """Total number of running frames currently in the queue. + """Returns the total number of running frames currently in the queue. :rtype: int :return: the total number of running frames @@ -298,17 +294,17 @@ def runningFrames(self): return self.data.show_stats.running_frames def deadFrames(self): - """Total number of dead frames currently in the queue. + """Returns the total number of dead frames currently in the queue. - :rtype: int + :rtype: int :return: the total number dead frames """ return self.data.show_stats.dead_frames def reservedCores(self): - """Total number of reserved cores by all frames. + """Returns the total number of reserved cores by all frames. - :rtype: float + :rtype: float :return: the total number of reserved cores """ return self.data.show_stats.reserved_cores @@ -316,23 +312,23 @@ def reservedCores(self): def defaultMinProcs(self): """Returns the default minProcs that new jobs are set to. - :rtype: int - :return: Default minProcs value for new jobs + :rtype: int + :return: default minProcs value for new jobs """ return self.data.default_min_procs def defaultMaxProcs(self): """Returns the default maxProcs that new jobs are set to. - :rtype: int - :return: Default maxProcs value for new jobs + :rtype: int + :return: default maxProcs value for new jobs """ return self.data.default_max_procs - + def totalJobsCreated(self): """A running counter of jobs launched. - :rtype: int + :rtype: int :return: total number of jobs created """ return self.data.show_stats.created_job_count @@ -340,9 +336,7 @@ def totalJobsCreated(self): def totalFramesCreated(self): """A running counter of frames launched. - :rtype: int + :rtype: int :return: total number of frames created """ return self.data.show_stats.created_frame_count - - diff --git a/pycue/opencue/wrappers/subscription.py b/pycue/opencue/wrappers/subscription.py index 25aa6c23e..057067e3c 100644 --- a/pycue/opencue/wrappers/subscription.py +++ b/pycue/opencue/wrappers/subscription.py @@ -12,50 +12,73 @@ # See the License for the specific language governing permissions and # limitations under the License. - -""" -Project: opencue Library - -Module: subscription.py - opencue Library implementation of a subscription - -""" +"""Module for classes related to subscriptions.""" from opencue.compiled_proto import subscription_pb2 from opencue.cuebot import Cuebot class Subscription(object): - """This class contains the grpc implementation related to a Subscription.""" + """This class contains the grpc implementation related to a Subscription. + + A subscription associates a show with an allocation. It allows the show to utilize resources + within that allocation and determines the amount of resources the show is allowed to use at + any given time.""" def __init__(self, subscription=None): self.data = subscription self.stub = Cuebot.getStub('subscription') def find(self, name): + """Returns a subscription by name. + + :type name: str + :param name: name of subscription to find + :rtype: opencue.wrappers.subscription.Subscription + :return: the named subscription + """ response = self.stub.Find( subscription_pb2.SubscriptionFindRequest(name=name), timeout=Cuebot.Timeout) return Subscription(response.subscription) - def get(self, id): + def get(self, subscription_id): + """Returns a subscription by id. + + :type subscription_id: str + :param subscription_id: id of subscription to get + :rtype: opencue.wrappers.subscription.Subscription + :return: the subscription of the id + """ response = self.stub.Get( - subscription_pb2.SubscriptionGetRequest(id=id), + subscription_pb2.SubscriptionGetRequest(id=subscription_id), timeout=Cuebot.Timeout) return Subscription(response.subscription) def setSize(self, size): + """Sets subscription size; the number of cores the show is allowed to use consistently. + + :type size: int + :param size: the new subscription size + """ assert (isinstance(size, int)), "size is not expected type: int" self.stub.SetSize( subscription_pb2.SubscriptionSetSizeRequest(subscription=self.data, new_size=size), timeout=Cuebot.Timeout) def setBurst(self, burst): + """Sets subscription burst size; the number of cores the show is allowed to burst to. + + :type burst: int + :param burst: the new burst size + """ assert (isinstance(burst, int)), "burst is not expected type: int" self.stub.SetBurst( subscription_pb2.SubscriptionSetBurstRequest(subscription=self.data, burst=burst), timeout=Cuebot.Timeout) def delete(self): + """Deletes a subscription.""" self.stub.Delete( subscription_pb2.SubscriptionDeleteRequest(subscription=self.data), timeout=Cuebot.Timeout) @@ -64,48 +87,54 @@ def id(self): """Returns the id of the subscription. :rtype: str - :return: Frame uuid""" + :return: id of the subscription + """ return self.data.id def name(self): """Returns the name of the subscription. :rtype: str - :return: Subscription name""" + :return: name of the subscription + """ return self.data.name def size(self): """Returns the subscription size. :rtype: int - :return: Subscription size""" + :return: subscription size + """ return self.data.size def burst(self): - """Returns the subscription burst. + """Returns the subscription burst size. :rtype: int - :return: Allowed burst""" + :return: subscription burst size + """ return self.data.burst def reservedCores(self): - """Returns the current number reserved in this subscription. + """Returns the current number of cores reserved in this subscription. :rtype: float - :return: Total running cores""" + :return: reserved cores + """ return self.data.reserved_cores def show(self): - """Returns the show that this subscription is for. + """Returns the name of the show that this subscription is for. :rtype: str - :return: The show that this subscription is for""" + :return: the name of the show that this subscription is for + """ return self.data.show_name def allocation(self): - """Returns the allocation that this subscription is subscribed to. + """Returns the allocation that this subscription is for. :rtype: str - :return: The allocation subscribed to""" + :return: the allocation subscribed to + """ return self.data.allocation_name - diff --git a/pycue/opencue/wrappers/task.py b/pycue/opencue/wrappers/task.py index c2246f4bc..356e942f3 100644 --- a/pycue/opencue/wrappers/task.py +++ b/pycue/opencue/wrappers/task.py @@ -12,13 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. - -""" -Project: opencue Library - -Module: task.py - opencue Library implementation of a task - -""" +"""Module for classes related to tasks.""" from opencue.compiled_proto import task_pb2 from opencue.cuebot import Cuebot @@ -32,18 +26,23 @@ def __init__(self, task=None): self.stub = Cuebot.getStub('task') def id(self): - """Returns the task's unique id""" + """Returns the unique id of the task. + + :rtype: str + :return: task id + """ return self.data.id def setMinCores(self, minCores): """Sets the minimum amount of cores for the task. :type minCores: int - :param minCores: the minimum number of cores the task needs""" + :param minCores: the minimum number of cores the task needs + """ self.stub.SetMinCores( task_pb2.TaskSetMinCoresRequest(task=self.data, new_min_cores=minCores), timeout=Cuebot.Timeout) def delete(self): - """Deletes this task""" + """Deletes the task.""" self.stub.Delete(task_pb2.TaskDeleteRequest(task=self.data), timeout=Cuebot.Timeout) diff --git a/pycue/opencue/wrappers/util.py b/pycue/opencue/wrappers/util.py index 20c8068a9..aa3f164d8 100644 --- a/pycue/opencue/wrappers/util.py +++ b/pycue/opencue/wrappers/util.py @@ -12,43 +12,55 @@ # See the License for the specific language governing permissions and # limitations under the License. - -""" -Project: opencue Library - -Module: util.py - opencue Library utility - -""" +"""Utility methods used by the wrapper classes.""" import time +# pylint: disable=redefined-builtin def format_time(epoch, format="%m/%d %H:%M", default="--/-- --:--"): - """Formats time using time formatting standards - see: https://docs.python.org/3/library/time.html""" + """Formats time using time formatting standards. + + See: https://docs.python.org/3/library/time.html + + :type epoch: int + :param epoch: time as an epoch + :type format: str + :param format: desired format of output string + :type default: str + :param default: the output if the given time is empty + :rtype: str + :return: string-formatted version of the given time + """ if not epoch: return default return time.strftime(format, time.localtime(epoch)) def dateToMMDDHHMM(sec): - """Returns date in the format %m/%d %H:%M + """Returns a time in the format `%m/%d %H:%M`. + :type sec: int + :param sec: time as an epoch :rtype: str - :return: Date in the format %m/%d %H:%M""" + :return: time in the format %m/%d %H:%M + """ if sec == 0: return "--/-- --:--" return time.strftime("%m/%d %H:%M", time.localtime(sec)) def __splitTime(sec): - """Returns time in the format H:MM:SS + """Splits a timestamp into hour, minute, and second components. - :rtype: str - :return: Time in the format H:MM:SS""" - min, sec = divmod(sec, 60) - hour, min = divmod(min, 60) - return (hour, min, sec) + :type sec: int + :param sec: timestamp as an epoch + :rtype: tuple + :return: (hour, min, sec) + """ + minute, sec = divmod(sec, 60) + hour, minute = divmod(minute, 60) + return hour, minute, sec def secondsToHHMMSS(sec): @@ -76,14 +88,15 @@ def secondsToHHHMM(sec): def secondsDiffToHMMSS(secA, secB): - """Returns time difference of arguements in the format H:MM:SS + """Returns time difference of arguments in the format H:MM:SS :type secA: int or float - :param secA: Seconds. 0 will be replaced with current time + :param secA: seconds. 0 will be replaced with current time :type secB: int or float - :param secB: Seconds. 0 will be replaced with current time + :param secB: seconds. 0 will be replaced with current time :rtype: str - :return: Time difference of arguments in the format H:MM:SS""" + :return: Time difference of arguments in the format H:MM:SS + """ if secA == 0: secA = time.time() if secB == 0: @@ -92,6 +105,13 @@ def secondsDiffToHMMSS(secA, secB): def convert_mem(kmem, unit=None): + """Returns an amount of memory in a human-readable string. + + :type kmem: int + :param kmem: amount of memory in kB + :rtype: str + :return: same amount of memory formatted into a human-readable string + """ k = 1024 if unit == 'K' or (unit is None and kmem < k): return '%dK' % kmem @@ -99,3 +119,4 @@ def convert_mem(kmem, unit=None): return '%dM' % (kmem / k) if unit == 'G' or (unit is None and kmem < pow(k, 3)): return '%.01fG' % (float(kmem) / pow(k, 2)) + return str(kmem) diff --git a/pycue/tests/api_test.py b/pycue/tests/api_test.py index 20c130e1d..0d05246c4 100644 --- a/pycue/tests/api_test.py +++ b/pycue/tests/api_test.py @@ -14,14 +14,16 @@ # See the License for the specific language governing permissions and # limitations under the License. +"""Tests for `opencue.api`.""" from __future__ import print_function from __future__ import division from __future__ import absolute_import -import mock import unittest -import opencue +import mock + +import opencue.api from opencue.compiled_proto import cue_pb2 from opencue.compiled_proto import depend_pb2 from opencue.compiled_proto import facility_pb2 @@ -639,12 +641,12 @@ def testFindFilter(self, getStubMock): filter=filter_pb2.Filter(name=filterName)) getStubMock.return_value = stubMock - filter = opencue.api.findFilter(TEST_SHOW_NAME, filterName) + filterReturned = opencue.api.findFilter(TEST_SHOW_NAME, filterName) stubMock.FindFilter.assert_called_with( filter_pb2.FilterFindFilterRequest(show=TEST_SHOW_NAME, name=filterName), timeout=mock.ANY) - self.assertEqual(filterName, filter.name()) + self.assertEqual(filterName, filterReturned.name()) class AllocTests(unittest.TestCase): @@ -668,7 +670,8 @@ def testCreateAlloc(self, getStubMock): def testGetAllocs(self, getStubMock): stubMock = mock.Mock() stubMock.GetAll.return_value = facility_pb2.AllocGetAllResponse( - allocations=facility_pb2.AllocationSeq(allocations=[facility_pb2.Allocation(name=TEST_ALLOC_NAME)])) + allocations=facility_pb2.AllocationSeq( + allocations=[facility_pb2.Allocation(name=TEST_ALLOC_NAME)])) getStubMock.return_value = stubMock allocs = opencue.api.getAllocations() @@ -775,17 +778,17 @@ def testGetProcs(self, getStubMock): self.assertEqual([TEST_PROC_NAME], [proc.name() for proc in procs]) -class Limittests(unittest.TestCase): - +class LimitTests(unittest.TestCase): + @mock.patch('opencue.cuebot.Cuebot.getStub') def testCreateLimit(self, getStubMock): stubMock = mock.Mock() stubMock.Create.return_value = limit_pb2.LimitCreateResponse() getStubMock.return_value = stubMock - + testLimitValue = 42 opencue.api.createLimit(TEST_LIMIT_NAME, testLimitValue) - + stubMock.Create.assert_called_with( limit_pb2.LimitCreateRequest(name=TEST_LIMIT_NAME, max_value=testLimitValue), timeout=mock.ANY) @@ -796,9 +799,9 @@ def testGetLimits(self, getStubMock): stubMock.GetAll.return_value = limit_pb2.LimitGetAllResponse( limits=[limit_pb2.Limit(name=TEST_LIMIT_NAME)]) getStubMock.return_value = stubMock - + limits = opencue.api.getLimits() - + stubMock.GetAll.assert_called_with(limit_pb2.LimitGetAllRequest(), timeout=mock.ANY) self.assertEqual(len(limits), 1) self.assertEqual(limits[0].name(), TEST_LIMIT_NAME) diff --git a/pycue/tests/file_sequence.py b/pycue/tests/file_sequence.py index 070bb5a4a..f03438f9c 100644 --- a/pycue/tests/file_sequence.py +++ b/pycue/tests/file_sequence.py @@ -14,6 +14,8 @@ # See the License for the specific language governing permissions and # limitations under the License. +"""Tests for `FileSequence`.""" + from __future__ import print_function from __future__ import division from __future__ import absolute_import @@ -155,7 +157,9 @@ class FrameSetTests(unittest.TestCase): def testMultipleSegments(self): result = FrameSet('57,1-3,4-2,12-15x2,76-70x-3,5-12y3,1-7:5') - self.assertEqual([57, 1, 2, 3, 4, 3, 2, 12, 14, 76, 73, 70, 6, 7, 9, 10, 12, 1, 6, 2, 4, 3, 5, 7], result.getAll()) + self.assertEqual( + [57, 1, 2, 3, 4, 3, 2, 12, 14, 76, 73, 70, 6, 7, 9, 10, 12, 1, 6, 2, 4, 3, 5, 7], + result.getAll()) def testSize(self): result = FrameSet('1-7') diff --git a/pycue/tests/search_test.py b/pycue/tests/search_test.py index 161a1709e..13e73046f 100644 --- a/pycue/tests/search_test.py +++ b/pycue/tests/search_test.py @@ -14,16 +14,18 @@ # See the License for the specific language governing permissions and # limitations under the License. +"""Tests for `opencue.search`.""" from __future__ import print_function from __future__ import division from __future__ import absolute_import -import mock import unittest -import opencue +import mock + from opencue.compiled_proto import job_pb2 from opencue.compiled_proto import host_pb2 +import opencue.search @mock.patch('opencue.cuebot.Cuebot.getStub') @@ -77,7 +79,7 @@ def testRaiseIfNotList(self, getStubMock): opencue.search.raiseIfNotList('user', 42) with self.assertRaises(TypeError): - opencue.search.raiseIfNotList('user', set(['iamnotalist'])) + opencue.search.raiseIfNotList('user', {'iamnotalist'}) self.assertIsNone(opencue.search.raiseIfNotList('user', ['iamnotalist'])) diff --git a/pycue/tests/util_test.py b/pycue/tests/util_test.py index 667f9bc6f..b76641851 100644 --- a/pycue/tests/util_test.py +++ b/pycue/tests/util_test.py @@ -14,18 +14,20 @@ # See the License for the specific language governing permissions and # limitations under the License. +"""Tests for `opencue.util`.""" from __future__ import print_function from __future__ import division from __future__ import absolute_import from builtins import range -import grpc -import mock import unittest import uuid -import opencue +import grpc +import mock + from opencue.compiled_proto import job_pb2 +import opencue.exception from opencue.wrappers.job import Job @@ -96,15 +98,16 @@ def testUnknownExceptionParser(self): @mock.patch('opencue.cuebot.Cuebot.getStub') def testProxyUniqueId(self, getStubMock): """convert a string and class name to proxy""" - id = 'A0000000-0000-0000-0000-000000000000' + objectId = 'A0000000-0000-0000-0000-000000000000' stubMock = mock.Mock() - stubMock.GetGroup.return_value = job_pb2.GroupGetGroupResponse(group=job_pb2.Group(id=id)) + stubMock.GetGroup.return_value = job_pb2.GroupGetGroupResponse( + group=job_pb2.Group(id=objectId)) getStubMock.return_value = stubMock - proxy = opencue.proxy(id, 'Group') + proxy = opencue.proxy(objectId, 'Group') - stubMock.GetGroup.assert_called_with(job_pb2.GroupGetGroupRequest(id=id)) - self.assertEqual(id, proxy.group.id) + stubMock.GetGroup.assert_called_with(job_pb2.GroupGetGroupRequest(id=objectId)) + self.assertEqual(objectId, proxy.group.id) @mock.patch('opencue.cuebot.Cuebot.getStub') def testProxyUniqueIdArray(self, getStubMock): diff --git a/pycue/tests/wrappers/allocation_test.py b/pycue/tests/wrappers/allocation_test.py index 203cfda6a..844423460 100644 --- a/pycue/tests/wrappers/allocation_test.py +++ b/pycue/tests/wrappers/allocation_test.py @@ -14,17 +14,20 @@ # See the License for the specific language governing permissions and # limitations under the License. +"""Tests for `opencue.wrappers.allocation`.""" from __future__ import print_function from __future__ import division from __future__ import absolute_import -import mock import unittest -import opencue +import mock + from opencue.compiled_proto import facility_pb2 from opencue.compiled_proto import host_pb2 from opencue.compiled_proto import subscription_pb2 +import opencue.wrappers.allocation +import opencue.wrappers.host TEST_ALLOC_NAME = 'test_allocation' @@ -101,13 +104,13 @@ def testReparentHostIds(self, getStubMock): stubMock = mock.Mock() stubMock.ReparentHosts.return_value = facility_pb2.AllocReparentHostsResponse() getStubMock.return_value = stubMock - + alloc = opencue.wrappers.allocation.Allocation( facility_pb2.Allocation(name=TEST_ALLOC_NAME)) hostIds = [TEST_HOST_ID] alloc.reparentHostIds(hostIds) hosts = [host_pb2.Host(id=TEST_HOST_ID)] - + stubMock.ReparentHosts.assert_called_with( facility_pb2.AllocReparentHostsRequest( allocation=alloc.data, hosts=host_pb2.HostSeq(hosts=hosts)), timeout=mock.ANY) diff --git a/pycue/tests/wrappers/comment_test.py b/pycue/tests/wrappers/comment_test.py index 22de54ac7..68481b6c5 100644 --- a/pycue/tests/wrappers/comment_test.py +++ b/pycue/tests/wrappers/comment_test.py @@ -14,15 +14,17 @@ # See the License for the specific language governing permissions and # limitations under the License. +"""Tests for `opencue.wrappers.comment`.""" from __future__ import print_function from __future__ import division from __future__ import absolute_import -import mock import unittest -import opencue +import mock + from opencue.compiled_proto import comment_pb2 +import opencue.wrappers.comment TEST_COMMENT_MESSAGE = "hi, I'm a message" diff --git a/pycue/tests/wrappers/deed_test.py b/pycue/tests/wrappers/deed_test.py index f07734851..8fd0833f6 100644 --- a/pycue/tests/wrappers/deed_test.py +++ b/pycue/tests/wrappers/deed_test.py @@ -14,15 +14,17 @@ # See the License for the specific language governing permissions and # limitations under the License. +"""Tests for `opencue.wrappers.deed`.""" from __future__ import print_function from __future__ import division from __future__ import absolute_import -import mock import unittest -import opencue +import mock + from opencue.compiled_proto import host_pb2 +import opencue.wrappers.deed TEST_DEED_ID = 'ddd-dd-dddd' diff --git a/pycue/tests/wrappers/depend_test.py b/pycue/tests/wrappers/depend_test.py index f86140e0c..27c7c298d 100644 --- a/pycue/tests/wrappers/depend_test.py +++ b/pycue/tests/wrappers/depend_test.py @@ -14,15 +14,17 @@ # See the License for the specific language governing permissions and # limitations under the License. +"""Tests for `opencue.wrappers.depend`.""" from __future__ import print_function from __future__ import division from __future__ import absolute_import -import mock import unittest -import opencue +import mock + from opencue.compiled_proto import depend_pb2 +import opencue.wrappers.depend TEST_DEPEND_ID = 'zzz-aaa-fff' diff --git a/pycue/tests/wrappers/filter_test.py b/pycue/tests/wrappers/filter_test.py index cfc95b611..4aac87877 100644 --- a/pycue/tests/wrappers/filter_test.py +++ b/pycue/tests/wrappers/filter_test.py @@ -14,16 +14,20 @@ # See the License for the specific language governing permissions and # limitations under the License. +"""Tests for `opencue.wrappers.filter`.""" from __future__ import print_function from __future__ import division from __future__ import absolute_import -import mock import unittest -import opencue +import mock + from opencue.compiled_proto import filter_pb2 from opencue.compiled_proto import job_pb2 +import opencue.wrappers.filter +import opencue.wrappers.group +import opencue.wrappers.job TEST_ACTION_ID = 'aaa-aaaa-aaa' @@ -39,12 +43,11 @@ def testDelete(self, getStubMock): stubMock.Delete.return_value = filter_pb2.FilterDeleteResponse() getStubMock.return_value = stubMock - filter = opencue.wrappers.filter.Filter( - filter_pb2.Filter(name=TEST_FILTER_NAME)) - filter.delete() + filterToDelete = opencue.wrappers.filter.Filter(filter_pb2.Filter(name=TEST_FILTER_NAME)) + filterToDelete.delete() stubMock.Delete.assert_called_with( - filter_pb2.FilterDeleteRequest(filter=filter.data), timeout=mock.ANY) + filter_pb2.FilterDeleteRequest(filter=filterToDelete.data), timeout=mock.ANY) def testCreateMatcher(self, getStubMock): matcherId = 'mmm-mmmm-mmm' @@ -56,15 +59,13 @@ def testCreateMatcher(self, getStubMock): queryStr = 'john' subject = filter_pb2.USER matcherType = filter_pb2.IS_NOT - matcherData = opencue.wrappers.filter.MatcherData(subject=subject, - type=matcherType, - input=queryStr) - filter = opencue.wrappers.filter.Filter( - filter_pb2.Filter(name=TEST_FILTER_NAME)) - matcher = filter.createMatcher(subject, matcherType, queryStr) + matcherData = opencue.wrappers.filter.MatcherData( + subject=subject, type=matcherType, input=queryStr) + filterForMatcher = opencue.wrappers.filter.Filter(filter_pb2.Filter(name=TEST_FILTER_NAME)) + matcher = filterForMatcher.createMatcher(subject, matcherType, queryStr) stubMock.CreateMatcher.assert_called_with( - filter_pb2.FilterCreateMatcherRequest(filter=filter.data, data=matcherData), + filter_pb2.FilterCreateMatcherRequest(filter=filterForMatcher.data, data=matcherData), timeout=mock.ANY) self.assertEqual(matcher.id(), matcherId) @@ -77,9 +78,8 @@ def testCreateAction(self, getStubMock): actionType = filter_pb2.PAUSE_JOB value = 10 - filter = opencue.wrappers.filter.Filter( - filter_pb2.Filter(name=TEST_FILTER_NAME)) - action = filter.createAction(actionType, value) + filterForAction = opencue.wrappers.filter.Filter(filter_pb2.Filter(name=TEST_FILTER_NAME)) + action = filterForAction.createAction(actionType, value) actionData = opencue.wrappers.filter.ActionData( type=actionType, value_type=filter_pb2.INTEGER_TYPE, @@ -90,7 +90,7 @@ def testCreateAction(self, getStubMock): boolean_value=False) stubMock.CreateAction.assert_called_with( - filter_pb2.FilterCreateActionRequest(filter=filter.data, data=actionData), + filter_pb2.FilterCreateActionRequest(filter=filterForAction.data, data=actionData), timeout=mock.ANY) self.assertEqual(action.id(), actionId) @@ -101,12 +101,11 @@ def testGetActions(self, getStubMock): actions=filter_pb2.ActionSeq(actions=[filter_pb2.Action(id=actionId)])) getStubMock.return_value = stubMock - filter = opencue.wrappers.filter.Filter( - filter_pb2.Filter(name=TEST_FILTER_NAME)) - actions = filter.getActions() + filterForActions = opencue.wrappers.filter.Filter(filter_pb2.Filter(name=TEST_FILTER_NAME)) + actions = filterForActions.getActions() stubMock.GetActions.assert_called_with( - filter_pb2.FilterGetActionsRequest(filter=filter.data), timeout=mock.ANY) + filter_pb2.FilterGetActionsRequest(filter=filterForActions.data), timeout=mock.ANY) self.assertEqual(len(actions), 1) self.assertEqual(actions[0].id(), actionId) @@ -117,12 +116,11 @@ def testGetMatchers(self, getStubMock): matchers=filter_pb2.MatcherSeq(matchers=[filter_pb2.Matcher(id=matcherId)])) getStubMock.return_value = stubMock - filter = opencue.wrappers.filter.Filter( - filter_pb2.Filter(name=TEST_FILTER_NAME)) - matchers = filter.getMatchers() + filterForMatchers = opencue.wrappers.filter.Filter(filter_pb2.Filter(name=TEST_FILTER_NAME)) + matchers = filterForMatchers.getMatchers() stubMock.GetMatchers.assert_called_with( - filter_pb2.FilterGetMatchersRequest(filter=filter.data), timeout=mock.ANY) + filter_pb2.FilterGetMatchersRequest(filter=filterForMatchers.data), timeout=mock.ANY) self.assertEqual(len(matchers), 1) self.assertEqual(matchers[0].id(), matcherId) @@ -131,74 +129,56 @@ def testLowerOrder(self, getStubMock): stubMock.LowerOrder.return_value = filter_pb2.FilterLowerOrderResponse() getStubMock.return_value = stubMock - filter = opencue.wrappers.filter.Filter( - filter_pb2.Filter(name=TEST_FILTER_NAME)) - filter.lowerOrder() + filterInst = opencue.wrappers.filter.Filter(filter_pb2.Filter(name=TEST_FILTER_NAME)) + filterInst.lowerOrder() stubMock.LowerOrder.assert_called_with( - filter_pb2.FilterLowerOrderRequest(filter=filter.data), timeout=mock.ANY) + filter_pb2.FilterLowerOrderRequest(filter=filterInst.data), timeout=mock.ANY) def testRaiseOrder(self, getStubMock): stubMock = mock.Mock() stubMock.RaiseOrder.return_value = filter_pb2.FilterRaiseOrderResponse() getStubMock.return_value = stubMock - filter = opencue.wrappers.filter.Filter( - filter_pb2.Filter(name=TEST_FILTER_NAME)) - filter.raiseOrder() + filterInst = opencue.wrappers.filter.Filter(filter_pb2.Filter(name=TEST_FILTER_NAME)) + filterInst.raiseOrder() stubMock.RaiseOrder.assert_called_with( - filter_pb2.FilterRaiseOrderRequest(filter=filter.data), timeout=mock.ANY) + filter_pb2.FilterRaiseOrderRequest(filter=filterInst.data), timeout=mock.ANY) def testOrderFirst(self, getStubMock): stubMock = mock.Mock() stubMock.OrderFirst.return_value = filter_pb2.FilterOrderFirstResponse() getStubMock.return_value = stubMock - filter = opencue.wrappers.filter.Filter( - filter_pb2.Filter(name=TEST_FILTER_NAME)) - filter.orderFirst() + filterInst = opencue.wrappers.filter.Filter(filter_pb2.Filter(name=TEST_FILTER_NAME)) + filterInst.orderFirst() stubMock.OrderFirst.assert_called_with( - filter_pb2.FilterOrderFirstRequest(filter=filter.data), timeout=mock.ANY) - - def testOrderLast(self, getStubMock): - stubMock = mock.Mock() - stubMock.OrderLast.return_value = filter_pb2.FilterOrderLastResponse() - getStubMock.return_value = stubMock - - filter = opencue.wrappers.filter.Filter( - filter_pb2.Filter(name=TEST_FILTER_NAME)) - filter.orderLast() - - stubMock.OrderLast.assert_called_with( - filter_pb2.FilterOrderLastRequest(filter=filter.data), timeout=mock.ANY) + filter_pb2.FilterOrderFirstRequest(filter=filterInst.data), timeout=mock.ANY) def testOrderLast(self, getStubMock): stubMock = mock.Mock() stubMock.OrderLast.return_value = filter_pb2.FilterOrderLastResponse() getStubMock.return_value = stubMock - filter = opencue.wrappers.filter.Filter( - filter_pb2.Filter(name=TEST_FILTER_NAME)) - filter.orderLast() + filterInst = opencue.wrappers.filter.Filter(filter_pb2.Filter(name=TEST_FILTER_NAME)) + filterInst.orderLast() stubMock.OrderLast.assert_called_with( - filter_pb2.FilterOrderLastRequest(filter=filter.data), timeout=mock.ANY) + filter_pb2.FilterOrderLastRequest(filter=filterInst.data), timeout=mock.ANY) def testRunFilterOnGroup(self, getStubMock): stubMock = mock.Mock() stubMock.RunFilterOnGroup.return_value = filter_pb2.FilterRunFilterOnGroupResponse() getStubMock.return_value = stubMock - group = opencue.wrappers.group.Group( - job_pb2.Group(name='testGroup')) - filter = opencue.wrappers.filter.Filter( - filter_pb2.Filter(name=TEST_FILTER_NAME)) - filter.runFilterOnGroup(group) + group = opencue.wrappers.group.Group(job_pb2.Group(name='testGroup')) + filterToRun = opencue.wrappers.filter.Filter(filter_pb2.Filter(name=TEST_FILTER_NAME)) + filterToRun.runFilterOnGroup(group) stubMock.RunFilterOnGroup.assert_called_with( - filter_pb2.FilterRunFilterOnGroupRequest(filter=filter.data, group=group.data), + filter_pb2.FilterRunFilterOnGroupRequest(filter=filterToRun.data, group=group.data), timeout=mock.ANY) def testRunFilterOnJobs(self, getStubMock): @@ -208,12 +188,11 @@ def testRunFilterOnJobs(self, getStubMock): jobs = [opencue.wrappers.job.Job(job_pb2.Job(name='testJob'))] jobSeq = job_pb2.JobSeq(jobs=[job.data for job in jobs]) - filter = opencue.wrappers.filter.Filter( - filter_pb2.Filter(name=TEST_FILTER_NAME)) - filter.runFilterOnJobs(jobs) + filterToRun = opencue.wrappers.filter.Filter(filter_pb2.Filter(name=TEST_FILTER_NAME)) + filterToRun.runFilterOnJobs(jobs) stubMock.RunFilterOnJobs.assert_called_with( - filter_pb2.FilterRunFilterOnJobsRequest(filter=filter.data, jobs=jobSeq), + filter_pb2.FilterRunFilterOnJobsRequest(filter=filterToRun.data, jobs=jobSeq), timeout=mock.ANY) def testSetEnabled(self, getStubMock): @@ -222,12 +201,12 @@ def testSetEnabled(self, getStubMock): getStubMock.return_value = stubMock value = True - filter = opencue.wrappers.filter.Filter( - filter_pb2.Filter(name=TEST_FILTER_NAME)) - filter.setEnabled(value) + filterToEnable = opencue.wrappers.filter.Filter(filter_pb2.Filter(name=TEST_FILTER_NAME)) + filterToEnable.setEnabled(value) stubMock.SetEnabled.assert_called_with( - filter_pb2.FilterSetEnabledRequest(filter=filter.data, enabled=value), timeout=mock.ANY) + filter_pb2.FilterSetEnabledRequest( + filter=filterToEnable.data, enabled=value), timeout=mock.ANY) def testSetName(self, getStubMock): stubMock = mock.Mock() @@ -235,12 +214,11 @@ def testSetName(self, getStubMock): getStubMock.return_value = stubMock value = 'newname' - filter = opencue.wrappers.filter.Filter( - filter_pb2.Filter(name=TEST_FILTER_NAME)) - filter.setName(value) + filterToSet = opencue.wrappers.filter.Filter(filter_pb2.Filter(name=TEST_FILTER_NAME)) + filterToSet.setName(value) stubMock.SetName.assert_called_with( - filter_pb2.FilterSetNameRequest(filter=filter.data, name=value), timeout=mock.ANY) + filter_pb2.FilterSetNameRequest(filter=filterToSet.data, name=value), timeout=mock.ANY) def testSetType(self, getStubMock): stubMock = mock.Mock() @@ -248,12 +226,11 @@ def testSetType(self, getStubMock): getStubMock.return_value = stubMock value = filter_pb2.MATCH_ALL - filter = opencue.wrappers.filter.Filter( - filter_pb2.Filter(name=TEST_FILTER_NAME)) - filter.setType(value) + filterToSet = opencue.wrappers.filter.Filter(filter_pb2.Filter(name=TEST_FILTER_NAME)) + filterToSet.setType(value) stubMock.SetType.assert_called_with( - filter_pb2.FilterSetTypeRequest(filter=filter.data, type=value), timeout=mock.ANY) + filter_pb2.FilterSetTypeRequest(filter=filterToSet.data, type=value), timeout=mock.ANY) def testSetOrder(self, getStubMock): stubMock = mock.Mock() @@ -261,12 +238,12 @@ def testSetOrder(self, getStubMock): getStubMock.return_value = stubMock value = 2 - filter = opencue.wrappers.filter.Filter( - filter_pb2.Filter(name=TEST_FILTER_NAME)) - filter.setOrder(value) + filterToSet = opencue.wrappers.filter.Filter(filter_pb2.Filter(name=TEST_FILTER_NAME)) + filterToSet.setOrder(value) stubMock.SetOrder.assert_called_with( - filter_pb2.FilterSetOrderRequest(filter=filter.data, order=value), timeout=mock.ANY) + filter_pb2.FilterSetOrderRequest( + filter=filterToSet.data, order=value), timeout=mock.ANY) @mock.patch('opencue.cuebot.Cuebot.getStub') @@ -278,21 +255,19 @@ def testGetParentFilter(self, getStubMock): filter=filter_pb2.Filter(name=TEST_FILTER_NAME)) getStubMock.return_value = stubMock - action = opencue.wrappers.filter.Action( - filter_pb2.Action(id=TEST_ACTION_ID)) - filter = action.getParentFilter() + action = opencue.wrappers.filter.Action(filter_pb2.Action(id=TEST_ACTION_ID)) + filterReturned = action.getParentFilter() stubMock.GetParentFilter.assert_called_with( filter_pb2.ActionGetParentFilterRequest(action=action.data), timeout=mock.ANY) - self.assertEqual(filter.name(), TEST_FILTER_NAME) + self.assertEqual(filterReturned.name(), TEST_FILTER_NAME) def testDelete(self, getStubMock): stubMock = mock.Mock() stubMock.Delete.return_value = filter_pb2.ActionDeleteResponse() getStubMock.return_value = stubMock - action = opencue.wrappers.filter.Action( - filter_pb2.Action(id=TEST_ACTION_ID)) + action = opencue.wrappers.filter.Action(filter_pb2.Action(id=TEST_ACTION_ID)) action.delete() stubMock.Delete.assert_called_with( @@ -462,13 +437,12 @@ def testGetParentFilter(self, getStubMock): filter=filter_pb2.Filter(name=TEST_FILTER_NAME)) getStubMock.return_value = stubMock - matcher = opencue.wrappers.filter.Matcher( - filter_pb2.Matcher(id=TEST_MATCHER_ID)) - filter = matcher.getParentFilter() + matcher = opencue.wrappers.filter.Matcher(filter_pb2.Matcher(id=TEST_MATCHER_ID)) + filterReturns = matcher.getParentFilter() stubMock.GetParentFilter.assert_called_with( filter_pb2.MatcherGetParentFilterRequest(matcher=matcher.data), timeout=mock.ANY) - self.assertEqual(filter.name(), TEST_FILTER_NAME) + self.assertEqual(filterReturns.name(), TEST_FILTER_NAME) def testDelete(self, getStubMock): stubMock = mock.Mock() @@ -526,7 +500,7 @@ 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) diff --git a/pycue/tests/wrappers/frame_test.py b/pycue/tests/wrappers/frame_test.py index 760c63085..8be9ff0fd 100644 --- a/pycue/tests/wrappers/frame_test.py +++ b/pycue/tests/wrappers/frame_test.py @@ -14,17 +14,21 @@ # See the License for the specific language governing permissions and # limitations under the License. +"""Tests for `opencue.wrappers.frame`.""" from __future__ import print_function from __future__ import division from __future__ import absolute_import -import mock import time import unittest -import opencue +import mock + from opencue.compiled_proto import depend_pb2 from opencue.compiled_proto import job_pb2 +import opencue.wrappers.frame +import opencue.wrappers.job +import opencue.wrappers.layer TEST_FRAME_NAME = 'testFrame' diff --git a/pycue/tests/wrappers/group_test.py b/pycue/tests/wrappers/group_test.py index 8a05f266e..615e64afc 100644 --- a/pycue/tests/wrappers/group_test.py +++ b/pycue/tests/wrappers/group_test.py @@ -14,15 +14,18 @@ # See the License for the specific language governing permissions and # limitations under the License. +"""Tests for `opencue.wrappers.group`.""" from __future__ import print_function from __future__ import division from __future__ import absolute_import -import mock import unittest -import opencue +import mock + from opencue.compiled_proto import job_pb2 +import opencue.wrappers.group +import opencue.wrappers.job TEST_GROUP_NAME = 'testGroup' @@ -215,7 +218,7 @@ def testReparentGroupIds(self, getStubMock): stubMock = mock.Mock() stubMock.ReparentGroups.return_value = job_pb2.GroupReparentGroupsResponse() getStubMock.return_value = stubMock - + groupId = 'ggg-gggg-ggg' groupIds = [groupId] groups = [opencue.wrappers.group.Group(job_pb2.Group(id='ggg-gggg-ggg'))] @@ -223,7 +226,7 @@ def testReparentGroupIds(self, getStubMock): group = opencue.wrappers.group.Group( job_pb2.Group(name=TEST_GROUP_NAME)) group.reparentGroupIds(groupIds) - + stubMock.ReparentGroups.assert_called_with( job_pb2.GroupReparentGroupsRequest(group=group.data, groups=groupSeq), timeout=mock.ANY) diff --git a/pycue/tests/wrappers/host_test.py b/pycue/tests/wrappers/host_test.py index bac92d892..74f406490 100644 --- a/pycue/tests/wrappers/host_test.py +++ b/pycue/tests/wrappers/host_test.py @@ -14,19 +14,22 @@ # See the License for the specific language governing permissions and # limitations under the License. +"""Tests for `opencue.wrappers.host`.""" from __future__ import print_function from __future__ import division from __future__ import absolute_import import os -import mock import unittest -import opencue +import mock + from opencue.compiled_proto import comment_pb2 from opencue.compiled_proto import facility_pb2 from opencue.compiled_proto import host_pb2 from opencue.compiled_proto import renderPartition_pb2 +import opencue.wrappers.allocation +import opencue.wrappers.host TEST_HOST_NAME = 'testHost' diff --git a/pycue/tests/wrappers/job_test.py b/pycue/tests/wrappers/job_test.py index f8e00fccc..0ad2504de 100644 --- a/pycue/tests/wrappers/job_test.py +++ b/pycue/tests/wrappers/job_test.py @@ -14,18 +14,23 @@ # See the License for the specific language governing permissions and # limitations under the License. +"""Tests for `opencue.wrappers.job`.""" from __future__ import print_function from __future__ import division from __future__ import absolute_import -import mock import os import unittest -import opencue +import mock + from opencue.compiled_proto import comment_pb2 from opencue.compiled_proto import depend_pb2 from opencue.compiled_proto import job_pb2 +import opencue.wrappers.frame +import opencue.wrappers.group +import opencue.wrappers.job +import opencue.wrappers.layer TEST_JOB_NAME = 'testJob' @@ -438,14 +443,14 @@ def testReorderFrames(self, getStubMock): stubMock.ReorderFrames.return_value = job_pb2.JobReorderFramesResponse() getStubMock.return_value = stubMock - range = '1-10' + frameRange = '1-10' order = job_pb2.REVERSE job = opencue.wrappers.job.Job( job_pb2.Job(name=TEST_JOB_NAME)) - job.reorderFrames(range, order) + job.reorderFrames(frameRange, order) stubMock.ReorderFrames.assert_called_with( - job_pb2.JobReorderFramesRequest(job=job.data, range=range, order=order), + job_pb2.JobReorderFramesRequest(job=job.data, range=frameRange, order=order), timeout=mock.ANY) def testStaggerFrames(self, getStubMock): @@ -453,14 +458,14 @@ def testStaggerFrames(self, getStubMock): stubMock.StaggerFrames.return_value = job_pb2.JobStaggerFramesResponse() getStubMock.return_value = stubMock - range = '1-10' + frameRange = '1-10' stagger = 5 job = opencue.wrappers.job.Job( job_pb2.Job(name=TEST_JOB_NAME)) - job.staggerFrames(range, stagger) + job.staggerFrames(frameRange, stagger) stubMock.StaggerFrames.assert_called_with( - job_pb2.JobStaggerFramesRequest(job=job.data, range=range, stagger=stagger), + job_pb2.JobStaggerFramesRequest(job=job.data, range=frameRange, stagger=stagger), timeout=mock.ANY) def testFrameStateTotals(self, getStubMock): @@ -491,7 +496,7 @@ def testFrameStateTotals(self, getStubMock): class NestedJobTests(unittest.TestCase): def testAsJob(self, getStubMock): - id = 'nnn-nnnn-nnn' + jobId = 'nnn-nnnn-nnn' state = job_pb2.FINISHED name = 'testNestedJob' shot = 'shotname' @@ -499,7 +504,7 @@ def testAsJob(self, getStubMock): user = 'username' group = 'groupname' facility = 'facilityname' - os = 'os' + jobOs = 'os' uid = 12345 priority = 14 minCores = 5 @@ -507,13 +512,13 @@ def testAsJob(self, getStubMock): logDir = '/path/to/logs' isPaused = False nestedJob = opencue.wrappers.job.NestedJob( - job_pb2.NestedJob(id=id, state=state, name=name, shot=shot, show=show, user=user, - group=group, facility=facility, os=os, uid=uid, priority=priority, + job_pb2.NestedJob(id=jobId, state=state, name=name, shot=shot, show=show, user=user, + group=group, facility=facility, os=jobOs, uid=uid, priority=priority, min_cores=minCores, max_cores=maxCores, log_dir=logDir, is_paused=isPaused)) job = opencue.wrappers.job.Job( - job_pb2.Job(id=id, state=state, name=name, shot=shot, show=show, user=user, - group=group, facility=facility, os=os, uid=uid, priority=priority, + job_pb2.Job(id=jobId, state=state, name=name, shot=shot, show=show, user=user, + group=group, facility=facility, os=jobOs, uid=uid, priority=priority, min_cores=minCores, max_cores=maxCores, log_dir=logDir, is_paused=isPaused)) diff --git a/pycue/tests/wrappers/layer_test.py b/pycue/tests/wrappers/layer_test.py index 34a699d8a..cf8fb0c33 100644 --- a/pycue/tests/wrappers/layer_test.py +++ b/pycue/tests/wrappers/layer_test.py @@ -14,16 +14,20 @@ # See the License for the specific language governing permissions and # limitations under the License. +"""Tests for `opencue.wrappers.layer`""" from __future__ import print_function from __future__ import division from __future__ import absolute_import -import mock import unittest -import opencue +import mock + from opencue.compiled_proto import depend_pb2 from opencue.compiled_proto import job_pb2 +import opencue.wrappers.frame +import opencue.wrappers.layer +import opencue.wrappers.job TEST_LAYER_NAME = 'testLayer' @@ -32,6 +36,7 @@ @mock.patch('opencue.cuebot.Cuebot.getStub') class LayerTests(unittest.TestCase): + """Tests for `opencue.wrappers.layer.Layer`.""" def testKill(self, getStubMock): stubMock = mock.Mock() @@ -370,14 +375,13 @@ def testReorderFrames(self, getStubMock): stubMock.ReorderFrames.return_value = job_pb2.LayerReorderFramesResponse() getStubMock.return_value = stubMock - range = '1-10' + frameRange = '1-10' order = job_pb2.REVERSE - layer = opencue.wrappers.layer.Layer( - job_pb2.Layer(name=TEST_LAYER_NAME)) - layer.reorderFrames(range, order) + layer = opencue.wrappers.layer.Layer(job_pb2.Layer(name=TEST_LAYER_NAME)) + layer.reorderFrames(frameRange, order) stubMock.ReorderFrames.assert_called_with( - job_pb2.LayerReorderFramesRequest(layer=layer.data, range=range, order=order), + job_pb2.LayerReorderFramesRequest(layer=layer.data, range=frameRange, order=order), timeout=mock.ANY) def testStaggerFrames(self, getStubMock): @@ -385,14 +389,14 @@ def testStaggerFrames(self, getStubMock): stubMock.StaggerFrames.return_value = job_pb2.LayerStaggerFramesResponse() getStubMock.return_value = stubMock - range = '1-10' + frameRange = '1-10' stagger = 4 layer = opencue.wrappers.layer.Layer( job_pb2.Layer(name=TEST_LAYER_NAME)) - layer.staggerFrames(range, stagger) + layer.staggerFrames(frameRange, stagger) stubMock.StaggerFrames.assert_called_with( - job_pb2.LayerStaggerFramesRequest(layer=layer.data, range=range, stagger=stagger), + job_pb2.LayerStaggerFramesRequest(layer=layer.data, range=frameRange, stagger=stagger), timeout=mock.ANY) diff --git a/pycue/tests/wrappers/limit_test.py b/pycue/tests/wrappers/limit_test.py index cbc079a54..ac72c9579 100644 --- a/pycue/tests/wrappers/limit_test.py +++ b/pycue/tests/wrappers/limit_test.py @@ -14,15 +14,17 @@ # See the License for the specific language governing permissions and # limitations under the License. +"""Tests for `opencue.wrappers.limit`.""" from __future__ import print_function from __future__ import division from __future__ import absolute_import -import mock import unittest -import opencue +import mock + from opencue.compiled_proto import limit_pb2 +import opencue.wrappers.limit TEST_LIMIT_ID = 'lll-llll-lll' @@ -32,29 +34,29 @@ @mock.patch('opencue.cuebot.Cuebot.getStub') class LimitTests(unittest.TestCase): - + def testCreate(self, getStubMock): stubMock = mock.Mock() stubMock.Create.return_value = limit_pb2.LimitCreateResponse() getStubMock.return_value = stubMock - + limit = opencue.wrappers.limit.Limit( limit_pb2.Limit(name=TEST_LIMIT_NAME, max_value=TEST_LIMIT_MAX_VALUE)) limit.create() - + stubMock.Create.assert_called_with( limit_pb2.LimitCreateRequest(name=TEST_LIMIT_NAME, max_value=TEST_LIMIT_MAX_VALUE), timeout=mock.ANY) - + def testDelete(self, getStubMock): stubMock = mock.Mock() stubMock.Delete.return_value = limit_pb2.LimitDeleteResponse() getStubMock.return_value = stubMock - + limit = opencue.wrappers.limit.Limit( limit_pb2.Limit(name=TEST_LIMIT_NAME, max_value=TEST_LIMIT_MAX_VALUE)) limit.delete() - + stubMock.Delete.assert_called_with( limit_pb2.LimitDeleteRequest(name=TEST_LIMIT_NAME), timeout=mock.ANY) @@ -63,10 +65,10 @@ def testFind(self, getStubMock): stubMock.Find.return_value = limit_pb2.LimitFindResponse( limit=limit_pb2.Limit(name=TEST_LIMIT_NAME, max_value=TEST_LIMIT_MAX_VALUE)) getStubMock.return_value = stubMock - + limit = opencue.wrappers.limit.Limit() responseLimit = limit.find(TEST_LIMIT_NAME) - + stubMock.Find.assert_called_with( limit_pb2.LimitFindRequest(name=TEST_LIMIT_NAME), timeout=mock.ANY) self.assertEqual(responseLimit.name(), TEST_LIMIT_NAME) @@ -77,10 +79,10 @@ def testGet(self, getStubMock): stubMock.Get.return_value = limit_pb2.LimitGetResponse( limit=limit_pb2.Limit(name=TEST_LIMIT_NAME, max_value=TEST_LIMIT_MAX_VALUE)) getStubMock.return_value = stubMock - + limit = opencue.wrappers.limit.Limit() responseLimit = limit.get(TEST_LIMIT_ID) - + stubMock.Get.assert_called_with( limit_pb2.LimitGetRequest(id=TEST_LIMIT_ID), timeout=mock.ANY) self.assertEqual(responseLimit.name(), TEST_LIMIT_NAME) @@ -91,11 +93,11 @@ def testRename(self, getStubMock): stubMock = mock.Mock() stubMock.Rename.return_value = limit_pb2.LimitRenameResponse() getStubMock.return_value = stubMock - + limit = opencue.wrappers.limit.Limit( limit_pb2.Limit(name=TEST_LIMIT_NAME, max_value=TEST_LIMIT_MAX_VALUE)) limit.rename(test_new_name) - + stubMock.Rename.assert_called_with( limit_pb2.LimitRenameRequest(old_name=TEST_LIMIT_NAME, new_name=test_new_name), timeout=mock.ANY) @@ -105,15 +107,15 @@ def testSetMaxValue(self, getStubMock): stubMock = mock.Mock() stubMock.SetMaxValue.return_value = limit_pb2.LimitSetMaxValueResponse() getStubMock.return_value = stubMock - + limit = opencue.wrappers.limit.Limit( limit_pb2.Limit(name=TEST_LIMIT_NAME, max_value=TEST_LIMIT_MAX_VALUE)) limit.setMaxValue(max_value) - + stubMock.SetMaxValue.assert_called_with( limit_pb2.LimitSetMaxValueRequest(name=TEST_LIMIT_NAME, max_value=max_value), timeout=mock.ANY) if __name__ == '__main__': - unittest.main() + unittest.main() diff --git a/pycue/tests/wrappers/owner_test.py b/pycue/tests/wrappers/owner_test.py index 3bcfc4303..6c31151ee 100644 --- a/pycue/tests/wrappers/owner_test.py +++ b/pycue/tests/wrappers/owner_test.py @@ -14,15 +14,17 @@ # See the License for the specific language governing permissions and # limitations under the License. +"""Tests for `opencue.wrappers.owner`.""" from __future__ import print_function from __future__ import division from __future__ import absolute_import -import mock import unittest -import opencue +import mock + from opencue.compiled_proto import host_pb2 +import opencue.wrappers.owner TEST_DEED_ID = 'ddd-dd-dddd' @@ -32,7 +34,6 @@ TEST_SHOW_NAME = 'testShow' - @mock.patch('opencue.cuebot.Cuebot.getStub') class OwnerTests(unittest.TestCase): diff --git a/pycue/tests/wrappers/proc_test.py b/pycue/tests/wrappers/proc_test.py index 693ac4ab2..82434f15f 100644 --- a/pycue/tests/wrappers/proc_test.py +++ b/pycue/tests/wrappers/proc_test.py @@ -14,16 +14,18 @@ # See the License for the specific language governing permissions and # limitations under the License. +"""Tests for `opencue.wrappers.proc`.""" from __future__ import print_function from __future__ import division from __future__ import absolute_import -import mock import unittest -import opencue +import mock + from opencue.compiled_proto import host_pb2 from opencue.compiled_proto import job_pb2 +import opencue.wrappers.proc TEST_HOST_NAME = 'testHost' diff --git a/pycue/tests/wrappers/service_test.py b/pycue/tests/wrappers/service_test.py index 5e4a20936..92b2e3b2c 100644 --- a/pycue/tests/wrappers/service_test.py +++ b/pycue/tests/wrappers/service_test.py @@ -14,15 +14,17 @@ # See the License for the specific language governing permissions and # limitations under the License. +"""Tests for `opencue.wrappers.service`.""" from __future__ import print_function from __future__ import division from __future__ import absolute_import -import mock import unittest -import opencue +import mock + from opencue.compiled_proto import service_pb2 +import opencue.wrappers.service TEST_SERVICE_NAME = 'testService' diff --git a/pycue/tests/wrappers/show_test.py b/pycue/tests/wrappers/show_test.py index c338d4246..b7cc3dd9a 100644 --- a/pycue/tests/wrappers/show_test.py +++ b/pycue/tests/wrappers/show_test.py @@ -14,14 +14,15 @@ # See the License for the specific language governing permissions and # limitations under the License. +"""Tests for the opencue.wrappers.show module.""" from __future__ import print_function from __future__ import division from __future__ import absolute_import -import mock import unittest -import opencue +import mock + from opencue.compiled_proto import facility_pb2 from opencue.compiled_proto import filter_pb2 from opencue.compiled_proto import host_pb2 @@ -29,6 +30,8 @@ from opencue.compiled_proto import service_pb2 from opencue.compiled_proto import show_pb2 from opencue.compiled_proto import subscription_pb2 +import opencue.wrappers.allocation +import opencue.wrappers.show TEST_ALLOCATION_ID = 'aaa-zzz-fff' @@ -74,7 +77,8 @@ def testCreateSubscription(self, getStubMock): show = opencue.wrappers.show.Show(show_pb2.Show(name=TEST_SHOW_NAME)) allocation = opencue.wrappers.allocation.Allocation( facility_pb2.Allocation(id=TEST_ALLOCATION_ID)) - subscription = show.createSubscription(allocation, TEST_SUBSCRIPTION_SIZE, TEST_SUBSCRIPTION_BURST) + subscription = show.createSubscription( + allocation, TEST_SUBSCRIPTION_SIZE, TEST_SUBSCRIPTION_BURST) stubMock.CreateSubscription.assert_called_with( show_pb2.ShowCreateSubscriptionRequest(show=show.data, @@ -200,12 +204,12 @@ def testFindFilter(self, getStubMock): getStubMock.return_value = stubMock show = opencue.wrappers.show.Show(show_pb2.Show(name=TEST_SHOW_NAME)) - filter = show.findFilter(TEST_FILTER_NAME) + filter_found = show.findFilter(TEST_FILTER_NAME) stubMock.FindFilter.assert_called_with( show_pb2.ShowFindFilterRequest(show=show.data, name=TEST_FILTER_NAME), timeout=mock.ANY) - self.assertEqual(filter.name(), TEST_FILTER_NAME) + self.assertEqual(filter_found.name(), TEST_FILTER_NAME) def testCreateFilter(self, getStubMock): stubMock = mock.Mock() @@ -214,12 +218,12 @@ def testCreateFilter(self, getStubMock): getStubMock.return_value = stubMock show = opencue.wrappers.show.Show(show_pb2.Show(name=TEST_SHOW_NAME)) - filter = show.createFilter(TEST_FILTER_NAME) + filter_created = show.createFilter(TEST_FILTER_NAME) stubMock.CreateFilter.assert_called_with( show_pb2.ShowCreateFilterRequest(show=show.data, name=TEST_FILTER_NAME), timeout=mock.ANY) - self.assertEqual(filter.name(), TEST_FILTER_NAME) + self.assertEqual(filter_created.name(), TEST_FILTER_NAME) def testGetGroups(self, getStubMock): stubMock = mock.Mock() diff --git a/pycue/tests/wrappers/subscription_test.py b/pycue/tests/wrappers/subscription_test.py index c29a875ae..342258487 100644 --- a/pycue/tests/wrappers/subscription_test.py +++ b/pycue/tests/wrappers/subscription_test.py @@ -14,19 +14,23 @@ # See the License for the specific language governing permissions and # limitations under the License. +"""Tests for `opencue.wrappers.subscription`.""" from __future__ import print_function from __future__ import division from __future__ import absolute_import -import mock import unittest -import opencue +import mock + from opencue.compiled_proto import subscription_pb2 +import opencue.wrappers.subscription + TEST_SUBSCRIPTION_ID = 'aaaa-aaa-aaaa' TEST_SUBSCRIPTION_NAME = 'testSubscription' + @mock.patch('opencue.cuebot.Cuebot.getStub') class SubscriptionTests(unittest.TestCase): diff --git a/pycue/tests/wrappers/task_test.py b/pycue/tests/wrappers/task_test.py index cf03578c9..bc1e0e146 100644 --- a/pycue/tests/wrappers/task_test.py +++ b/pycue/tests/wrappers/task_test.py @@ -14,15 +14,17 @@ # See the License for the specific language governing permissions and # limitations under the License. +"""Tests for `opencue.wrappers.task`.""" from __future__ import print_function from __future__ import division from __future__ import absolute_import -import mock import unittest -import opencue +import mock + from opencue.compiled_proto import task_pb2 +import opencue.wrappers.task @mock.patch('opencue.cuebot.Cuebot.getStub') diff --git a/pycue/tests/wrappers/util_test.py b/pycue/tests/wrappers/util_test.py index bb6c8217f..35f26192b 100644 --- a/pycue/tests/wrappers/util_test.py +++ b/pycue/tests/wrappers/util_test.py @@ -14,6 +14,7 @@ # See the License for the specific language governing permissions and # limitations under the License. +"""Tests for `opencue.wrappers.util`.""" from __future__ import print_function from __future__ import division @@ -25,6 +26,7 @@ import opencue.wrappers.util + TEST_SECONDS_A = 1557942905 TEST_SECONDS_B = 2000 TEST_SECONDS_C = 0