Merge pull request #4919 from Michaelredaa/kitsu-sync-specific-projects

This commit is contained in:
Milan Kolar 2023-05-30 22:01:23 +02:00 committed by GitHub
commit c18e1d384d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 64 additions and 15 deletions

View file

@ -94,7 +94,7 @@ class KitsuModule(OpenPypeModule, IPluginPaths, ITrayAction):
return {
"publish": [os.path.join(current_dir, "plugins", "publish")],
"actions": [os.path.join(current_dir, "actions")]
"actions": [os.path.join(current_dir, "actions")],
}
def cli(self, click_group):
@ -128,15 +128,35 @@ def push_to_zou(login, password):
@click.option(
"-p", "--password", envvar="KITSU_PWD", help="Password for kitsu username"
)
def sync_service(login, password):
@click.option(
"-prj",
"--project",
"projects",
multiple=True,
default=[],
help="Sync specific kitsu projects",
)
@click.option(
"-lo",
"--listen-only",
"listen_only",
is_flag=True,
default=False,
help="Listen to events only without any syncing",
)
def sync_service(login, password, projects, listen_only):
"""Synchronize openpype database from Zou sever database.
Args:
login (str): Kitsu user login
password (str): Kitsu user password
projects (tuple): specific kitsu projects
listen_only (bool): run listen only without any syncing
"""
from .utils.update_op_with_zou import sync_all_projects
from .utils.sync_service import start_listeners
sync_all_projects(login, password)
if not listen_only:
sync_all_projects(login, password, filter_projects=projects)
start_listeners(login, password)

View file

@ -94,9 +94,7 @@ def update_op_assets(
if not item_doc: # Create asset
op_asset = create_op_asset(item)
insert_result = dbcon.insert_one(op_asset)
item_doc = get_asset_by_id(
project_name, insert_result.inserted_id
)
item_doc = get_asset_by_id(project_name, insert_result.inserted_id)
# Update asset
item_data = deepcopy(item_doc["data"])
@ -329,7 +327,7 @@ def write_project_to_op(project: dict, dbcon: AvalonMongoDB) -> UpdateOne:
"code": project_code,
"fps": float(project["fps"]),
"zou_id": project["id"],
"active": project['project_status_name'] != "Closed",
"active": project["project_status_name"] != "Closed",
}
)
@ -359,7 +357,10 @@ def write_project_to_op(project: dict, dbcon: AvalonMongoDB) -> UpdateOne:
def sync_all_projects(
login: str, password: str, ignore_projects: list = None
login: str,
password: str,
ignore_projects: list = None,
filter_projects: tuple = None,
):
"""Update all OP projects in DB with Zou data.
@ -367,6 +368,7 @@ def sync_all_projects(
login (str): Kitsu user login
password (str): Kitsu user password
ignore_projects (list): List of unsynced project names
filter_projects (tuple): Tuple of filter project names to sync with
Raises:
gazu.exception.AuthFailedException: Wrong user login and/or password
"""
@ -381,7 +383,24 @@ def sync_all_projects(
dbcon = AvalonMongoDB()
dbcon.install()
all_projects = gazu.project.all_projects()
for project in all_projects:
project_to_sync = []
if filter_projects:
all_kitsu_projects = {p["name"]: p for p in all_projects}
for proj_name in filter_projects:
if proj_name in all_kitsu_projects:
project_to_sync.append(all_kitsu_projects[proj_name])
else:
log.info(
f"`{proj_name}` project does not exist in Kitsu."
f" Please make sure the project is spelled correctly."
)
else:
# all project
project_to_sync = all_projects
for project in project_to_sync:
if ignore_projects and project["name"] in ignore_projects:
continue
sync_project_from_kitsu(dbcon, project)
@ -408,14 +427,13 @@ def sync_project_from_kitsu(dbcon: AvalonMongoDB, project: dict):
# Get all statuses for projects from Kitsu
all_status = gazu.project.all_project_status()
for status in all_status:
if project['project_status_id'] == status['id']:
project['project_status_name'] = status['name']
if project["project_status_id"] == status["id"]:
project["project_status_name"] = status["name"]
break
# Do not sync closed kitsu project that is not found in openpype
if (
project['project_status_name'] == "Closed"
and not get_project(project['name'])
if project["project_status_name"] == "Closed" and not get_project(
project["name"]
):
return
@ -444,7 +462,7 @@ def sync_project_from_kitsu(dbcon: AvalonMongoDB, project: dict):
log.info("Project created: {}".format(project_name))
bulk_writes.append(write_project_to_op(project, dbcon))
if project['project_status_name'] == "Closed":
if project["project_status_name"] == "Closed":
return
# Try to find project document