Skip to content

Commit

Permalink
Fix lint and unit-tests
Browse files Browse the repository at this point in the history
  • Loading branch information
DiegoTavares committed Aug 21, 2024
1 parent 7b6f9aa commit a61b939
Show file tree
Hide file tree
Showing 4 changed files with 137 additions and 97 deletions.
9 changes: 6 additions & 3 deletions cuegui/cuegui/MainWindow.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
from builtins import range
import sys
import time
import yaml

from qtpy import QtCore
from qtpy import QtGui
Expand Down Expand Up @@ -71,7 +72,7 @@ def __init__(self, app_name, app_version, window_name, parent = None):
self.name = window_name
else:
self.name = self.windows_names[0]
self.__isEnabled = bool(int(QtGui.qApp.settings.value("EnableJobInteraction", 0)))
self.__isEnabled = yaml.safe_load(self.app.settings.value("EnableJobInteraction", "False"))

# Provides a location for widgets to the right of the menu
menuLayout = QtWidgets.QHBoxLayout()
Expand Down Expand Up @@ -201,14 +202,16 @@ def __createMenus(self):

if self.__isEnabled is False:
# Menu Bar: File -> Enable Job Interaction
enableJobInteraction = QtWidgets.QAction(QtGui.QIcon('icons/exit.png'), '&Enable Job Interaction', self)
enableJobInteraction = QtWidgets.QAction(QtGui.QIcon('icons/exit.png'),
'&Enable Job Interaction', self)
enableJobInteraction.setStatusTip('Enable Job Interaction')
enableJobInteraction.triggered.connect(self.__enableJobInteraction)
self.fileMenu.addAction(enableJobInteraction)
# allow user to disable the job interaction
else:
# Menu Bar: File -> Disable Job Interaction
enableJobInteraction = QtWidgets.QAction(QtGui.QIcon('icons/exit.png'), '&Disable Job Interaction', self)
enableJobInteraction = QtWidgets.QAction(QtGui.QIcon('icons/exit.png'),
'&Disable Job Interaction', self)
enableJobInteraction.setStatusTip('Disable Job Interaction')
enableJobInteraction.triggered.connect(self.__enableJobInteraction)
self.fileMenu.addAction(enableJobInteraction)
Expand Down
147 changes: 84 additions & 63 deletions cuegui/cuegui/MenuActions.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,11 @@ class AbstractActions(object):

__iconCache = {}

# Template for permission alert messages
USER_INTERACTION_PERMISSIONS = "You do not have permissions to {0} owned by {1}" \
"\n\nJob actions can still be enabled at File > Enable Job Interaction," \
" but caution is advised."

def __init__(self, caller, updateCallable, selectedRpcObjectsCallable, sourceCallable):
self._caller = caller
self.__selectedRpcObjects = selectedRpcObjectsCallable
Expand Down Expand Up @@ -214,9 +219,6 @@ def getText(self, title, body, default):
class JobActions(AbstractActions):
"""Actions for jobs."""

# Template for permission alert messages
USER_INTERACTION_PERMISSIONS = "You do not have permissions to {0} owned by {2}"

def __init__(self, *args):
AbstractActions.__init__(self, *args)

Expand Down Expand Up @@ -396,7 +398,7 @@ def kill(self, rpcObjects=None):
self.killDependents(authorized_jobs)
if blocked_job_owners:
cuegui.Utils.showErrorMessageBox(
JobActions.USER_INTERACTION_PERMISSIONS.format(
AbstractActions.USER_INTERACTION_PERMISSIONS.format(
"kill some of the selected jobs",
", ".join(blocked_job_owners)))
self._update()
Expand Down Expand Up @@ -477,7 +479,7 @@ def eatDead(self, rpcObjects=None):
job.eatFrames(state=[opencue.compiled_proto.job_pb2.DEAD])
if blocked_job_owners:
cuegui.Utils.showErrorMessageBox(
JobActions.USER_INTERACTION_PERMISSIONS.format(
AbstractActions.USER_INTERACTION_PERMISSIONS.format(
"eat dead for some of the selected jobs",
", ".join(blocked_job_owners)))
self._update()
Expand All @@ -487,18 +489,36 @@ def eatDead(self, rpcObjects=None):
def autoEatOn(self, rpcObjects=None):
jobs = self._getOnlyJobObjects(rpcObjects)
if jobs:
blocked_job_owners = []
for job in jobs:
job.setAutoEat(True)
job.eatFrames(state=[opencue.compiled_proto.job_pb2.DEAD])
if not cuegui.Utils.isPermissible(job):
blocked_job_owners.append(job.username())
else:
job.setAutoEat(True)
job.eatFrames(state=[opencue.compiled_proto.job_pb2.DEAD])
if blocked_job_owners:
cuegui.Utils.showErrorMessageBox(
AbstractActions.USER_INTERACTION_PERMISSIONS.format(
"enable auto eating frames",
", ".join(blocked_job_owners)))
self._update()

autoEatOff_info = ["Disable auto eating", None, "eat"]

def autoEatOff(self, rpcObjects=None):
jobs = self._getOnlyJobObjects(rpcObjects)
if jobs:
blocked_job_owners = []
for job in jobs:
job.setAutoEat(False)
if not cuegui.Utils.isPermissible(job):
blocked_job_owners.append(job.username())
else:
job.setAutoEat(False)
if blocked_job_owners:
cuegui.Utils.showErrorMessageBox(
AbstractActions.USER_INTERACTION_PERMISSIONS.format(
"disable auto eating frames",
", ".join(blocked_job_owners)))
self._update()

retryDead_info = ["Retry dead frames", None, "retry"]
Expand All @@ -519,7 +539,7 @@ def retryDead(self, rpcObjects=None):
state=[opencue.compiled_proto.job_pb2.DEAD])
if blocked_job_owners:
cuegui.Utils.showErrorMessageBox(
JobActions.USER_INTERACTION_PERMISSIONS.format(
AbstractActions.USER_INTERACTION_PERMISSIONS.format(
"retry dead for some of the selected jobs",
", ".join(blocked_job_owners)))
self._update()
Expand Down Expand Up @@ -817,7 +837,7 @@ def kill(self, rpcObjects=None):
#check permissions
if not cuegui.Utils.isPermissible(self._getSource()):
cuegui.Utils.showErrorMessageBox(
JobActions.USER_INTERACTION_PERMISSIONS.format(
AbstractActions.USER_INTERACTION_PERMISSIONS.format(
"kill layers",
self._getSource().username()))
else:
Expand All @@ -835,7 +855,7 @@ def eat(self, rpcObjects=None):
if layers:
if not cuegui.Utils.isPermissible(self._getSource()):
cuegui.Utils.showErrorMessageBox(
JobActions.USER_INTERACTION_PERMISSIONS.format(
AbstractActions.USER_INTERACTION_PERMISSIONS.format(
"eat layers",
self._getSource().username())
)
Expand All @@ -854,7 +874,7 @@ def retry(self, rpcObjects=None):
if layers:
if not cuegui.Utils.isPermissible(self._getSource()):
cuegui.Utils.showErrorMessageBox(
JobActions.USER_INTERACTION_PERMISSIONS.format(
AbstractActions.USER_INTERACTION_PERMISSIONS.format(
"retry layers",
self._getSource().username())
)
Expand All @@ -873,7 +893,7 @@ def retryDead(self, rpcObjects=None):
if layers:
if not cuegui.Utils.isPermissible(self._getSource()):
cuegui.Utils.showErrorMessageBox(
JobActions.USER_INTERACTION_PERMISSIONS.format(
AbstractActions.USER_INTERACTION_PERMISSIONS.format(
"retry dead layers",
self._getSource().username())
)
Expand Down Expand Up @@ -1109,7 +1129,7 @@ def retry(self, rpcObjects=None):
# check permissions
if not cuegui.Utils.isPermissible(job):
cuegui.Utils.showErrorMessageBox(
JobActions.USER_INTERACTION_PERMISSIONS.format(
AbstractActions.USER_INTERACTION_PERMISSIONS.format(
"retry frames",
job.username())
)
Expand Down Expand Up @@ -1151,11 +1171,9 @@ def previewAovs(self, rpcObjects=None):
def eat(self, rpcObjects=None):
names = [frame.data.name for frame in self._getOnlyFrameObjects(rpcObjects)]
if names:
#check permissions
print(self._getSource())
if not cuegui.Utils.isPermissible(self._getSource()):
cuegui.Utils.showErrorMessageBox(
JobActions.USER_INTERACTION_PERMISSIONS.format(
AbstractActions.USER_INTERACTION_PERMISSIONS.format(
"eat frames",
self._getSource().username())
)
Expand All @@ -1173,7 +1191,7 @@ def kill(self, rpcObjects=None):
if names:
if not cuegui.Utils.isPermissible(self._getSource(), self):
cuegui.Utils.showErrorMessageBox(
JobActions.USER_INTERACTION_PERMISSIONS.format(
AbstractActions.USER_INTERACTION_PERMISSIONS.format(
"kill frames",
self._getSource().username()))
else:
Expand Down Expand Up @@ -1289,51 +1307,52 @@ def eatandmarkdone(self, rpcObjects=None):
#check permissions
if not cuegui.Utils.isPermissible(self._getSource(), self):
cuegui.Utils.showErrorMessageBox(
JobActions.USER_INTERACTION_PERMISSIONS.format(
AbstractActions.USER_INTERACTION_PERMISSIONS.format(
"eat and mark done frames",
self._getSource().username())
)
else:
if cuegui.Utils.questionBoxYesNo(
self._caller, "Confirm",
"Eat and Mark done all selected frames?\n"
"(Drops any dependencies that are waiting on these frames)\n\n"
"If a frame is part of a layer that will now only contain\n"
"eaten or succeeded frames, any dependencies on the\n"
"layer will be dropped as well.",
frameNames):

# Mark done the layers to drop their dependencies if the layer is done

if len(frames) == 1:
# Since only a single frame selected, check if layer is only one frame
layer = opencue.api.findLayer(self._getSource().data.name,
frames[0].data.layer_name)
if layer.data.layer_stats.total_frames == 1:
# Single frame selected of single frame layer, mark done and eat it all
layer.eat()
layer.markdone()

self._update()
return

self._getSource().eatFrames(name=frameNames)
self._getSource().markdoneFrames(name=frameNames)

# Warning: The below assumes that eaten frames are desired to be markdone

# Wait for the markDoneFrames to be processed, then drop the dependencies on
# the layer if all frames are done.
layerNames = [frame.data.layer_name for frame in frames]
time.sleep(1)
for layer in self._getSource().getLayers():
if layer.data.name in layerNames:
if (
layer.data.layer_stats.eaten_frames +
layer.data.layer_stats.succeeded_frames ==
layer.data.layer_stats.total_frames):
layer.markdone()
return
if not cuegui.Utils.questionBoxYesNo(
self._caller, "Confirm",
"Eat and Mark done all selected frames?\n"
"(Drops any dependencies that are waiting on these frames)\n\n"
"If a frame is part of a layer that will now only contain\n"
"eaten or succeeded frames, any dependencies on the\n"
"layer will be dropped as well.",
frameNames):
return

# Mark done the layers to drop their dependencies if the layer is done

if len(frames) == 1:
# Since only a single frame selected, check if layer is only one frame
layer = opencue.api.findLayer(self._getSource().data.name,
frames[0].data.layer_name)
if layer.data.layer_stats.total_frames == 1:
# Single frame selected of single frame layer, mark done and eat it all
layer.eat()
layer.markdone()

self._update()
return

self._getSource().eatFrames(name=frameNames)
self._getSource().markdoneFrames(name=frameNames)

# Warning: The below assumes that eaten frames are desired to be markdone

# Wait for the markDoneFrames to be processed, then drop the dependencies on
# the layer if all frames are done.
layerNames = [frame.data.layer_name for frame in frames]
time.sleep(1)
for layer in self._getSource().getLayers():
if layer.data.name in layerNames:
if (
layer.data.layer_stats.eaten_frames +
layer.data.layer_stats.succeeded_frames ==
layer.data.layer_stats.total_frames):
layer.markdone()
self._update()


class ShowActions(AbstractActions):
Expand Down Expand Up @@ -1766,17 +1785,19 @@ def view(self, rpcObjects=None):
def kill(self, rpcObjects=None):
procs = self._getOnlyProcObjects(rpcObjects)
if procs:
print(self._getSource())
if not cuegui.Utils.isPermissible(self._getSource(), self):
if not cuegui.Utils.isPermissible(self._getSource()):
cuegui.Utils.showErrorMessageBox(
JobActions.USER_INTERACTION_PERMISSIONS.format(
AbstractActions.USER_INTERACTION_PERMISSIONS.format(
"eat and mark done frames",
self._getSource().username())
)
else:
if cuegui.Utils.questionBoxYesNo(
self._caller, "Confirm", "Kill selected frames?",
["%s -> %s @ %s" % (proc.data.job_name, proc.data.frame_name, proc.data.name)
["%s -> %s @ %s" % (
proc.data.job_name,
proc.data.frame_name,
proc.data.name)
for proc in procs]):
for proc in procs:
self.cuebotCall(proc.kill,
Expand Down
14 changes: 5 additions & 9 deletions cuegui/cuegui/Utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@
import time
import traceback
import webbrowser
import yaml

from qtpy import QtCore
from qtpy import QtGui
from qtpy import QtWidgets
import getpass
import six

import opencue
Expand Down Expand Up @@ -683,14 +683,10 @@ def isPermissible(jobObject):
:ptype userName: Opencue Job Object
:return:
"""
hasPermissions = False
# Case 1. Check if current user is the job owner
# Read cached setting from user config file
hasPermissions = yaml.safe_load(cuegui.app().settings.value("EnableJobInteraction", "False"))
# If not set by default, check if current user is the job owner
currentUser = getpass.getuser()
if currentUser.lower() == jobObject.username().lower():
hasPermissions = True

# Case 2. Check if "Enable not owned Job Interactions" is Enabled
if bool(int(QtGui.qApp.settings.value("EnableJobInteraction", 0))):
if not hasPermissions and currentUser.lower() == jobObject.username().lower():
hasPermissions = True

return hasPermissions
Loading

0 comments on commit a61b939

Please sign in to comment.