mirror of
https://github.com/dw-0/kiauh.git
synced 2026-04-02 07:45:15 +05:00
Compare commits
1 Commits
a639bd09ce
...
df92ae25b2
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
df92ae25b2 |
@@ -10,8 +10,6 @@
|
|||||||
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,
|
||||||
)
|
)
|
||||||
@@ -19,16 +17,12 @@ 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__()
|
||||||
@@ -43,8 +37,6 @@ 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),
|
||||||
@@ -73,12 +65,6 @@ 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,12 +2,8 @@ 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 subprocess import CalledProcessError, PIPE, run
|
from typing import List
|
||||||
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
|
||||||
|
|
||||||
|
|
||||||
@@ -59,33 +55,3 @@ 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