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 #1396 from pypeclub/feature/project_manager
Browse files Browse the repository at this point in the history
  • Loading branch information
mkolar authored May 19, 2021
2 parents c80bdef + c5525ab commit 2b8233d
Show file tree
Hide file tree
Showing 25 changed files with 4,038 additions and 8 deletions.
5 changes: 5 additions & 0 deletions openpype/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,11 @@ def launch(app, project, asset, task,
PypeCommands().run_application(app, project, asset, task, tools, arguments)


@main.command(context_settings={"ignore_unknown_options": True})
def projectmanager():
PypeCommands().launch_project_manager()


@main.command(
context_settings=dict(
ignore_unknown_options=True,
Expand Down
8 changes: 8 additions & 0 deletions openpype/lib/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@
)

from .avalon_context import (
CURRENT_DOC_SCHEMAS,
PROJECT_NAME_ALLOWED_SYMBOLS,
PROJECT_NAME_REGEX,
create_project,
is_latest,
any_outdated,
get_asset,
Expand Down Expand Up @@ -163,6 +167,10 @@
"recursive_bases_from_class",
"classes_from_module",

"CURRENT_DOC_SCHEMAS",
"PROJECT_NAME_ALLOWED_SYMBOLS",
"PROJECT_NAME_REGEX",
"create_project",
"is_latest",
"any_outdated",
"get_asset",
Expand Down
93 changes: 93 additions & 0 deletions openpype/lib/avalon_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,99 @@
log = logging.getLogger("AvalonContext")


CURRENT_DOC_SCHEMAS = {
"project": "openpype:project-3.0",
"asset": "openpype:asset-3.0",
"config": "openpype:config-2.0"
}
PROJECT_NAME_ALLOWED_SYMBOLS = "a-zA-Z0-9_"
PROJECT_NAME_REGEX = re.compile(
"^[{}]+$".format(PROJECT_NAME_ALLOWED_SYMBOLS)
)


def create_project(
project_name, project_code, library_project=False, dbcon=None
):
"""Create project using OpenPype settings.
This project creation function is not validating project document on
creation. It is because project document is created blindly with only
minimum required information about project which is it's name, code, type
and schema.
Entered project name must be unique and project must not exist yet.
Args:
project_name(str): New project name. Should be unique.
project_code(str): Project's code should be unique too.
library_project(bool): Project is library project.
dbcon(AvalonMongoDB): Object of connection to MongoDB.
Raises:
ValueError: When project name already exists in MongoDB.
Returns:
dict: Created project document.
"""

from openpype.settings import ProjectSettings, SaveWarningExc
from avalon.api import AvalonMongoDB
from avalon.schema import validate

if dbcon is None:
dbcon = AvalonMongoDB()

if not PROJECT_NAME_REGEX.match(project_name):
raise ValueError((
"Project name \"{}\" contain invalid characters"
).format(project_name))

database = dbcon.database
project_doc = database[project_name].find_one(
{"type": "project"},
{"name": 1}
)
if project_doc:
raise ValueError("Project with name \"{}\" already exists".format(
project_name
))

project_doc = {
"type": "project",
"name": project_name,
"data": {
"code": project_code,
"library_project": library_project
},
"schema": CURRENT_DOC_SCHEMAS["project"]
}
# Insert document with basic data
database[project_name].insert_one(project_doc)
# Load ProjectSettings for the project and save it to store all attributes
# and Anatomy
try:
project_settings_entity = ProjectSettings(project_name)
project_settings_entity.save()
except SaveWarningExc as exc:
print(str(exc))
except Exception:
database[project_name].delete_one({"type": "project"})
raise

project_doc = database[project_name].find_one({"type": "project"})

try:
# Validate created project document
validate(project_doc)
except Exception:
# Remove project if is not valid
database[project_name].delete_one({"type": "project"})
raise

return project_doc


def with_avalon(func):
@functools.wraps(func)
def wrap_avalon(*args, **kwargs):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,7 @@

BaseEvent
)
from openpype.modules.ftrack.lib.avalon_sync import (
EntitySchemas
)
from openpype.lib import CURRENT_DOC_SCHEMAS


class SyncToAvalonEvent(BaseEvent):
Expand Down Expand Up @@ -1128,7 +1126,7 @@ def create_entity_in_avalon(self, ftrack_ent, parent_avalon):
"_id": mongo_id,
"name": name,
"type": "asset",
"schema": EntitySchemas["asset"],
"schema": CURRENT_DOC_SCHEMAS["asset"],
"parent": proj["_id"],
"data": {
"ftrackId": ftrack_ent["id"],
Expand Down
8 changes: 4 additions & 4 deletions openpype/modules/ftrack/lib/avalon_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@


# Current schemas for avalon types
EntitySchemas = {
CURRENT_DOC_SCHEMAS = {
"project": "openpype:project-3.0",
"asset": "openpype:asset-3.0",
"config": "openpype:config-2.0"
Expand Down Expand Up @@ -1862,7 +1862,7 @@ def create_avalon_entity(self, ftrack_id):

item["_id"] = new_id
item["parent"] = self.avalon_project_id
item["schema"] = EntitySchemas["asset"]
item["schema"] = CURRENT_DOC_SCHEMAS["asset"]
item["data"]["visualParent"] = avalon_parent

new_id_str = str(new_id)
Expand Down Expand Up @@ -2003,8 +2003,8 @@ def create_avalon_project(self):

project_item["_id"] = new_id
project_item["parent"] = None
project_item["schema"] = EntitySchemas["project"]
project_item["config"]["schema"] = EntitySchemas["config"]
project_item["schema"] = CURRENT_DOC_SCHEMAS["project"]
project_item["config"]["schema"] = CURRENT_DOC_SCHEMAS["config"]

self.ftrack_avalon_mapper[self.ft_project_id] = new_id
self.avalon_ftrack_mapper[new_id] = self.ft_project_id
Expand Down
6 changes: 6 additions & 0 deletions openpype/pype_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,12 @@ def extractenvironments(output_json_path, project, asset, task, app):
with open(output_json_path, "w") as file_stream:
json.dump(env, file_stream, indent=4)

@staticmethod
def launch_project_manager():
from openpype.tools import project_manager

project_manager.main()

def texture_copy(self, project, asset, path):
pass

Expand Down
10 changes: 10 additions & 0 deletions openpype/tools/project_manager/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from .project_manager import (
ProjectManagerWindow,
main
)


__all__ = (
"ProjectManagerWindow",
"main"
)
5 changes: 5 additions & 0 deletions openpype/tools/project_manager/__main__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from project_manager import main


if __name__ == "__main__":
main()
50 changes: 50 additions & 0 deletions openpype/tools/project_manager/project_manager/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
__all__ = (
"IDENTIFIER_ROLE",

"HierarchyView",

"ProjectModel",
"CreateProjectDialog",

"HierarchyModel",
"HierarchySelectionModel",
"BaseItem",
"RootItem",
"ProjectItem",
"AssetItem",
"TaskItem",

"ProjectManagerWindow",
"main"
)


from .constants import (
IDENTIFIER_ROLE
)
from .widgets import CreateProjectDialog
from .view import HierarchyView
from .model import (
ProjectModel,

HierarchyModel,
HierarchySelectionModel,
BaseItem,
RootItem,
ProjectItem,
AssetItem,
TaskItem
)
from .window import ProjectManagerWindow


def main():
import sys
from Qt import QtWidgets

app = QtWidgets.QApplication([])

window = ProjectManagerWindow()
window.show()

sys.exit(app.exec_())
13 changes: 13 additions & 0 deletions openpype/tools/project_manager/project_manager/constants.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import re
from Qt import QtCore


IDENTIFIER_ROLE = QtCore.Qt.UserRole + 1
DUPLICATED_ROLE = QtCore.Qt.UserRole + 2
HIERARCHY_CHANGE_ABLE_ROLE = QtCore.Qt.UserRole + 3
REMOVED_ROLE = QtCore.Qt.UserRole + 4
ITEM_TYPE_ROLE = QtCore.Qt.UserRole + 5
EDITOR_OPENED_ROLE = QtCore.Qt.UserRole + 6

NAME_ALLOWED_SYMBOLS = "a-zA-Z0-9_"
NAME_REGEX = re.compile("^[" + NAME_ALLOWED_SYMBOLS + "]*$")
Loading

0 comments on commit 2b8233d

Please sign in to comment.