change gui with notebook tab
This commit is contained in:
parent
23a5c593ed
commit
a982c35c7d
1952
GitUtility.py
1952
GitUtility.py
File diff suppressed because it is too large
Load Diff
@ -1,44 +1,17 @@
|
||||
# -*- mode: python ; coding: utf-8 -*-
|
||||
|
||||
block_cipher = None
|
||||
|
||||
a = Analysis(
|
||||
['GitUtility.py'],
|
||||
pathex=[],
|
||||
binaries=[],
|
||||
datas=[('git_svn_sync.ini', '.')],
|
||||
hiddenimports=[],
|
||||
hookspath=[],
|
||||
hooksconfig={},
|
||||
runtime_hooks=[],
|
||||
excludes=[],
|
||||
noarchive=False,
|
||||
optimize=0,
|
||||
)
|
||||
pyz = PYZ(a.pure)
|
||||
a = Analysis(scripts=['C:\\src\\____GitProjects\\GitUtility\\GitUtility.py'], pathex=['C:\\src\\____GitProjects\\GitUtility'], binaries=[], datas=[('C:\\src\\____GitProjects\\GitUtility\\git_svn_sync.ini', '.')], hiddenimports=[], hookspath=[], runtime_hooks=[], excludes=[], win_no_prefer_redirects=False, win_private_assemblies=False, cipher=None, noarchive=False,)
|
||||
|
||||
exe = EXE(
|
||||
pyz,
|
||||
a.scripts,
|
||||
[],
|
||||
exclude_binaries=True,
|
||||
name='GitUtility',
|
||||
pyz = PYZ(a.pure, a.zipped_data, cipher=None)
|
||||
|
||||
exe = EXE(pyz, a.scripts, a.binaries, a.zipfiles, a.datas, [], name='GitUtility',
|
||||
debug=False,
|
||||
bootloader_ignore_signals=False,
|
||||
strip=False,
|
||||
upx=True,
|
||||
console=False,
|
||||
disable_windowed_traceback=False,
|
||||
argv_emulation=False,
|
||||
target_arch=None,
|
||||
codesign_identity=None,
|
||||
entitlements_file=None,
|
||||
)
|
||||
coll = COLLECT(
|
||||
exe,
|
||||
a.binaries,
|
||||
a.datas,
|
||||
strip=False,
|
||||
upx=True,
|
||||
upx_exclude=[],
|
||||
name='GitUtility',
|
||||
)
|
||||
runtime_tmpdir=None,
|
||||
console=False,)
|
||||
coll = COLLECT(exe, a.binaries, a.zipfiles, a.datas, strip=False, upx=True, upx_exclude=[], name='GitUtility',)
|
||||
|
||||
@ -6,10 +6,13 @@ import os
|
||||
from git_commands import GitCommands, GitCommandError
|
||||
from backup_handler import BackupHandler
|
||||
|
||||
|
||||
class ActionHandler:
|
||||
"""Handles the execution logic for core application actions."""
|
||||
|
||||
def __init__(self, logger, git_commands: GitCommands, backup_handler: BackupHandler):
|
||||
def __init__(
|
||||
self, logger, git_commands: GitCommands, backup_handler: BackupHandler
|
||||
):
|
||||
"""
|
||||
Initializes the ActionHandler.
|
||||
|
||||
@ -22,10 +25,15 @@ class ActionHandler:
|
||||
self.git_commands = git_commands
|
||||
self.backup_handler = backup_handler
|
||||
|
||||
|
||||
def _perform_backup_if_enabled(self, svn_path, profile_name,
|
||||
autobackup_enabled, backup_base_dir,
|
||||
excluded_extensions, excluded_dirs):
|
||||
def _perform_backup_if_enabled(
|
||||
self,
|
||||
svn_path,
|
||||
profile_name,
|
||||
autobackup_enabled,
|
||||
backup_base_dir,
|
||||
excluded_extensions,
|
||||
excluded_dirs,
|
||||
):
|
||||
"""
|
||||
Performs backup if enabled. Raises IOError on backup failure.
|
||||
|
||||
@ -53,7 +61,7 @@ class ActionHandler:
|
||||
backup_base_dir,
|
||||
profile_name,
|
||||
excluded_extensions,
|
||||
excluded_dirs
|
||||
excluded_dirs,
|
||||
)
|
||||
# Log success if backup handler doesn't raise an error
|
||||
self.logger.info(f"Backup completed successfully: {backup_path}")
|
||||
@ -65,7 +73,6 @@ class ActionHandler:
|
||||
# Standardize on IOError for backup failures passed up
|
||||
raise IOError(f"Autobackup failed: {backup_e}") from backup_e
|
||||
|
||||
|
||||
def execute_prepare_repo(self, svn_path):
|
||||
"""
|
||||
Executes the 'prepare repository' action.
|
||||
@ -98,11 +105,18 @@ class ActionHandler:
|
||||
self.logger.error(f"Failed to prepare repository: {e}", exc_info=True)
|
||||
raise
|
||||
|
||||
|
||||
def execute_create_bundle(self, svn_path, bundle_full_path, profile_name,
|
||||
autobackup_enabled, backup_base_dir,
|
||||
autocommit_enabled, commit_message,
|
||||
excluded_extensions, excluded_dirs):
|
||||
def execute_create_bundle(
|
||||
self,
|
||||
svn_path,
|
||||
bundle_full_path,
|
||||
profile_name,
|
||||
autobackup_enabled,
|
||||
backup_base_dir,
|
||||
autocommit_enabled,
|
||||
commit_message,
|
||||
excluded_extensions,
|
||||
excluded_dirs,
|
||||
):
|
||||
"""
|
||||
Executes 'create bundle', including backup and commit logic.
|
||||
|
||||
@ -126,8 +140,12 @@ class ActionHandler:
|
||||
# --- Backup Step ---
|
||||
# _perform_backup_if_enabled raises IOError on failure
|
||||
self._perform_backup_if_enabled(
|
||||
svn_path, profile_name, autobackup_enabled, backup_base_dir,
|
||||
excluded_extensions, excluded_dirs
|
||||
svn_path,
|
||||
profile_name,
|
||||
autobackup_enabled,
|
||||
backup_base_dir,
|
||||
excluded_extensions,
|
||||
excluded_dirs,
|
||||
)
|
||||
|
||||
# --- Autocommit Step ---
|
||||
@ -139,9 +157,14 @@ class ActionHandler:
|
||||
if has_changes:
|
||||
self.logger.info("Changes detected, performing autocommit...")
|
||||
# Use provided message or generate default
|
||||
commit_msg_to_use = commit_message if commit_message else \
|
||||
f"Autocommit '{profile_name}' before bundle"
|
||||
self.logger.debug(f"Using autocommit message: '{commit_msg_to_use}'")
|
||||
commit_msg_to_use = (
|
||||
commit_message
|
||||
if commit_message
|
||||
else f"Autocommit '{profile_name}' before bundle"
|
||||
)
|
||||
self.logger.debug(
|
||||
f"Using autocommit message: '{commit_msg_to_use}'"
|
||||
)
|
||||
# Perform commit (raises error on failure, returns bool)
|
||||
self.git_commands.git_commit(svn_path, commit_msg_to_use)
|
||||
# Log based on return value? git_commit already logs detail.
|
||||
@ -179,10 +202,16 @@ class ActionHandler:
|
||||
self.logger.error(f"Bundle creation failed: {bundle_e}", exc_info=True)
|
||||
raise bundle_e
|
||||
|
||||
|
||||
def execute_fetch_bundle(self, svn_path, bundle_full_path, profile_name,
|
||||
autobackup_enabled, backup_base_dir,
|
||||
excluded_extensions, excluded_dirs):
|
||||
def execute_fetch_bundle(
|
||||
self,
|
||||
svn_path,
|
||||
bundle_full_path,
|
||||
profile_name,
|
||||
autobackup_enabled,
|
||||
backup_base_dir,
|
||||
excluded_extensions,
|
||||
excluded_dirs,
|
||||
):
|
||||
"""
|
||||
Executes the 'fetch bundle' action, including backup logic.
|
||||
|
||||
@ -195,8 +224,12 @@ class ActionHandler:
|
||||
# --- Backup Step ---
|
||||
# Raises IOError on failure
|
||||
self._perform_backup_if_enabled(
|
||||
svn_path, profile_name, autobackup_enabled, backup_base_dir,
|
||||
excluded_extensions, excluded_dirs
|
||||
svn_path,
|
||||
profile_name,
|
||||
autobackup_enabled,
|
||||
backup_base_dir,
|
||||
excluded_extensions,
|
||||
excluded_dirs,
|
||||
)
|
||||
|
||||
# --- Fetch and Merge Step ---
|
||||
@ -211,7 +244,6 @@ class ActionHandler:
|
||||
self.logger.error(f"Fetch/merge failed: {fetch_e}", exc_info=True)
|
||||
raise fetch_e
|
||||
|
||||
|
||||
def execute_manual_commit(self, svn_path, commit_message):
|
||||
"""
|
||||
Executes a manual commit with the provided message.
|
||||
@ -242,7 +274,6 @@ class ActionHandler:
|
||||
self.logger.error(f"Manual commit failed: {e}", exc_info=True)
|
||||
raise
|
||||
|
||||
|
||||
def execute_create_tag(self, svn_path, commit_message, tag_name, tag_message):
|
||||
"""
|
||||
Executes tag creation, including pre-commit using commit_message if needed.
|
||||
@ -277,14 +308,15 @@ class ActionHandler:
|
||||
# git_commit raises error on failure, returns bool otherwise
|
||||
commit_made = self.git_commands.git_commit(svn_path, commit_message)
|
||||
# Log based on return value? git_commit logs details.
|
||||
self.logger.info(f"Pre-tag commit attempt finished (made={commit_made}).")
|
||||
self.logger.info(
|
||||
f"Pre-tag commit attempt finished (made={commit_made})."
|
||||
)
|
||||
else:
|
||||
self.logger.info("No uncommitted changes detected before tagging.")
|
||||
|
||||
except Exception as e:
|
||||
# Catch errors during status check or commit
|
||||
self.logger.error(f"Error during pre-tag commit step: {e}",
|
||||
exc_info=True)
|
||||
self.logger.error(f"Error during pre-tag commit step: {e}", exc_info=True)
|
||||
raise # Re-raise commit-related errors
|
||||
|
||||
# --- Create Tag Step ---
|
||||
@ -297,11 +329,9 @@ class ActionHandler:
|
||||
return True # Indicate success
|
||||
except Exception as e:
|
||||
# Catch errors during tag creation
|
||||
self.logger.error(f"Failed to create tag '{tag_name}': {e}",
|
||||
exc_info=True)
|
||||
self.logger.error(f"Failed to create tag '{tag_name}': {e}", exc_info=True)
|
||||
raise # Re-raise tag creation errors
|
||||
|
||||
|
||||
def execute_checkout_tag(self, svn_path, tag_name):
|
||||
"""
|
||||
Executes checkout for the specified tag after checking changes.
|
||||
@ -331,8 +361,7 @@ class ActionHandler:
|
||||
self.logger.debug("No uncommitted changes found.")
|
||||
except Exception as e:
|
||||
# Catch errors during status check
|
||||
self.logger.error(f"Status check error before checkout: {e}",
|
||||
exc_info=True)
|
||||
self.logger.error(f"Status check error before checkout: {e}", exc_info=True)
|
||||
raise # Re-raise status check errors
|
||||
|
||||
# --- Execute Checkout ---
|
||||
@ -348,11 +377,11 @@ class ActionHandler:
|
||||
raise GitCommandError("Checkout failed for unknown reason.")
|
||||
except Exception as e:
|
||||
# Catch errors during checkout (e.g., tag not found)
|
||||
self.logger.error(f"Failed to checkout tag '{tag_name}': {e}",
|
||||
exc_info=True)
|
||||
self.logger.error(
|
||||
f"Failed to checkout tag '{tag_name}': {e}", exc_info=True
|
||||
)
|
||||
raise # Re-raise checkout errors
|
||||
|
||||
|
||||
# --- Branch Actions ---
|
||||
def execute_create_branch(self, svn_path, branch_name, start_point=None):
|
||||
"""
|
||||
@ -363,8 +392,10 @@ class ActionHandler:
|
||||
Returns: True on success.
|
||||
Raises: GitCommandError/ValueError/Exception on failure.
|
||||
"""
|
||||
self.logger.info(f"Executing create branch '{branch_name}' "
|
||||
f"from '{start_point or 'HEAD'}'.")
|
||||
self.logger.info(
|
||||
f"Executing create branch '{branch_name}' "
|
||||
f"from '{start_point or 'HEAD'}'."
|
||||
)
|
||||
try:
|
||||
# Delegate to git_commands, raises error on failure
|
||||
self.git_commands.create_branch(svn_path, branch_name, start_point)
|
||||
@ -374,7 +405,6 @@ class ActionHandler:
|
||||
self.logger.error(f"Failed to create branch: {e}", exc_info=True)
|
||||
raise
|
||||
|
||||
|
||||
def execute_switch_branch(self, svn_path, branch_name):
|
||||
"""
|
||||
Executes branch switch after checking for changes.
|
||||
@ -398,8 +428,7 @@ class ActionHandler:
|
||||
self.logger.debug("No uncommitted changes found.")
|
||||
except Exception as e:
|
||||
# Catch errors during status check
|
||||
self.logger.error(f"Status check error before switch: {e}",
|
||||
exc_info=True)
|
||||
self.logger.error(f"Status check error before switch: {e}", exc_info=True)
|
||||
raise # Re-raise status check errors
|
||||
|
||||
# --- Execute Switch ---
|
||||
@ -409,11 +438,11 @@ class ActionHandler:
|
||||
return success
|
||||
except Exception as e:
|
||||
# Catch errors during switch (e.g., branch not found)
|
||||
self.logger.error(f"Failed switch to branch '{branch_name}': {e}",
|
||||
exc_info=True)
|
||||
self.logger.error(
|
||||
f"Failed switch to branch '{branch_name}': {e}", exc_info=True
|
||||
)
|
||||
raise
|
||||
|
||||
|
||||
def execute_delete_branch(self, svn_path, branch_name, force=False):
|
||||
"""
|
||||
Executes branch deletion.
|
||||
@ -434,11 +463,11 @@ class ActionHandler:
|
||||
return success
|
||||
except Exception as e:
|
||||
# Catch errors (like not merged, needs force)
|
||||
self.logger.error(f"Failed delete branch '{branch_name}': {e}",
|
||||
exc_info=True)
|
||||
self.logger.error(
|
||||
f"Failed delete branch '{branch_name}': {e}", exc_info=True
|
||||
)
|
||||
raise
|
||||
|
||||
|
||||
def execute_delete_tag(self, svn_path, tag_name):
|
||||
"""
|
||||
Executes deletion for the specified tag.
|
||||
@ -464,6 +493,5 @@ class ActionHandler:
|
||||
return success # Should be True if no exception
|
||||
except Exception as e:
|
||||
# Catch and re-raise errors from git_commands.delete_tag
|
||||
self.logger.error(f"Failed to delete tag '{tag_name}': {e}",
|
||||
exc_info=True)
|
||||
self.logger.error(f"Failed to delete tag '{tag_name}': {e}", exc_info=True)
|
||||
raise # Re-raise for the UI layer to handle
|
||||
@ -4,6 +4,7 @@ import datetime
|
||||
import zipfile
|
||||
import logging
|
||||
|
||||
|
||||
class BackupHandler:
|
||||
"""Handles the creation of ZIP backups with exclusions."""
|
||||
|
||||
@ -20,8 +21,14 @@ class BackupHandler:
|
||||
# to ConfigManager based on the current profile selected in the UI.
|
||||
# The create_zip_backup method now receives the parsed exclusions directly.
|
||||
|
||||
def create_zip_backup(self, source_repo_path, backup_base_dir,
|
||||
profile_name, excluded_extensions, excluded_dirs_base):
|
||||
def create_zip_backup(
|
||||
self,
|
||||
source_repo_path,
|
||||
backup_base_dir,
|
||||
profile_name,
|
||||
excluded_extensions,
|
||||
excluded_dirs_base,
|
||||
):
|
||||
"""
|
||||
Creates a timestamped ZIP backup of the source repository directory,
|
||||
respecting provided exclusions.
|
||||
@ -60,16 +67,17 @@ class BackupHandler:
|
||||
# exist_ok=True prevents error if directory already exists
|
||||
os.makedirs(backup_base_dir, exist_ok=True)
|
||||
except OSError as e:
|
||||
self.logger.error(f"Cannot create backup directory: {e}",
|
||||
exc_info=True)
|
||||
self.logger.error(f"Cannot create backup directory: {e}", exc_info=True)
|
||||
# Re-raise as IOError for the caller to potentially handle differently
|
||||
raise IOError(f"Could not create backup directory: {e}") from e
|
||||
|
||||
# --- 2. Construct Backup Filename ---
|
||||
now_str = datetime.datetime.now().strftime("%Y%m%d_%H%M%S")
|
||||
# Sanitize profile name for use in filename (remove potentially invalid chars)
|
||||
safe_profile = "".join(c for c in profile_name
|
||||
if c.isalnum() or c in '_-').rstrip() or "profile"
|
||||
safe_profile = (
|
||||
"".join(c for c in profile_name if c.isalnum() or c in "_-").rstrip()
|
||||
or "profile"
|
||||
)
|
||||
backup_filename = f"{now_str}_backup_{safe_profile}.zip"
|
||||
backup_full_path = os.path.join(backup_base_dir, backup_filename)
|
||||
self.logger.info(f"Target backup ZIP file: {backup_full_path}")
|
||||
@ -82,9 +90,9 @@ class BackupHandler:
|
||||
|
||||
try:
|
||||
# Open ZIP file with settings for compression and large files
|
||||
zip_f = zipfile.ZipFile(backup_full_path, 'w',
|
||||
compression=zipfile.ZIP_DEFLATED,
|
||||
allowZip64=True)
|
||||
zip_f = zipfile.ZipFile(
|
||||
backup_full_path, "w", compression=zipfile.ZIP_DEFLATED, allowZip64=True
|
||||
)
|
||||
|
||||
# Walk through the source directory tree
|
||||
for root, dirs, files in os.walk(source_repo_path, topdown=True):
|
||||
@ -111,8 +119,10 @@ class BackupHandler:
|
||||
file_ext_lower = file_ext.lower()
|
||||
|
||||
# Check exclusion rules (case-insensitive filename or extension)
|
||||
if filename.lower() in excluded_dirs_base or \
|
||||
file_ext_lower in excluded_extensions:
|
||||
if (
|
||||
filename.lower() in excluded_dirs_base
|
||||
or file_ext_lower in excluded_extensions
|
||||
):
|
||||
path_excluded = os.path.join(root, filename)
|
||||
self.logger.debug(f"Excluding file: {path_excluded}")
|
||||
files_excluded += 1
|
||||
@ -134,7 +144,7 @@ class BackupHandler:
|
||||
# Log error writing a specific file but allow backup to continue
|
||||
self.logger.error(
|
||||
f"Error writing file '{file_full_path}' to ZIP: {write_e}",
|
||||
exc_info=True
|
||||
exc_info=True,
|
||||
)
|
||||
# Consider marking the backup as potentially incomplete
|
||||
|
||||
|
||||
1009
git_commands.py
1009
git_commands.py
File diff suppressed because it is too large
Load Diff
@ -1,8 +1,10 @@
|
||||
# profile_handler.py
|
||||
import logging
|
||||
|
||||
# Assuming ConfigManager handles its own constants now
|
||||
from config_manager import ConfigManager, DEFAULT_PROFILE, DEFAULT_BACKUP_DIR
|
||||
|
||||
|
||||
class ProfileHandler:
|
||||
"""Handles loading, saving, adding, removing profiles via ConfigManager."""
|
||||
|
||||
@ -50,15 +52,16 @@ class ProfileHandler:
|
||||
|
||||
# Convert loaded string values back to appropriate types if needed
|
||||
# Example: Booleans
|
||||
profile_data["autocommit"] = \
|
||||
profile_data["autocommit"] = (
|
||||
str(profile_data.get("autocommit", "False")).lower() == "true"
|
||||
profile_data["autobackup"] = \
|
||||
)
|
||||
profile_data["autobackup"] = (
|
||||
str(profile_data.get("autobackup", "False")).lower() == "true"
|
||||
)
|
||||
|
||||
self.logger.debug(f"Loaded data for '{profile_name}': {profile_data}")
|
||||
return profile_data
|
||||
|
||||
|
||||
def save_profile_data(self, profile_name, profile_data):
|
||||
"""
|
||||
Saves the provided data dictionary to the specified profile name.
|
||||
@ -90,21 +93,19 @@ class ProfileHandler:
|
||||
# Assume other types can be directly converted to string
|
||||
value_to_save = str(value) if value is not None else ""
|
||||
|
||||
self.config_manager.set_profile_option(
|
||||
profile_name, key, value_to_save
|
||||
)
|
||||
self.config_manager.set_profile_option(profile_name, key, value_to_save)
|
||||
|
||||
# Persist changes to the configuration file
|
||||
self.config_manager.save_config()
|
||||
self.logger.info(f"Profile '{profile_name}' saved successfully.")
|
||||
return True
|
||||
except Exception as e:
|
||||
self.logger.error(f"Error saving profile '{profile_name}': {e}",
|
||||
exc_info=True)
|
||||
self.logger.error(
|
||||
f"Error saving profile '{profile_name}': {e}", exc_info=True
|
||||
)
|
||||
# Let the caller (main app) show the error message
|
||||
return False
|
||||
|
||||
|
||||
def add_new_profile(self, profile_name):
|
||||
"""
|
||||
Adds a new profile with default settings.
|
||||
@ -143,11 +144,11 @@ class ProfileHandler:
|
||||
return True
|
||||
except Exception as e:
|
||||
# Log unexpected errors during profile addition
|
||||
self.logger.error(f"Error adding profile '{profile_name}': {e}",
|
||||
exc_info=True)
|
||||
self.logger.error(
|
||||
f"Error adding profile '{profile_name}': {e}", exc_info=True
|
||||
)
|
||||
return False
|
||||
|
||||
|
||||
def remove_existing_profile(self, profile_name):
|
||||
"""
|
||||
Removes an existing profile (cannot remove the default profile).
|
||||
@ -180,10 +181,13 @@ class ProfileHandler:
|
||||
return True
|
||||
else:
|
||||
# ConfigManager should log the reason for failure
|
||||
self.logger.error(f"ConfigManager reported failure removing '{profile_name}'.")
|
||||
self.logger.error(
|
||||
f"ConfigManager reported failure removing '{profile_name}'."
|
||||
)
|
||||
return False
|
||||
except Exception as e:
|
||||
# Log unexpected errors during removal
|
||||
self.logger.error(f"Error removing profile '{profile_name}': {e}",
|
||||
exc_info=True)
|
||||
self.logger.error(
|
||||
f"Error removing profile '{profile_name}': {e}", exc_info=True
|
||||
)
|
||||
return False
|
||||
Loading…
Reference in New Issue
Block a user