jycache-model/hffs/hffs.py

56 lines
1.4 KiB
Python
Raw Permalink Normal View History

"""Entrypoint of HFFS."""
2024-06-26 15:59:19 +08:00
import asyncio
import logging
from argparse import Namespace
2024-06-26 15:59:19 +08:00
from hffs.client import model_cmd, peer_cmd, uninstall_cmd
from hffs.common.context import HffsContext
from hffs.config import conf_cmd, config_manager
from hffs.daemon import daemon_cmd
from hffs.utils import auth_cmd, logging as logging_utils
from hffs.utils.args import arg_parser
2024-06-26 15:59:19 +08:00
logger = logging.getLogger(__name__)
async def _exec_cmd(args: Namespace) -> None:
if args.command == "daemon":
exec_cmd = daemon_cmd.exec_cmd
elif args.command == "peer":
exec_cmd = peer_cmd.exec_cmd
elif args.command == "model":
exec_cmd = model_cmd.exec_cmd
elif args.command == "conf":
exec_cmd = conf_cmd.exec_cmd
elif args.command == "auth":
exec_cmd = auth_cmd.exec_cmd
elif args.command == "uninstall":
exec_cmd = uninstall_cmd.exec_cmd
2024-06-26 15:59:19 +08:00
else:
raise NotImplementedError
2024-06-26 15:59:19 +08:00
await exec_cmd(args)
2024-06-26 15:59:19 +08:00
async def _async_main() -> None:
config = config_manager.load_config()
HffsContext.init_with_config(config)
2024-06-26 15:59:19 +08:00
args = arg_parser()
logging_utils.setup_logging(args)
2024-06-26 15:59:19 +08:00
await _exec_cmd(args)
2024-06-26 15:59:19 +08:00
def main() -> None:
"""Entrypoint of HFFS."""
2024-06-26 15:59:19 +08:00
try:
asyncio.run(_async_main())
except (
KeyboardInterrupt,
asyncio.exceptions.CancelledError,
):
# ignore interrupt and cancel errors as they are handled by daemon
logger.info("Shutting down HFFS.")