Skip to content

Commit

Permalink
[cuegui] Move constants to a YAML config file. (#1242)
Browse files Browse the repository at this point in the history
  • Loading branch information
bcipriano authored Jan 26, 2023
1 parent f7cf0bd commit 8a33d83
Show file tree
Hide file tree
Showing 11 changed files with 442 additions and 140 deletions.
3 changes: 1 addition & 2 deletions cuebot/src/main/resources/opencue.properties
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,7 @@ protected_shows=testing
# -1 means shows should not get deactivated at all.
max_show_stale_days=-1

# These flags determine whether or not layers/frames will be readonly when job is finished.
# These flags determine whether layers/frames will be readonly when job is finished.
# If flags are set as true, layers/frames cannot be retried, eaten, edited dependency on, etc.
# In order to toggle the same functionility on cuegui side, set flags in cue_resources.yaml
layer.finished_jobs_readonly=false
frame.finished_jobs_readonly=false
214 changes: 134 additions & 80 deletions cuegui/cuegui/Constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,91 +17,165 @@
Application constants.
"""


from __future__ import print_function
from __future__ import division
from __future__ import absolute_import

import logging
import os
import platform

from PySide2 import QtCore
from PySide2 import QtGui
from PySide2 import QtWidgets
import yaml

import opencue
import opencue.config


possible_version_path = os.path.join(
os.path.abspath(os.path.join(__file__ , "../../..")), 'VERSION.in')
if os.path.exists(possible_version_path):
with open(possible_version_path) as fp:
VERSION = fp.read().strip()
else:
VERSION = "1.3.0"
__CONFIG_FILE_ENV_VAR = 'CUEGUI_CONFIG_FILE'
__DEFAULT_INI_PATH_ENV_VAR = 'CUEGUI_DEFAULT_INI_PATH'
__DEFAULT_CONFIG_FILE_NAME = 'cuegui.yaml'
__DEFAULT_CONFIG_FILE = os.path.join(
os.path.dirname(__file__), 'config', __DEFAULT_CONFIG_FILE_NAME)


def __getLogger():
"""Other code should use cuegui.Logger to get a logger; we avoid using that module here
to avoid creating a circular dependency."""
logger_format = logging.Formatter("%(levelname)-9s %(module)-10s %(message)s")
logger_stream = logging.StreamHandler()
logger_stream.setLevel(logging.INFO)
logger_stream.setFormatter(logger_format)
logger = logging.getLogger(__file__)
logger.addHandler(logger_stream)
return logger


def __loadConfigFromFile():
logger = __getLogger()
with open(__DEFAULT_CONFIG_FILE) as fp:
config = yaml.load(fp, Loader=yaml.SafeLoader)

user_config_file = None

logger.debug('Checking for cuegui config file path in %s', __CONFIG_FILE_ENV_VAR)
config_file_from_env = os.environ.get(__CONFIG_FILE_ENV_VAR)
if config_file_from_env and os.path.exists(config_file_from_env):
user_config_file = config_file_from_env

if not user_config_file:
config_file_from_user_profile = os.path.join(
opencue.config.config_base_directory(), __DEFAULT_CONFIG_FILE_NAME)
logger.debug('Checking for cuegui config at %s', config_file_from_user_profile)
if os.path.exists(config_file_from_user_profile):
user_config_file = config_file_from_user_profile

if user_config_file:
logger.info('Loading cuegui config from %s', user_config_file)
with open(user_config_file, 'r') as fp:
config.update(yaml.load(fp, Loader=yaml.SafeLoader))

return config


def __packaged_version():
possible_version_path = os.path.join(
os.path.abspath(os.path.join(__file__, "../../..")), 'VERSION.in')
if os.path.exists(possible_version_path):
with open(possible_version_path) as fp:
default_version = fp.read().strip()
return default_version
return "1.3.0"

STARTUP_NOTICE_DATE = 0
STARTUP_NOTICE_MSG = ""

JOB_UPDATE_DELAY = 10000 # msec
LAYER_UPDATE_DELAY = 10000 # msec
FRAME_UPDATE_DELAY = 10000 # msec
HOST_UPDATE_DELAY = 20000 # msec
AFTER_ACTION_UPDATE_DELAY = 1000 # msec
__config = __loadConfigFromFile()

MAX_LOG_POPUPS = 5
MINIMUM_UPDATE_INTERVAL = 5 # sec
VERSION = __config.get('version', __packaged_version())

FONT_SIZE = 10 # 8
STANDARD_FONT = QtGui.QFont("Luxi Sans", FONT_SIZE)
STANDARD_ROW_HEIGHT = 16 # 14
STARTUP_NOTICE_DATE = __config.get('startup_notice.date')
STARTUP_NOTICE_MSG = __config.get('startup_notice.msg')

MEMORY_WARNING_LEVEL = 5242880
JOB_UPDATE_DELAY = __config.get('refresh.job_update_delay')
LAYER_UPDATE_DELAY = __config.get('refresh.layer_update_delay')
FRAME_UPDATE_DELAY = __config.get('refresh.frame_update_delay')
HOST_UPDATE_DELAY = __config.get('refresh.host_update_delay')
AFTER_ACTION_UPDATE_DELAY = __config.get('refresh.after_action_update_delay')
MINIMUM_UPDATE_INTERVAL = __config.get('refresh.min_update_interval') // 1000

RESOURCE_PATH = os.path.dirname(__file__) + "/images"
DEFAULT_INI_PATH = os.getenv('CUEGUI_DEFAULT_INI_PATH', os.path.dirname(__file__) + '/config')
FONT_FAMILY = __config.get('style.font.family')
FONT_SIZE = __config.get('style.font.size')
STANDARD_FONT = QtGui.QFont(FONT_FAMILY, FONT_SIZE)

DEFAULT_PLUGIN_PATHS = [os.path.dirname(__file__) + "/plugins"]
RESOURCE_PATH = __config.get('paths.resources')
if not os.path.isabs(RESOURCE_PATH):
RESOURCE_PATH = os.path.abspath(os.path.join(os.path.dirname(__file__), RESOURCE_PATH))

LOGGER_FORMAT = "%(levelname)-9s %(module)-10s %(message)s"
LOGGER_LEVEL = "WARNING"
CONFIG_PATH = __config.get('paths.config')
if not os.path.isabs(CONFIG_PATH):
CONFIG_PATH = os.path.abspath(os.path.join(os.path.dirname(__file__), CONFIG_PATH))

EMAIL_SUBJECT_PREFIX = "cuemail: please check "
EMAIL_BODY_PREFIX = "Your PSTs request that you check "
EMAIL_BODY_SUFFIX = "\n\n"
EMAIL_DOMAIN = ""
DEFAULT_INI_PATH = os.getenv('CUEGUI_DEFAULT_INI_PATH', __config.get('paths.default_ini_path'))
if not os.path.isabs(DEFAULT_INI_PATH):
DEFAULT_INI_PATH = os.path.abspath(os.path.join(os.path.dirname(__file__), DEFAULT_INI_PATH))

GITHUB_CREATE_ISSUE_URL = 'https://github.com/AcademySoftwareFoundation/OpenCue/issues/new'
URL_USERGUIDE = "https://www.opencue.io/docs/"
URL_SUGGESTION = "%s?labels=enhancement&template=enhancement.md" % GITHUB_CREATE_ISSUE_URL
URL_BUG = "%s?labels=bug&template=bug_report.md" % GITHUB_CREATE_ISSUE_URL
DEFAULT_PLUGIN_PATHS = __config.get('paths.plugins')
for i, path in enumerate(DEFAULT_PLUGIN_PATHS):
if not os.path.isabs(path):
DEFAULT_PLUGIN_PATHS[i] = os.path.abspath(os.path.join(os.path.dirname(__file__), path))

if platform.system() == "Windows":
DEFAULT_EDITOR = "notepad"
LOGGER_FORMAT = __config.get('logger.format')
LOGGER_LEVEL = __config.get('logger.level')

EMAIL_SUBJECT_PREFIX = __config.get('email.subject_prefix')
EMAIL_BODY_PREFIX = __config.get('email.body_prefix')
EMAIL_BODY_SUFFIX = __config.get('email.body_suffix')
EMAIL_DOMAIN = __config.get('email.domain')

GITHUB_CREATE_ISSUE_URL = __config.get('links.issue.create')
URL_USERGUIDE = __config.get('links.user_guide')
URL_SUGGESTION = GITHUB_CREATE_ISSUE_URL + __config.get('links.issue.suggestion')
URL_BUG = GITHUB_CREATE_ISSUE_URL + __config.get('links.issue.bug')

if platform.system() == 'Windows':
DEFAULT_EDITOR = __config.get('editor.windows')
elif platform.system() == 'Darwin':
DEFAULT_EDITOR = __config.get('editor.mac')
else:
DEFAULT_EDITOR = "gview -R -m -M -U %s/gvimrc +" % DEFAULT_INI_PATH
DEFAULT_EDITOR = __config.get('editor.linux')
DEFAULT_EDITOR = DEFAULT_EDITOR.format(config_path=CONFIG_PATH)

LOG_ROOT_OS = __config.get('render_logs.root')

ALLOWED_TAGS = tuple(__config.get('allowed_tags'))

DARK_STYLE_SHEET = os.path.join(CONFIG_PATH, __config.get('style.style_sheet'))
COLOR_THEME = __config.get('style.color_theme')
__bg_colors = __config.get('style.colors.background')
COLOR_USER_1 = QtGui.QColor(*__bg_colors[0])
COLOR_USER_2 = QtGui.QColor(*__bg_colors[1])
COLOR_USER_3 = QtGui.QColor(*__bg_colors[2])
COLOR_USER_4 = QtGui.QColor(*__bg_colors[3])

__frame_colors = __config.get('style.colors.frame_state')
RGB_FRAME_STATE = {
opencue.api.job_pb2.DEAD: QtGui.QColor(*__frame_colors.get('DEAD')),
opencue.api.job_pb2.DEPEND: QtGui.QColor(*__frame_colors.get('DEPEND')),
opencue.api.job_pb2.EATEN: QtGui.QColor(*__frame_colors.get('EATEN')),
opencue.api.job_pb2.RUNNING: QtGui.QColor(*__frame_colors.get('RUNNING')),
opencue.api.job_pb2.SETUP: QtGui.QColor(*__frame_colors.get('SETUP')),
opencue.api.job_pb2.SUCCEEDED: QtGui.QColor(*__frame_colors.get('SUCCEEDED')),
opencue.api.job_pb2.WAITING: QtGui.QColor(*__frame_colors.get('WAITING')),
opencue.api.job_pb2.CHECKPOINT: QtGui.QColor(*__frame_colors.get('CHECKPOINT')),
}

EMPTY_INDEX = QtCore.QModelIndex()
MEMORY_WARNING_LEVEL = __config.get('memory_warning_level')

QVARIANT_CENTER = QtCore.Qt.AlignCenter
QVARIANT_RIGHT = QtCore.Qt.AlignRight
QVARIANT_NULL = None
QVARIANT_BLACK = QtGui.QColor(QtCore.Qt.black)
QVARIANT_GREY = QtGui.QColor(QtCore.Qt.gray)

ALLOWED_TAGS = ("general", "desktop", "playblast", "util", "preprocess", "wan", "cuda", "splathw",
'naiad', 'massive')

RGB_FRAME_STATE = {opencue.api.job_pb2.DEAD: QtGui.QColor(255, 0, 0),
opencue.api.job_pb2.DEPEND: QtGui.QColor(160, 32, 240),
opencue.api.job_pb2.EATEN: QtGui.QColor(150, 0, 0),
opencue.api.job_pb2.RUNNING: QtGui.QColor(200, 200, 55),
opencue.api.job_pb2.SETUP: QtGui.QColor(160, 32, 240),
opencue.api.job_pb2.SUCCEEDED: QtGui.QColor(55, 200, 55),
opencue.api.job_pb2.WAITING: QtGui.QColor(135, 207, 235),
opencue.api.job_pb2.CHECKPOINT: QtGui.QColor(61, 98, 247)}
QVARIANT_FRAME_STATE = \
dict((key, RGB_FRAME_STATE[key]) for key in list(RGB_FRAME_STATE.keys()))
LOG_HIGHLIGHT_ERROR = __config.get('render_logs.highlight.error')
LOG_HIGHLIGHT_WARN = __config.get('render_logs.highlight.warning')
LOG_HIGHLIGHT_INFO = __config.get('render_logs.highlight.info')

RESOURCE_LIMITS = __config.get('resources')

TYPE_JOB = QtWidgets.QTreeWidgetItem.UserType + 1
TYPE_LAYER = QtWidgets.QTreeWidgetItem.UserType + 2
Expand All @@ -120,27 +194,7 @@
TYPE_TASK = QtWidgets.QTreeWidgetItem.UserType + 15
TYPE_LIMIT = QtWidgets.QTreeWidgetItem.UserType + 16

COLUMN_INFO_DISPLAY = 2

DARK_STYLE_SHEET = os.path.join(DEFAULT_INI_PATH, "darkpalette.qss")
COLOR_THEME = "plastique"
COLOR_USER_1 = QtGui.QColor(50, 50, 100)
COLOR_USER_2 = QtGui.QColor(100, 100, 50)
COLOR_USER_3 = QtGui.QColor(0, 50, 0)
COLOR_USER_4 = QtGui.QColor(50, 30, 0)

QVARIANT_NULL = None
QT_MAX_INT = 2147483647

LOG_HIGHLIGHT_ERROR = [
'error', 'aborted', 'fatal', 'failed', 'killed', 'command not found',
'no licenses could be found', 'killMessage']
LOG_HIGHLIGHT_WARN = ['warning', 'not found']
LOG_HIGHLIGHT_INFO = ['info:', 'rqd cmd:']


LOG_ROOT_OS = {
"rhel7": "/shots",
"linux": "/shots",
"windows": "S:",
"mac": "/Users/shots"
}
COLUMN_INFO_DISPLAY = 2
5 changes: 2 additions & 3 deletions cuegui/cuegui/Config.py → cuegui/cuegui/Layout.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
# limitations under the License.


"""Functions for loading application state and settings from disk."""
"""Functions for loading application layout and other state from disk."""

from __future__ import print_function
from __future__ import division
Expand All @@ -39,8 +39,7 @@ def startup(app_name):
:return: settings object containing the loaded settings
:rtype: QtCore.QSettings
"""
# read saved config from disk
# copy default config
# E.g. ~/.config/.cuecommander/config.ini
config_path = "/.%s/config" % app_name.lower()
settings = QtCore.QSettings(QtCore.QSettings.IniFormat, QtCore.QSettings.UserScope, config_path)
logger.info('Reading config file from %s', settings.fileName())
Expand Down
4 changes: 2 additions & 2 deletions cuegui/cuegui/Main.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
from PySide2 import QtGui

import cuegui
import cuegui.Config
import cuegui.Layout
import cuegui.Constants
import cuegui.Logger
import cuegui.MainWindow
Expand Down Expand Up @@ -69,7 +69,7 @@ def startup(app_name, app_version, argv):

app.threadpool = cuegui.ThreadPool.ThreadPool(3, parent=app)

settings = cuegui.Config.startup(app_name)
settings = cuegui.Layout.startup(app_name)
app.settings = settings

cuegui.Style.init()
Expand Down
2 changes: 1 addition & 1 deletion cuegui/cuegui/Redirect.py
Original file line number Diff line number Diff line change
Expand Up @@ -543,7 +543,7 @@ def __isBurstSafe(self, alloc, procs, show):
burst target show burst and the number of cores being redirected. If
there's a number of cores that may not be possible to pick up by the
target show, that number should be lower than the threshold set in the
cue_resources config.
cuegui.yaml `resources` config.
@param alloc: The name of the allocation for the cores
@type alloc: str
Expand Down
18 changes: 3 additions & 15 deletions cuegui/cuegui/Utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@
from PySide2 import QtGui
from PySide2 import QtWidgets
import six
import yaml
from yaml.scanner import ScannerError

import opencue
import opencue.wrappers.group
Expand Down Expand Up @@ -389,26 +387,16 @@ def memoryToString(kmem, unit=None):
return "%.01fG" % (float(kmem) / pow(k, 2))


def getResourceConfig(path=None):
def getResourceConfig():
"""Reads the given yaml file and returns the entries as a dictionary.
If no config path is given, the default resources config will be read
If the given path does not exist, a warning will be printed and an empty
dictionary will be returned
@param path: The path for the yaml file to read
@type path: str
@return: The entries in the given yaml file
@return: Resource config settings
@rtype: dict<str:str>
"""
config = {}
if not path:
path = '{}/cue_resources.yaml'.format(cuegui.Constants.DEFAULT_INI_PATH)
try:
with open(path, 'r') as fileObject:
config = yaml.load(fileObject, Loader=yaml.SafeLoader)
except (IOError, ScannerError) as e:
print('WARNING: Could not read config file %s: %s' % (path, e))
return config
return cuegui.Constants.RESOURCE_LIMITS


################################################################################
Expand Down
28 changes: 0 additions & 28 deletions cuegui/cuegui/config/cue_resources.yaml

This file was deleted.

Loading

0 comments on commit 8a33d83

Please sign in to comment.