Skip to content

Commit

Permalink
[cuegui] Add dynamic version fetching for the CueGUI About menu (Acad…
Browse files Browse the repository at this point in the history
…emySoftwareFoundation#1517)

- Implemented new configuration options in cuegui.yaml:
- `cuegui.use.custom.version`: Toggle between using VERSION.in or custom
CueGUI version.
- `cuegui.custom.cmd.version.stable`: Command to fetch stable version
(`setenv OPENCUE_BETA 0`)
- `cuegui.custom.cmd.version.beta`: Command to fetch beta version
(`setenv OPENCUE_BETA 1`)
- Modified Constants.py to fetch version dynamically based on config.
- Updated MainWindows.py to display the correct version (stable or beta)
in the About menu.
- Fallback to VERSION.in if custom version is disabled.

---------

Signed-off-by: Ramon Figueiredo <[email protected]>
  • Loading branch information
ramonfigueiredo authored Sep 26, 2024
1 parent da2fe01 commit 4e0ec97
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 1 deletion.
20 changes: 19 additions & 1 deletion cuegui/cuegui/Constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

import logging
import os
import subprocess
import platform

from qtpy import QtGui
Expand Down Expand Up @@ -88,10 +89,27 @@ def __packaged_version():
return default_version
return "1.3.0"

def __get_version_from_cmd(command):
try:
result = subprocess.run(command, shell=True, capture_output=True, text=True, check=True)
return result.stdout.strip()
except subprocess.CalledProcessError as e:
print(f"Command failed with return code {e.returncode}: {e}")
except Exception as e:
print(f"Failed to get version from command: {e}")
return None

__config = __loadConfigFromFile()

VERSION = __config.get('version', __packaged_version())
# Decide which CueGUI version to show
if __config.get('cuegui.use.custom.version', False):
beta_version = os.getenv('OPENCUE_BETA', '0')
if beta_version == '1':
VERSION = __get_version_from_cmd(__config.get('cuegui.custom.cmd.version.beta'))
else:
VERSION = __get_version_from_cmd(__config.get('cuegui.custom.cmd.version.stable'))
else:
VERSION = __config.get('version', __packaged_version())

STARTUP_NOTICE_DATE = __config.get('startup_notice.date')
STARTUP_NOTICE_MSG = __config.get('startup_notice.msg')
Expand Down
7 changes: 7 additions & 0 deletions cuegui/cuegui/MainWindow.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,13 @@ def showStatusBarMessage(self, message, delay=5000):
def displayAbout(self):
"""Displays about text."""
msg = self.app_name + "\n\nA opencue tool\n\n"
msg += "CueGUI:\n%s\n\n" % cuegui.Constants.VERSION

if os.getenv('OPENCUE_BETA'):
msg += "(Beta Version)\n\n"
else:
msg += "(Stable Version)\n\n"

msg += "Qt:\n%s\n\n" % QtCore.qVersion()
msg += "Python:\n%s\n\n" % sys.version
QtWidgets.QMessageBox.about(self, "About", msg)
Expand Down
11 changes: 11 additions & 0 deletions cuegui/cuegui/config/cuegui.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
# Default CueGUI config file

# Configure how a version number should be acquired.
# - False, use the version number in VERSION.in
# - True, run the commands defined at cuegui.custom.cmd.version.beta (for beta) or cuegui.custom.cmd.version.stable (for stable) to acquire the version number
cuegui.use.custom.version: False
# Used to show the CueGUI beta version, if the environment variable OPENCUE_BETA = 1 (setenv OPENCUE_BETA 1)
# If the CueGUI beta version is enabled, it's possible to run a shell command to get the cuegui version or any other
# custom command specified in the environment configuration.
cuegui.custom.cmd.version.beta: "echo 1.0.0"
# Used to show the CueGUI stable version, if the environment variable OPENCUE_BETA = 0 (setenv OPENCUE_BETA 0)
cuegui.custom.cmd.version.stable: "echo 1.0.1"

logger.format: '%(levelname)-9s %(module)-10s %(message)s'
logger.level: 'WARNING'

Expand Down

0 comments on commit 4e0ec97

Please sign in to comment.