2023-08-30 17:00:29 +00:00
|
|
|
import logging
|
|
|
|
from abc import ABC, abstractmethod
|
|
|
|
from argparse import ArgumentParser, Namespace
|
2024-01-27 19:49:49 +00:00
|
|
|
from typing import Any
|
2023-08-30 17:00:29 +00:00
|
|
|
|
|
|
|
from github import Github
|
|
|
|
from github.Auth import AppAuth
|
|
|
|
|
2024-01-27 19:49:49 +00:00
|
|
|
from ryujinx_mako._const import (
|
|
|
|
APP_ID,
|
|
|
|
PRIVATE_KEY,
|
|
|
|
INSTALLATION_ID,
|
|
|
|
SCRIPT_NAME,
|
|
|
|
IS_DRY_RUN,
|
|
|
|
)
|
2023-08-30 17:00:29 +00:00
|
|
|
|
|
|
|
|
|
|
|
class Subcommand(ABC):
|
2024-01-27 19:49:49 +00:00
|
|
|
_subcommands: dict[str, Any] = {}
|
|
|
|
|
2023-08-30 17:00:29 +00:00
|
|
|
@abstractmethod
|
|
|
|
def __init__(self, parser: ArgumentParser):
|
|
|
|
parser.set_defaults(func=self.run)
|
|
|
|
|
|
|
|
@property
|
|
|
|
def logger(self):
|
|
|
|
return logging.getLogger(SCRIPT_NAME).getChild(
|
|
|
|
type(self).name().replace("-", "_")
|
|
|
|
)
|
|
|
|
|
|
|
|
@abstractmethod
|
|
|
|
def run(self, args: Namespace):
|
|
|
|
raise NotImplementedError()
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
@abstractmethod
|
|
|
|
def name() -> str:
|
|
|
|
raise NotImplementedError()
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
@abstractmethod
|
|
|
|
def description() -> str:
|
|
|
|
raise NotImplementedError()
|
|
|
|
|
2024-01-27 19:49:49 +00:00
|
|
|
@classmethod
|
|
|
|
def get_subcommand(cls, name: str):
|
|
|
|
return cls._subcommands[name]
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def add_subcommand(cls, name: str, subcommand):
|
|
|
|
if name in cls._subcommands.keys():
|
|
|
|
raise ValueError(f"Key '{name}' already exists in {cls}._subcommands")
|
|
|
|
cls._subcommands[name] = subcommand
|
|
|
|
|
2023-08-30 17:00:29 +00:00
|
|
|
|
|
|
|
class GithubSubcommand(Subcommand, ABC):
|
2024-01-27 19:49:49 +00:00
|
|
|
_github = (
|
|
|
|
Github(auth=AppAuth(APP_ID, PRIVATE_KEY).get_installation_auth(INSTALLATION_ID))
|
|
|
|
if not IS_DRY_RUN
|
|
|
|
else None
|
2023-08-30 17:00:29 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
@property
|
|
|
|
def github(self):
|
|
|
|
return type(self)._github
|