80 lines
3.0 KiB
Python
80 lines
3.0 KiB
Python
# --- FILE: gitsync_tool/logic/automation_handler.py ---
|
|
|
|
from typing import TYPE_CHECKING
|
|
|
|
from gitutility.async_tasks import async_workers
|
|
from gitutility.logging_setup import log_handler
|
|
from gitutility.config.config_manager import DEFAULT_REMOTE_NAME
|
|
|
|
# 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,
|
|
},
|
|
) |