mygramps/install_to_snap.sh
Daniel Viegas 5860b3d25c Improve code quality across the codebase
- Add comprehensive type hints to MyTimeline.py methods
  - Add type hints to __init__, change_db, and tooltip formatting methods
  - Use Any for Gramps-specific types that aren't easily importable

- Refactor generate_demo_family.py to use ElementTree
  - Replace string concatenation with xml.etree.ElementTree for proper XML generation
  - Add compatibility handling for Python < 3.9 (ET.indent)
  - Add EventData, PersonData, and FamilyData dataclasses for better structure
  - Add comprehensive type hints to all functions

- Extract magic numbers to named constants
  - Add constants for UI dimensions, timeline heights, dialog sizes
  - Add constants for date calculations and genealogical year ranges
  - Improve code readability and maintainability

- Refactor duplicated code in filter dialog handlers
  - Extract common checkbox handler logic into reusable methods
  - Create _make_group_toggle_handler and _make_child_toggle_handler
  - Eliminate code duplication between event type and family filters

- Improve shell scripts with better error handling
  - Add validation for Gramps installation
  - Improve error messages with actionable troubleshooting steps
  - Use set -euo pipefail for better error detection
  - Add better user guidance in error scenarios
2025-11-29 22:49:16 +01:00

183 lines
5.6 KiB
Bash
Executable File

#!/bin/bash
#
# Script to install MyTimeline plugin to snap-installed Gramps
#
# This script copies the MyTimeline plugin files to the Gramps snap plugin directory
# so it can be used in the snap-installed version of Gramps 6.0
#
set -euo pipefail # Exit on error, undefined vars, pipe failures
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
# Get the directory where this script is located
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# Source plugin files
PLUGIN_SRC_DIR="$SCRIPT_DIR"
PLUGIN_FILES=("MyTimeline.gpr.py" "MyTimeline.py")
# Target directory for snap-installed Gramps
# Gramps 6.0 plugins directory in snap
PLUGIN_DEST_DIR="$HOME/snap/gramps/current/.local/share/gramps/gramps60/plugins"
# Alternative locations to try (in case snap structure differs)
ALTERNATIVE_DIRS=(
"$HOME/snap/gramps/current/.local/share/gramps/gramps60/plugins"
"$HOME/snap/gramps/current/.gramps/gramps60/plugins"
"$HOME/snap/gramps/current/.gramps/plugins"
"$HOME/snap/gramps/common/.local/share/gramps/gramps60/plugins"
"$HOME/.local/share/gramps/gramps60/plugins"
"$HOME/.gramps/gramps60/plugins"
)
echo "=========================================="
echo "MyTimeline Plugin Installer for Snap Gramps"
echo "=========================================="
echo ""
# Function to check if Gramps is installed via snap
check_gramps_installed() {
if ! command -v gramps &> /dev/null && ! snap list gramps &> /dev/null; then
echo -e "${YELLOW}Warning: Gramps may not be installed via snap.${NC}"
echo "This script is designed for snap-installed Gramps."
echo "If Gramps is installed differently, you may need to manually install the plugin."
echo ""
read -p "Continue anyway? (y/N): " -n 1 -r
echo
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
echo "Installation cancelled."
exit 0
fi
fi
}
# Function to find the correct plugin directory
find_plugin_dir() {
# Try the primary location first
if [ -d "$PLUGIN_DEST_DIR" ]; then
echo "$PLUGIN_DEST_DIR"
return 0
fi
# Try alternative locations
for dir in "${ALTERNATIVE_DIRS[@]}"; do
if [ -d "$dir" ]; then
echo "$dir"
return 0
fi
done
# If not found, ask user or create the primary location
echo ""
echo -e "${YELLOW}Warning: Plugin directory not found in standard locations.${NC}"
echo "Attempting to create: $PLUGIN_DEST_DIR"
mkdir -p "$PLUGIN_DEST_DIR"
echo "$PLUGIN_DEST_DIR"
return 0
}
# Check if Gramps is installed
check_gramps_installed
# Verify source files exist
echo "Checking source files..."
MISSING_FILES=()
for file in "${PLUGIN_FILES[@]}"; do
if [ ! -f "$PLUGIN_SRC_DIR/$file" ]; then
MISSING_FILES+=("$file")
else
echo -e "${GREEN}${NC} Found: $file"
fi
done
if [ ${#MISSING_FILES[@]} -gt 0 ]; then
echo ""
echo -e "${RED}Error: Missing required plugin files:${NC}"
for file in "${MISSING_FILES[@]}"; do
echo " - $file"
done
echo ""
echo -e "${YELLOW}Troubleshooting:${NC}"
echo " 1. Make sure you're running this script from the directory containing the plugin files"
echo " 2. Verify that MyTimeline.gpr.py and MyTimeline.py exist in: $PLUGIN_SRC_DIR"
echo " 3. Check file permissions: ls -la $PLUGIN_SRC_DIR"
exit 1
fi
# Find the target directory
echo ""
echo "Locating Gramps plugin directory..."
TARGET_DIR=$(find_plugin_dir)
if [ -z "$TARGET_DIR" ]; then
echo -e "${RED}Error: Could not determine plugin directory location.${NC}"
echo ""
echo -e "${YELLOW}Troubleshooting:${NC}"
echo " 1. Verify Gramps is installed: snap list gramps"
echo " 2. Check if snap directory exists: ls -la $HOME/snap/gramps/"
echo " 3. Try running Gramps at least once to create the plugin directory"
echo " 4. Manually create the directory: mkdir -p $PLUGIN_DEST_DIR"
echo ""
echo "If the issue persists, you may need to install the plugin manually."
exit 1
fi
echo -e "${GREEN}${NC} Target directory: $TARGET_DIR"
echo ""
# Check if plugin already exists
PLUGIN_EXISTS=false
for file in "${PLUGIN_FILES[@]}"; do
if [ -f "$TARGET_DIR/$file" ]; then
PLUGIN_EXISTS=true
break
fi
done
# Backup existing plugin if it exists
if [ "$PLUGIN_EXISTS" = true ]; then
echo -e "${YELLOW}Warning: Plugin files already exist in target directory.${NC}"
BACKUP_DIR="$TARGET_DIR/mytimeline_backup_$(date +%Y%m%d_%H%M%S)"
echo "Creating backup in: $BACKUP_DIR"
mkdir -p "$BACKUP_DIR"
for file in "${PLUGIN_FILES[@]}"; do
if [ -f "$TARGET_DIR/$file" ]; then
cp "$TARGET_DIR/$file" "$BACKUP_DIR/"
fi
done
echo -e "${GREEN}${NC} Backup created"
echo ""
fi
# Copy plugin files
echo "Installing plugin files..."
for file in "${PLUGIN_FILES[@]}"; do
if ! cp "$PLUGIN_SRC_DIR/$file" "$TARGET_DIR/"; then
echo -e "${RED}Error: Failed to copy $file${NC}"
echo "Check file permissions and disk space."
exit 1
fi
echo -e "${GREEN}${NC} Installed: $file"
done
echo ""
echo "=========================================="
echo -e "${GREEN}Installation completed successfully!${NC}"
echo "=========================================="
echo ""
echo "Plugin files installed to:"
echo " $TARGET_DIR"
echo ""
echo "Next steps:"
echo " 1. Restart Gramps if it's currently running"
echo " 2. Go to Edit → Preferences → Plugins"
echo " 3. Enable the 'MyTimeline' plugin"
echo " 4. The plugin should appear in the Views menu under 'Families'"
echo ""