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

View file

@ -18,9 +18,20 @@ This setting is available for all the users of the OpenPype instance.
## Synchronize
Updating OP with Kitsu data is executed running the `sync-service`, which requires to provide your Kitsu credentials with `-l, --login` and `-p, --password` or by setting the environment variables `KITSU_LOGIN` and `KITSU_PWD`. This process will request data from Kitsu and create/delete/update OP assets.
Once this sync is done, the thread will automatically start a loop to listen to Kitsu events.
- `-prj, --project` This flag accepts multiple project name to sync specific projects, and the default to sync all projects.
- `-lo, --listen-only` This flag to run listen to Kitsu events only without any sync.
Note: You must use one argument of `-pro` or `-lo`, because the listen only flag override syncing flag.
```bash
// sync all projects then run listen
openpype_console module kitsu sync-service -l me@domain.ext -p my_password
// sync specific projects then run listen
openpype_console module kitsu sync-service -l me@domain.ext -p my_password -prj project_name01 -prj project_name02
// start listen only for all projects
openpype_console module kitsu sync-service -l me@domain.ext -p my_password -lo
```
### Events listening