127 lines
5.1 KiB
Python
127 lines
5.1 KiB
Python
# --- FILE: gitsync_tool/logic/automation_handler.py ---
|
|
|
|
from typing import TYPE_CHECKING
|
|
from tkinter import simpledialog
|
|
|
|
from gitutility.async_tasks import async_workers
|
|
from gitutility.logging_setup import log_handler
|
|
from gitutility.config.config_manager import DEFAULT_REMOTE_NAME
|
|
from gitutility.gui.dialogs import SelectSubmoduleDialog
|
|
|
|
# Forward reference for type hinting
|
|
if TYPE_CHECKING:
|
|
from ..app import GitSvnSyncApp
|
|
|
|
class AutomationHandler:
|
|
"""
|
|
Handles logic for automated, multi-step tasks such as updating a wiki
|
|
or cleaning repository history.
|
|
"""
|
|
|
|
def __init__(self, app: "GitSvnSyncApp"):
|
|
"""
|
|
Initializes the AutomationHandler.
|
|
|
|
Args:
|
|
app: The main application instance.
|
|
"""
|
|
self.app = app
|
|
self.main_frame = app.main_frame
|
|
self.wiki_updater = app.wiki_updater
|
|
self.history_cleaner = app.history_cleaner
|
|
|
|
def update_gitea_wiki(self):
|
|
"""Starts the asynchronous task to update the Gitea wiki."""
|
|
func_name = "update_gitea_wiki"
|
|
log_handler.log_info(f"--- Action Triggered: Update Gitea Wiki ---", func_name=func_name)
|
|
|
|
svn_path = self.app._get_and_validate_svn_path("Update Gitea Wiki")
|
|
if not svn_path or not self.app._is_repo_ready(svn_path):
|
|
self.main_frame.show_error("Action Failed", "Repository path is invalid or not prepared.")
|
|
return
|
|
|
|
remote_url = self.main_frame.remote_url_var.get().strip()
|
|
if not remote_url:
|
|
self.main_frame.show_error("Action Failed", "Remote URL is not configured in the current profile.")
|
|
return
|
|
|
|
if not self.main_frame.ask_yes_no(
|
|
"Confirm Wiki Update",
|
|
"Update Gitea Wiki pages from local 'doc/' folder?\n"
|
|
"(This will clone the wiki, commit, and push changes.)"
|
|
):
|
|
self.main_frame.update_status_bar("Wiki update cancelled.")
|
|
return
|
|
|
|
args = (self.wiki_updater, svn_path, remote_url)
|
|
self.app._start_async_operation(
|
|
worker_func=async_workers.run_update_wiki_async,
|
|
args_tuple=args,
|
|
context_dict={"context": "update_wiki", "status_msg": "Updating Gitea Wiki..."},
|
|
)
|
|
|
|
def analyze_and_clean_history(self):
|
|
"""Starts the analysis phase for cleaning the repository history."""
|
|
func_name = "analyze_and_clean_history"
|
|
log_handler.log_info(f"--- Action Triggered: Analyze History for Cleaning ---", func_name=func_name)
|
|
|
|
svn_path = self.app._get_and_validate_svn_path("Analyze History")
|
|
if not svn_path or not self.app._is_repo_ready(svn_path):
|
|
self.main_frame.show_error("Action Failed", "Repository path is invalid or not prepared.")
|
|
return
|
|
|
|
args = (self.history_cleaner, svn_path)
|
|
self.app._start_async_operation(
|
|
worker_func=async_workers.run_analyze_repo_for_purge_async,
|
|
args_tuple=args,
|
|
context_dict={
|
|
"context": "analyze_history",
|
|
"status_msg": "Analyzing repository history...",
|
|
"repo_path": svn_path,
|
|
},
|
|
)
|
|
|
|
def clean_invalid_submodule(self):
|
|
"""
|
|
Handles the workflow for cleaning an invalid submodule state by asking the user for the path.
|
|
"""
|
|
func_name = "clean_invalid_submodule"
|
|
log_handler.log_info(f"--- Action Triggered: Clean Invalid Submodule ---", func_name=func_name)
|
|
|
|
svn_path = self.app._get_and_validate_svn_path("Clean Submodule State")
|
|
if not svn_path or not self.app._is_repo_ready(svn_path):
|
|
self.main_frame.show_error("Action Failed", "Repository path is invalid or not prepared.")
|
|
return
|
|
|
|
# --- MODIFICA CHIAVE: Torniamo a chiedere il percorso all'utente ---
|
|
submodule_path = simpledialog.askstring(
|
|
"Clean Submodule",
|
|
"Enter the relative path of the submodule to forcibly clean (e.g., 'libs/my-submodule'):",
|
|
parent=self.app.master
|
|
)
|
|
|
|
if not submodule_path or not submodule_path.strip():
|
|
self.main_frame.update_status_bar("Clean submodule cancelled.")
|
|
return
|
|
|
|
# Normalizza il percorso per coerenza
|
|
submodule_path = submodule_path.strip().replace("\\", "/")
|
|
|
|
if not self.main_frame.ask_yes_no(
|
|
"Confirm Destructive Clean",
|
|
f"This will forcibly remove all traces of '{submodule_path}' from the repository.\n\n"
|
|
"This is a recovery tool for inconsistent states. Proceed?"
|
|
):
|
|
self.main_frame.update_status_bar("Clean submodule cancelled.")
|
|
return
|
|
|
|
# Avviamo la nostra funzione di pulizia potenziata
|
|
args = (self.app.submodule_handler, svn_path, submodule_path)
|
|
self.app._start_async_operation(
|
|
worker_func=async_workers.run_force_clean_submodule_async,
|
|
args_tuple=args,
|
|
context_dict={
|
|
"context": "force_clean_submodule",
|
|
"status_msg": f"Forcibly cleaning submodule '{submodule_path}'..."
|
|
}
|
|
) |