Skip to content

feat: Backlog/connect config #424

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 56 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
56 commits
Select commit Hold shift + click to select a range
8c42aaa
remove framework-widget
lluisCM Feb 7, 2024
d6233a9
Merge branch 'main' of github.com:ftrackhq/integrations
lluisCM Feb 7, 2024
d4f8153
Merge branch 'main' of github.com:ftrackhq/integrations
lluisCM Feb 7, 2024
5a9acf3
Merge branch 'main' of github.com:ftrackhq/integrations
lluisCM Feb 7, 2024
2a04cd7
Merge branch 'main' of github.com:ftrackhq/integrations
lluisCM Feb 8, 2024
6fc405f
Merge branch 'main' of github.com:ftrackhq/integrations
lluisCM Feb 8, 2024
90ab95e
Merge branch 'main' of github.com:ftrackhq/integrations
lluisCM Feb 8, 2024
3849d82
Merge branch 'main' of github.com:ftrackhq/integrations
lluisCM Feb 8, 2024
599b789
Merge branch 'main' of github.com:ftrackhq/integrations
lluisCM Feb 12, 2024
3f25798
Merge branch 'main' of github.com:ftrackhq/integrations
lluisCM Feb 12, 2024
95a0677
Merge branch 'main' of github.com:ftrackhq/integrations
lluisCM Feb 12, 2024
19f54de
Merge branch 'main' of github.com:ftrackhq/integrations
lluisCM Feb 12, 2024
398bd41
Merge branch 'main' of github.com:ftrackhq/integrations
lluisCM Feb 12, 2024
f760b3e
Merge branch 'main' of github.com:ftrackhq/integrations
lluisCM Feb 12, 2024
f4b9e97
Merge branch 'main' of github.com:ftrackhq/integrations
lluisCM Feb 12, 2024
b1d7554
Merge branch 'main' of github.com:ftrackhq/integrations
lluisCM Feb 12, 2024
e132d07
Merge branch 'main' of github.com:ftrackhq/integrations
lluisCM Feb 12, 2024
5477ad1
Merge branch 'main' of github.com:ftrackhq/integrations
lluisCM Feb 13, 2024
4b1a74f
Merge branch 'main' of github.com:ftrackhq/integrations
lluisCM Feb 14, 2024
b84d398
Merge branch 'main' of github.com:ftrackhq/integrations
lluisCM Feb 16, 2024
cbd2c2c
update date on publisher widget and timetracker widget
lluisCM Feb 16, 2024
1f48ab1
Merge branch 'main' of github.com:ftrackhq/integrations
lluisCM Feb 16, 2024
e3132db
Merge branch 'main' of github.com:ftrackhq/integrations
lluisCM Feb 20, 2024
bc67e17
Merge branch 'main' of github.com:ftrackhq/integrations
lluisCM Feb 21, 2024
391cde7
Merge branch 'main' of github.com:ftrackhq/integrations
lluisCM Feb 23, 2024
8e19633
Merge branch 'main' of github.com:ftrackhq/integrations
lluisCM Feb 26, 2024
acbfd19
Merge branch 'main' of github.com:ftrackhq/integrations
lluisCM Feb 26, 2024
1a6ea94
Merge branch 'main' of github.com:ftrackhq/integrations
lluisCM Feb 26, 2024
6a86252
Merge branch 'main' of github.com:ftrackhq/integrations
lluisCM Feb 27, 2024
1122fea
Merge branch 'main' of github.com:ftrackhq/integrations
lluisCM Mar 8, 2024
08ba490
Merge branch 'main' of github.com:ftrackhq/integrations
lluisCM Mar 8, 2024
4a7e8e1
Merge branch 'main' of github.com:ftrackhq/integrations
lluisCM Mar 8, 2024
88ec7a4
Merge branch 'main' of github.com:ftrackhq/integrations
lluisCM Mar 8, 2024
b06af7f
Merge branch 'main' of github.com:ftrackhq/integrations
lluisCM Mar 8, 2024
fc7a97a
Merge branch 'main' of github.com:ftrackhq/integrations
lluisCM Mar 11, 2024
51910e9
Merge branch 'main' of github.com:ftrackhq/integrations
lluisCM Mar 11, 2024
8b89581
Merge branch 'main' of github.com:ftrackhq/integrations
lluisCM Mar 11, 2024
d585549
Merge branch 'main' of github.com:ftrackhq/integrations
lluisCM Mar 12, 2024
525216c
clean up utils
lluisCM Mar 12, 2024
dae90f7
write and read yaml config file of connect, renamed the old config fi…
lluisCM Mar 12, 2024
4b64221
config file implemented, WIP but ready to be tested
lluisCM Mar 12, 2024
a4d5ab4
make sure connect_config has allways the default values
lluisCM Mar 13, 2024
1121ee7
WIP
lluisCM Mar 13, 2024
1e6e428
deprecate of get_plugin_diirectiories function
lluisCM Mar 13, 2024
4986dc0
plugin_path key working as expected
lluisCM Mar 13, 2024
89f19c4
connect using the config working
lluisCM Mar 13, 2024
73b8353
move get_connect_plugin_version to ftrack_utils
lluisCM Mar 13, 2024
7295830
Plugin name replacement working
lluisCM Mar 13, 2024
74a7515
Update apps/connect/source/ftrack_connect/ui/application.py
lluisCM Mar 18, 2024
57718ac
Update apps/connect/source/ftrack_connect/plugin_manager/__init__.py
lluisCM Mar 18, 2024
46c1878
Update apps/connect/source/ftrack_connect/utils/plugin.py
lluisCM Mar 18, 2024
45c0fa0
resolving environment variables works
lluisCM Mar 18, 2024
111f711
update release notes
lluisCM Mar 19, 2024
a60c728
align with utils cleanup branch
lluisCM Mar 20, 2024
bfae395
align with main
lluisCM Mar 20, 2024
5c35b07
align with main
lluisCM Apr 17, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions apps/connect/release_notes.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# ftrack Connect release Notes

## Upcoming

* [new] Support resolving local variables withing the same connect_config.yaml file and environment variables using ${name_of_the_key}
* [new] Custom launch_path setting on connect_config.yaml
* [deprecated] FTRACK_CONNECT_PLUGIN_PATH is deprecated in favor of plugin_path in the connect_config.yaml
* [new] Implemented connect_config.yaml file driven by FTRACK_CONNECT_CONFIG_PATH

## v3.0.0
2024-04-02

Expand Down
26 changes: 24 additions & 2 deletions apps/connect/source/ftrack_connect/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,16 @@
import pkg_resources
import importlib

from ftrack_connect.utils.config import (
get_connect_config,
write_connect_config_file_path,
verify_connect_config,
)
from ftrack_connect.utils.plugin import (
get_default_plugin_directory,
create_target_plugin_directory,
PLUGIN_DIRECTORIES,
)
from ftrack_connect.utils.log import get_default_log_directory


def main_connect(arguments=None):
Expand Down Expand Up @@ -85,8 +91,24 @@ def main_connect(arguments=None):
'ftrack_connect', level=loggingLevels[namespace.verbosity]
)

default_values = {
'type': 'connect_config',
'name': 'default-connect-config',
'plugin_path': [
get_default_plugin_directory(),
'${FTRACK_CONNECT_PLUGIN_PATH}',
],
'plugin_name': '*',
'launch_path': '${plugin_path}/${plugin_name}/launch',
}
connect_config = get_connect_config()
if not connect_config:
write_connect_config_file_path(default_values)
connect_config = get_connect_config()
connect_config = verify_connect_config(connect_config, default_values)

# Make sure plugin directory is created
create_target_plugin_directory(PLUGIN_DIRECTORIES[0])
create_target_plugin_directory(connect_config['plugin_path'][0])

single_instance = None
if not namespace.allow_multiple:
Expand Down
23 changes: 20 additions & 3 deletions apps/connect/source/ftrack_connect/plugin_manager/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@
from ftrack_connect.qt import QtWidgets, QtCore, QtGui

from ftrack_connect.utils.thread import qt_main_thread
from ftrack_connect.utils.plugin import PLUGIN_DIRECTORIES
from ftrack_connect.utils.config import (
get_connect_config,
get_connect_config_path,
)

from ftrack_connect.ui.widget.overlay import BlockingOverlay, BusyOverlay
import ftrack_connect.ui.application
Expand Down Expand Up @@ -57,12 +60,15 @@ def installed_plugins(self):
'''Return list of installed plugins'''
return self._installed_plugins

@property
def connect_config(self):
return self._connect_config

# default methods
def __init__(self, session, parent=None):
'''Instantiate the plugin widget.'''
super(PluginManager, self).__init__(session, parent=parent)
self._label = None
self._select_release_type_widget = None
self._search_bar = None
self._plugin_list_widget = None
self._button_layout = None
Expand All @@ -76,6 +82,14 @@ def __init__(self, session, parent=None):
self._initialised = False
self._installed_plugins = None

self._connect_config = get_connect_config()
if not self.connect_config:
raise FileNotFoundError(
f"Connect config file (ftrack_connect.yaml) not found in the "
f"following directory: {get_connect_config_path()}.\n"
f"Please provide one before continuing."
)

self._reset_plugin_list()
self._plugin_processor = PluginProcessor()

Expand Down Expand Up @@ -106,7 +120,10 @@ def build(self):
)
self.layout().addWidget(self._select_release_type_widget)
# plugin list
self._plugin_list_widget = DndPluginList()
self._plugin_list_widget = DndPluginList(
self.connect_config['plugin_path'][0]
)

self.layout().addWidget(self._plugin_list_widget)

# apply and reset button.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
from ftrack_connect.qt import QtWidgets, QtCore, QtGui

from ftrack_connect.utils.plugin import (
PLUGIN_DIRECTORIES,
get_plugin_json_url_from_environment,
fetch_github_releases,
get_plugin_data,
Expand Down Expand Up @@ -55,11 +54,11 @@ def downloadable_plugin_count(self):
'''Return downloadable plugin count.'''
return self._downloadable_plugin_count

def __init__(self, parent=None):
def __init__(self, default_plugin_directory=None, parent=None):
super(DndPluginList, self).__init__(parent=parent)

# Set the plugin directory to install to the first path on PLUGIN_DIRECTORIES
self.default_install_plugin_directory = PLUGIN_DIRECTORIES[0]
self.default_install_plugin_directory = default_plugin_directory

# If set, download plugins from this url instead of the releases
self._json_config_url = get_plugin_json_url_from_environment()
Expand Down
41 changes: 32 additions & 9 deletions apps/connect/source/ftrack_connect/ui/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import uuid
import logging
import weakref
import glob
from operator import itemgetter
import time
import qtawesome as qta
Expand All @@ -33,7 +34,6 @@
get_default_plugin_directory,
get_plugins_from_path,
get_plugin_data,
PLUGIN_DIRECTORIES,
)
from ftrack_connect.utils.credentials import (
load_credentials,
Expand All @@ -53,6 +53,10 @@
DiscoverApplications,
)

from ftrack_connect.utils.config import (
get_connect_config,
get_connect_config_path,
)
from ftrack_connect.utils.plugin import create_target_plugin_directory


Expand Down Expand Up @@ -159,6 +163,10 @@ def session(self):
def plugins(self):
return self._plugins

@property
def connect_config(self):
return self._connect_config

def __init__(self, theme='system', instance=None, log_level=None):
'''Initialise the main application window with *theme*, singleton
*instance* and custom *log_level*.'''
Expand All @@ -171,6 +179,14 @@ def __init__(self, theme='system', instance=None, log_level=None):
self.__connect_start_time = time.time()
self._log_level = log_level

self._connect_config = get_connect_config()
if not self.connect_config:
raise FileNotFoundError(
f"Connect config file (ftrack_connect.yaml) not found in the "
f"following directory: {get_connect_config_path()}.\n"
f"Please provide one before continuing."
)

self._discovered_plugins = (
self._discover_plugin_data_from_plugin_directories()
)
Expand Down Expand Up @@ -741,7 +757,7 @@ def _available_plugin_data_from_plugin_directories(self):

result = []
i = 0
for plugin_base_directory in PLUGIN_DIRECTORIES:
for plugin_base_directory in self.connect_config['plugin_path']:
current_dir_plugins = []
for plugin in self._gather_plugins(
plugin_base_directory, source_index=i
Expand Down Expand Up @@ -797,7 +813,7 @@ def _discover_plugin_data_from_plugin_directories(self):

result = []
i = 0
for plugin_base_directory in PLUGIN_DIRECTORIES:
for plugin_base_directory in self.connect_config['plugin_path']:
result.extend(
self._gather_plugins(plugin_base_directory, source_index=i)
)
Expand Down Expand Up @@ -1045,7 +1061,7 @@ def _show_about(self):

self.focus()

aboutDialog = _about.AboutDialog(self)
aboutDialog = _about.AboutDialog(self, self.connect_config)

environment_data = os.environ.copy()
environment_data.update(
Expand Down Expand Up @@ -1146,7 +1162,9 @@ def _open_default_plugin_directory(self):
'''Open default plugin directory in platform default file browser.'''

try:
create_target_plugin_directory(PLUGIN_DIRECTORIES[0])
create_target_plugin_directory(
self.connect_config['plugin_path'][0]
)
except OSError:
messageBox = QtWidgets.QMessageBox(parent=self)
messageBox.setIcon(QtWidgets.QMessageBox.Warning)
Expand All @@ -1169,10 +1187,15 @@ def _discover_applications(self):
f' {len(self.plugins)} plugins.'
)

for connect_plugin_path in [plugin['path'] for plugin in self.plugins]:
launcher_config_path = os.path.join(connect_plugin_path, 'launch')
if os.path.isdir(launcher_config_path):
launcher_config_paths.append(launcher_config_path)
if isinstance(self.connect_config['launch_path'], list):
for launch_path in self.connect_config['launch_path']:
found_dirs = glob.glob(
launch_path
) # We can use recursive=True if we want to look in the entire folder
if found_dirs:
for path in found_dirs:
if os.path.isdir(path):
launcher_config_paths.append(path)

# Create store containing launchable applications.
self._application_launcher = DiscoverApplications(
Expand Down
11 changes: 8 additions & 3 deletions apps/connect/source/ftrack_connect/ui/widget/about.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,17 @@
from ftrack_connect.utils.log import get_log_directory

from ftrack_connect.utils.directory import open_directory
from ftrack_connect.utils.plugin import PLUGIN_DIRECTORIES


class AboutDialog(QtWidgets.QDialog):
'''About widget.'''

def __init__(self, parent, icon=':ftrack/connect/logo/dark2x'):
def __init__(
self, parent, connect_config, icon=':ftrack/connect/logo/dark2x'
):
super(AboutDialog, self).__init__(parent)
self.connect_config = connect_config

self.setWindowTitle('About connect')
layout = QtWidgets.QVBoxLayout()
layout.setContentsMargins(20, 20, 20, 20)
Expand Down Expand Up @@ -208,7 +211,9 @@ def setInformation(self, versionData, user, server, widget_plugins):
)

source_dirs = ""
for index, plugin_directory in enumerate(PLUGIN_DIRECTORIES):
for index, plugin_directory in enumerate(
self.connect_config['plugin_path']
):
if index == 0:
index = 'Target'
source_dirs += sources_item_template.format(
Expand Down
74 changes: 74 additions & 0 deletions apps/connect/source/ftrack_connect/utils/config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
# :coding: utf-8
# :copyright: Copyright (c) 2024 ftrack

import os
import glob
import logging

import platformdirs

from ftrack_utils.yaml import (
read_yaml_file,
write_yaml_file,
substitute_placeholders,
)

logger = logging.getLogger(__name__)


def get_default_config_directory():
return platformdirs.user_data_dir('ftrack-connect', 'ftrack')


def get_connect_config_path():
'''Return Path of the ftrack_connect.yaml file'''
config_path = os.getenv(
'FTRACK_CONNECT_CONFIG_PATH', get_default_config_directory()
)
return config_path


def get_connect_config():
'''Return the content of the ftrack_connect.yaml file'''
config_path = get_connect_config_path()
yaml_files = glob.glob(os.path.join(config_path, '*.yaml'))

found_config = None
for yaml_file in yaml_files:
yaml_content = read_yaml_file(yaml_file)
if yaml_content.get('type') != 'connect_config':
logger.warning(
"Ignoring file {yaml_file} as is not tagged as connect_config type"
)
continue
try:
found_config = substitute_placeholders(yaml_content, yaml_content)
except Exception as e:
raise Exception(
f"Error found on parsing connect config file {yaml_file}. Error: {e}"
)
break

return found_config


def write_connect_config_file_path(content):
'''Write the content to the ftrack_connect.yaml file'''
config_path = get_connect_config_path()
config_file = os.path.join(config_path, 'ftrack_connect.yaml')

return write_yaml_file(config_file, content)


def verify_connect_config(connect_config, default_values):
'''
Make sure the given *connect_config* has all keys defined on the
*default_values*, if not, set the default values on it.
'''
for k, v in default_values.items():
if k not in connect_config.keys():
logger.warning(
f"Missing default {k} key on Connect_config file, setting it up with the default value: {v}"
)
connect_config[k] = v
return connect_config
9 changes: 3 additions & 6 deletions apps/connect/source/ftrack_connect/utils/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,9 @@ def get_default_plugin_directory():
return platformdirs.user_data_dir('ftrack-connect-plugins', 'ftrack')


PLUGIN_DIRECTORIES = [
os.path.expandvars(p)
for p in os.getenv(
'FTRACK_CONNECT_PLUGIN_PATH', get_default_plugin_directory()
).split(os.pathsep)
]
def get_plugin_directories_from_config(config_file):
# TODO: this one is deprecated as connect_config has deprecated this environment variable.
return config_file['FTRACK_CONNECT_PLUGIN_PATH'].split(os.pathsep)


def get_plugins_from_path(plugin_directory):
Expand Down
Loading
Loading