added cli commands for sync server

This commit is contained in:
Jakub Trllo 2022-08-31 14:43:10 +02:00
parent 0d67038a80
commit 1ff3b31d40
2 changed files with 56 additions and 3 deletions

View file

@ -1,11 +1,16 @@
import os
from bson.objectid import ObjectId
import sys
import time
from datetime import datetime
import threading
import platform
import copy
import signal
from collections import deque, defaultdict
import click
from bson.objectid import ObjectId
from openpype.client import get_projects
from openpype.modules import OpenPypeModule
from openpype_interfaces import ITrayModule
@ -2080,3 +2085,46 @@ class SyncServerModule(OpenPypeModule, ITrayModule):
settings ('presets')
"""
return presets[project_name]['sites'][site_name]['root']
def cli(self, click_group):
click_group.add_command(cli_main)
@click.group(SyncServerModule.name, help="SyncServer module related commands.")
def cli_main():
pass
@cli_main.command()
@click.option(
"-a",
"--active_site",
required=True,
help="Name of active stie")
def syncservice(active_site):
"""Launch sync server under entered site.
This should be ideally used by system service (such us systemd or upstart
on linux and window service).
"""
from openpype.modules import ModulesManager
os.environ["OPENPYPE_LOCAL_ID"] = active_site
def signal_handler(sig, frame):
print("You pressed Ctrl+C. Process ended.")
sync_server_module.server_exit()
sys.exit(0)
signal.signal(signal.SIGINT, signal_handler)
signal.signal(signal.SIGTERM, signal_handler)
manager = ModulesManager()
sync_server_module = manager.modules_by_name["sync_server"]
sync_server_module.server_init()
sync_server_module.server_start()
while True:
time.sleep(1.0)

View file

@ -4,6 +4,7 @@ import os
import sys
import json
import time
import signal
class PypeCommands:
@ -315,8 +316,12 @@ class PypeCommands:
pytest.main(args)
def syncserver(self, active_site):
"""Start running sync_server in background."""
import signal
"""Start running sync_server in background.
This functionality is available in directly in module cli commands.
`~/openpype_console module sync_server syncservice`
"""
os.environ["OPENPYPE_LOCAL_ID"] = active_site
def signal_handler(sig, frame):