mirror of
https://github.com/dw-0/kiauh.git
synced 2025-12-23 15:53:36 +05:00
Compare commits
2 Commits
df92ae25b2
...
a639bd09ce
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a639bd09ce | ||
|
|
b020f10967 |
@@ -10,6 +10,8 @@
|
|||||||
import textwrap
|
import textwrap
|
||||||
from typing import Type, Optional
|
from typing import Type, Optional
|
||||||
|
|
||||||
|
from components.klipper import KLIPPER_DIR
|
||||||
|
from components.klipper.klipper import Klipper
|
||||||
from components.klipper_firmware.menus.klipper_build_menu import (
|
from components.klipper_firmware.menus.klipper_build_menu import (
|
||||||
KlipperBuildFirmwareMenu,
|
KlipperBuildFirmwareMenu,
|
||||||
)
|
)
|
||||||
@@ -17,12 +19,16 @@ from components.klipper_firmware.menus.klipper_flash_menu import (
|
|||||||
KlipperFlashMethodMenu,
|
KlipperFlashMethodMenu,
|
||||||
KlipperSelectMcuConnectionMenu,
|
KlipperSelectMcuConnectionMenu,
|
||||||
)
|
)
|
||||||
|
from components.moonraker import MOONRAKER_DIR
|
||||||
|
from components.moonraker.moonraker import Moonraker
|
||||||
from core.menus import Option
|
from core.menus import Option
|
||||||
from core.menus.base_menu import BaseMenu
|
from core.menus.base_menu import BaseMenu
|
||||||
from utils.constants import COLOR_YELLOW, RESET_FORMAT
|
from utils.constants import COLOR_YELLOW, RESET_FORMAT
|
||||||
|
from utils.git_utils import rollback_repository
|
||||||
|
|
||||||
|
|
||||||
# noinspection PyUnusedLocal
|
# noinspection PyUnusedLocal
|
||||||
|
# noinspection PyMethodMayBeStatic
|
||||||
class AdvancedMenu(BaseMenu):
|
class AdvancedMenu(BaseMenu):
|
||||||
def __init__(self, previous_menu: Optional[Type[BaseMenu]] = None):
|
def __init__(self, previous_menu: Optional[Type[BaseMenu]] = None):
|
||||||
super().__init__()
|
super().__init__()
|
||||||
@@ -37,6 +43,8 @@ class AdvancedMenu(BaseMenu):
|
|||||||
|
|
||||||
def set_options(self):
|
def set_options(self):
|
||||||
self.options = {
|
self.options = {
|
||||||
|
"1": Option(method=self.klipper_rollback, menu=True),
|
||||||
|
"2": Option(method=self.moonraker_rollback, menu=True),
|
||||||
"3": Option(method=self.build, menu=True),
|
"3": Option(method=self.build, menu=True),
|
||||||
"4": Option(method=self.flash, menu=False),
|
"4": Option(method=self.flash, menu=False),
|
||||||
"5": Option(method=self.build_flash, menu=False),
|
"5": Option(method=self.build_flash, menu=False),
|
||||||
@@ -65,6 +73,12 @@ class AdvancedMenu(BaseMenu):
|
|||||||
)[1:]
|
)[1:]
|
||||||
print(menu, end="")
|
print(menu, end="")
|
||||||
|
|
||||||
|
def klipper_rollback(self, **kwargs):
|
||||||
|
rollback_repository(KLIPPER_DIR, Klipper)
|
||||||
|
|
||||||
|
def moonraker_rollback(self, **kwargs):
|
||||||
|
rollback_repository(MOONRAKER_DIR, Moonraker)
|
||||||
|
|
||||||
def build(self, **kwargs):
|
def build(self, **kwargs):
|
||||||
KlipperBuildFirmwareMenu(previous_menu=self.__class__).run()
|
KlipperBuildFirmwareMenu(previous_menu=self.__class__).run()
|
||||||
|
|
||||||
|
|||||||
@@ -2,8 +2,12 @@ import json
|
|||||||
import urllib.request
|
import urllib.request
|
||||||
from http.client import HTTPResponse
|
from http.client import HTTPResponse
|
||||||
from json import JSONDecodeError
|
from json import JSONDecodeError
|
||||||
from typing import List
|
from subprocess import CalledProcessError, PIPE, run
|
||||||
|
from typing import List, Type
|
||||||
|
|
||||||
|
from core.instance_manager.base_instance import BaseInstance
|
||||||
|
from core.instance_manager.instance_manager import InstanceManager
|
||||||
|
from utils.input_utils import get_number_input, get_confirm
|
||||||
from utils.logger import Logger
|
from utils.logger import Logger
|
||||||
|
|
||||||
|
|
||||||
@@ -55,3 +59,33 @@ def get_latest_unstable_tag(repo_path: str) -> str:
|
|||||||
except Exception:
|
except Exception:
|
||||||
Logger.print_error("Error while getting the latest unstable tag")
|
Logger.print_error("Error while getting the latest unstable tag")
|
||||||
raise
|
raise
|
||||||
|
|
||||||
|
|
||||||
|
def rollback_repository(repo_dir: str, instance: Type[BaseInstance]) -> None:
|
||||||
|
q1 = "How many commits do you want to roll back"
|
||||||
|
amount = get_number_input(q1, 1, allow_go_back=True)
|
||||||
|
|
||||||
|
im = InstanceManager(instance)
|
||||||
|
|
||||||
|
Logger.print_warn("Do not continue if you have ongoing prints!", start="\n")
|
||||||
|
Logger.print_warn(
|
||||||
|
f"All currently running {im.instance_type.__name__} services will be stopped!"
|
||||||
|
)
|
||||||
|
if not get_confirm(
|
||||||
|
f"Roll back {amount} commit{'s' if amount > 1 else ''}",
|
||||||
|
default_choice=False,
|
||||||
|
allow_go_back=True,
|
||||||
|
):
|
||||||
|
Logger.print_info("Aborting roll back ...")
|
||||||
|
return
|
||||||
|
|
||||||
|
im.stop_all_instance()
|
||||||
|
|
||||||
|
try:
|
||||||
|
cmd = ["git", "reset", "--hard", f"HEAD~{amount}"]
|
||||||
|
run(cmd, cwd=repo_dir, check=True, stdout=PIPE, stderr=PIPE)
|
||||||
|
Logger.print_ok(f"Rolled back {amount} commits!", start="\n")
|
||||||
|
except CalledProcessError as e:
|
||||||
|
Logger.print_error(f"An error occured during repo rollback:\n{e}")
|
||||||
|
|
||||||
|
im.start_all_instance()
|
||||||
|
|||||||
Reference in New Issue
Block a user