Skip to content
This repository has been archived by the owner on Sep 20, 2024. It is now read-only.

Commit

Permalink
Merge pull request #1157 from pypeclub/feature/ftrack_module_refactor
Browse files Browse the repository at this point in the history
Ftrack module refactor
  • Loading branch information
mkolar authored Mar 18, 2021
2 parents 8083534 + a48fa5f commit 4f08208
Show file tree
Hide file tree
Showing 56 changed files with 195 additions and 481 deletions.
8 changes: 4 additions & 4 deletions pype/lib/applications.py
Original file line number Diff line number Diff line change
Expand Up @@ -631,13 +631,13 @@ def discover_launch_hooks(self, force=False):
)
continue

modules = modules_from_path(path)
for _module in modules:
modules, _crashed = modules_from_path(path)
for _filepath, module in modules:
all_classes["pre"].extend(
classes_from_module(PreLaunchHook, _module)
classes_from_module(PreLaunchHook, module)
)
all_classes["post"].extend(
classes_from_module(PostLaunchHook, _module)
classes_from_module(PostLaunchHook, module)
)

for launch_type, classes in all_classes.items():
Expand Down
6 changes: 5 additions & 1 deletion pype/lib/mongo.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,10 +137,14 @@ class PypeMongoConnection:
mongo_clients = {}
log = logging.getLogger("PypeMongoConnection")

@staticmethod
def get_default_mongo_url():
return os.environ["PYPE_MONGO"]

@classmethod
def get_mongo_client(cls, mongo_url=None):
if mongo_url is None:
mongo_url = os.environ["PYPE_MONGO"]
mongo_url = cls.get_default_mongo_url()

connection = cls.mongo_clients.get(mongo_url)
if connection:
Expand Down
12 changes: 9 additions & 3 deletions pype/lib/python_module_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,15 @@ def modules_from_path(folder_path):
Arguments:
path (str): Path to folder containing python scripts.
return_crasher (bool): Crashed module paths with exception info
will be returned too.
Returns:
List of modules.
list, tuple: List of modules when `return_crashed` is False else tuple
with list of modules at first place and tuple of path and exception
info at second place.
"""
crashed = []
modules = []
# Just skip and return empty list if path is not set
if not folder_path:
Expand Down Expand Up @@ -67,16 +72,17 @@ def modules_from_path(folder_path):

module.__file__ = full_path

modules.append(module)
modules.append((full_path, module))

except Exception:
crashed.append((full_path, sys.exc_info()))
log.warning(
"Failed to load path: \"{0}\"".format(full_path),
exc_info=True
)
continue

return modules
return modules, crashed


def recursive_bases_from_class(klass):
Expand Down
13 changes: 1 addition & 12 deletions pype/modules/ftrack/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,9 @@
IFtrackEventHandlerPaths,
FTRACK_MODULE_DIR
)
from . import ftrack_server
from .ftrack_server import FtrackServer, check_ftrack_url
from .lib import BaseHandler, BaseEvent, BaseAction, ServerAction

__all__ = (
"FtrackModule",
"IFtrackEventHandlerPaths",
"FTRACK_MODULE_DIR",

"ftrack_server",
"FtrackServer",
"check_ftrack_url",
"BaseHandler",
"BaseEvent",
"BaseAction",
"ServerAction"
"FTRACK_MODULE_DIR"
)
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import time
import traceback

from pype.modules.ftrack import ServerAction
from pype.modules.ftrack.lib import ServerAction
from pype.modules.ftrack.lib.avalon_sync import SyncEntitiesFactory


Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
from pype.modules.ftrack.lib import BaseEvent
from pype.modules.ftrack.lib.avalon_sync import CUST_ATTR_ID_KEY
from pype.modules.ftrack.events.event_sync_to_avalon import SyncToAvalonEvent
from pype.modules.ftrack.event_handlers_server.event_sync_to_avalon import (
SyncToAvalonEvent
)


class DelAvalonIdFromNew(BaseEvent):
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from pype.modules.ftrack import BaseEvent
from pype.modules.ftrack.lib import BaseEvent


class FirstVersionStatus(BaseEvent):
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import collections
from pype.modules.ftrack import BaseEvent
from pype.modules.ftrack.lib import BaseEvent


class NextTaskUpdate(BaseEvent):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import datetime

import ftrack_api
from pype.modules.ftrack import BaseEvent
from pype.modules.ftrack.lib import BaseEvent


class PushFrameValuesToTaskEvent(BaseEvent):
Expand Down Expand Up @@ -272,10 +272,9 @@ def finalize(
if new_value == old_value:
continue

entity_key = collections.OrderedDict({
"configuration_id": attr_id,
"entity_id": entity_id
})
entity_key = collections.OrderedDict()
entity_key["configuration_id"] = attr_id
entity_key["entity_id"] = entity_id
self._cached_changes.append({
"attr_key": attr_key,
"entity_id": entity_id,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,20 @@
from bson.objectid import ObjectId
from pymongo import UpdateOne

import ftrack_api

from avalon import schema
from avalon.api import AvalonMongoDB

from pype.modules.ftrack.lib import avalon_sync
from pype.modules.ftrack.lib import (
avalon_sync,
BaseEvent
)
from pype.modules.ftrack.lib.avalon_sync import (
CUST_ATTR_ID_KEY, CUST_ATTR_AUTO_SYNC, EntitySchemas
CUST_ATTR_ID_KEY,
CUST_ATTR_AUTO_SYNC,
EntitySchemas
)
import ftrack_api
from pype.modules.ftrack import BaseEvent

from avalon.api import AvalonMongoDB


class SyncToAvalonEvent(BaseEvent):
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import collections
from pype.modules.ftrack import BaseEvent
from pype.modules.ftrack.lib import BaseEvent


class TaskStatusToParent(BaseEvent):
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import collections
from pype.modules.ftrack import BaseEvent
from pype.modules.ftrack.lib import BaseEvent


class TaskToVersionStatus(BaseEvent):
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import collections
from pype.modules.ftrack import BaseEvent
from pype.modules.ftrack.lib import BaseEvent


class ThumbnailEvents(BaseEvent):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import re
import subprocess

from pype.modules.ftrack import BaseEvent
from pype.modules.ftrack.lib import BaseEvent
from pype.modules.ftrack.lib.avalon_sync import CUST_ATTR_ID_KEY
from avalon.api import AvalonMongoDB

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from pype.modules.ftrack import BaseEvent
from pype.modules.ftrack.lib import BaseEvent


class VersionToTaskStatus(BaseEvent):
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import os
import requests
import errno
import json
import requests

from bson.objectid import ObjectId
from pype.modules.ftrack.lib import BaseAction, statics_icon
Expand Down
22 changes: 0 additions & 22 deletions pype/modules/ftrack/events/event_test.py

This file was deleted.

19 changes: 12 additions & 7 deletions pype/modules/ftrack/ftrack_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,21 @@ def initialize(self, settings):
self.ftrack_url = ftrack_settings["ftrack_server"]

current_dir = os.path.dirname(os.path.abspath(__file__))
self.server_event_handlers_paths = [
os.path.join(current_dir, "events"),
*ftrack_settings["ftrack_events_path"]
server_event_handlers_paths = [
os.path.join(current_dir, "event_handlers_server")
]
self.user_event_handlers_paths = [
os.path.join(current_dir, "actions"),
*ftrack_settings["ftrack_actions_path"]
server_event_handlers_paths.extend(
ftrack_settings["ftrack_events_path"]
)
user_event_handlers_paths = [
os.path.join(current_dir, "event_handlers_user")
]

user_event_handlers_paths.extend(
ftrack_settings["ftrack_actions_path"]
)
# Prepare attribute
self.server_event_handlers_paths = server_event_handlers_paths
self.user_event_handlers_paths = user_event_handlers_paths
self.tray_module = None

def get_global_environments(self):
Expand Down
Loading

0 comments on commit 4f08208

Please sign in to comment.