Skip to content

Conversation

mgazza
Copy link
Collaborator

@mgazza mgazza commented Sep 28, 2025

Summary

Enhanced the auto-updater downloader to use zip-based downloads with Python-only file copying for maximum safety. This naturally supports directory structures while preserving all user configurations.

Problem Solved

  • Chicken-and-egg: Can't list utils/* files in PREDBAT_FILES before they exist
  • Safety concern: Need to avoid overwriting user configurations like config/apps.yaml

Solution: Safe Zip + Python-Only

Changed to zip-based downloads with selective Python file copying:

  • Downloads entire repository as zip from GitHub releases
  • Only copies *.py files (never config, cache, or other files)
  • Creates directory structure for utils/*.py files
  • Preserves all user settings and configurations

Changes Made

  • Added predbat_update_download_zip(): Downloads full repo zip
  • Python-only copying: Only copies *.py files from extracted zip
  • Directory support: Creates e.g.utils/ and copies utils/*.py files
  • Safety first: Never copies config, cache, backup, or non-Python files
  • Backward compatible: Falls back to individual file downloads if needed

Key Safety Features

Preserves user configs: Never touches config/apps.yaml or other settings
Python code only: Only *.py files get updated
No overwrites: Ignores .bak, cache, and development files
Directory structure: Automatically creates utils/ for OO managers
Future-proof: Any new *.py files or directories work automatically

What Gets Copied

  • ✅ Root *.py files: predbat.py, config.py, utils.py, etc.
  • ✅ Subdirectory *.py files: utils/battery_manager.py, etc.
  • ✅ Directory structure: Creates utils/ as needed

What Gets Ignored (for safety)

  • config/apps.yaml (user settings preserved)
  • __pycache__/, .ruff_cache/ (development artifacts)
  • .bak, .git files (backup/development files)
  • ❌ Any non-Python files

How It Works

  1. Downloads https://github.com/springfall2008/batpred/archive/refs/tags/v8.25.1.zip
  2. Extracts to temporary directory
  3. Copies only *.py files from apps/predbat/ and subdirectories
  4. Creates directory structure as needed
  5. Cleans up temporary files

Impact

  • Users get complete Python code updates including directory structures
  • All user configurations remain untouched
  • Enables clean OO architecture with utils subdirectories
  • Zero risk of breaking user setups
  • Foundation for better code organization

This addresses the safety concern while enabling directory support for the OO architecture.

🤖 Generated with Claude Code

- Copy only Python files from zip download for safety
- Preserves user config files (config/apps.yaml etc)
- Creates directory structure for python files in subdirs
- Ignores cache, backup, and development files

This ensures only code gets updated, never user settings.
@mgazza mgazza force-pushed the feat/enhance-downloader-directory-support branch from 456b4ce to 47c1ac3 Compare September 28, 2025 14:36

# Move the file
if os.path.exists(source):
os.rename(source, dest)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if rename overwrites

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it works on linux/unix on windows it wont. we should use os.replace

…overwriting

- os.rename() fails on Windows when destination exists (raises FileExistsError)
- os.replace() provides consistent cross-platform overwrite behavior
- Ensures update process works reliably on both Unix and Windows systems
- Addresses platform-dependent file overwriting issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants