forgejo-sync-manager-core v1.0.2

Universal core library for Forgejo repository synchronization

Reusable Python library providing core functionality for CLI and GUI applications.

Python Forgejo Repository Manager Git PyPI Cross-Platform

forgejo-sync-manager-core — a reusable Python library that provides the core functionality for synchronizing Forgejo repositories. Designed to be used by both CLI and GUI applications, ensuring code reuse and consistency across different interfaces.

Requirements: Python 3.8+, Git, Forgejo server with API access, requests library.

  • Forgejo API Client — token-based authentication
  • Repository Discovery — with pagination support
  • Git Repository Cloning — and updating
  • Repository Recloning — functionality
  • Local Repository Checking — existence verification
  • Path Management — for local storage
  • Cross-Platform — Linux, Windows, macOS
  • Abstract Base Classes — for easy extension

Core Classes:

ClassDescription
ForgejoAuthAuthentication container for server URL and token
ForgejoAPIClientAPI client for Forgejo REST API
ConfigManagerConfiguration file management (JSON)
BaseSyncManagerAbstract base class for sync operations

Sync Managers:

ClassPurpose
GUISyncManagerLightweight manager for GUI applications (no console output)
CLISyncManagerFull-featured manager with console progress output

git clone https://github.com/smartlegionlab/forgejo-sync-manager-core.git
cd forgejo-sync-manager-core
python -m venv venv
pip install -r requirements.txt

Basic Authentication:

from forgejo_sync_manager_core.core.auth import ForgejoAuth

auth = ForgejoAuth(
    token="your_token",
    server_url="http://localhost:3000",
    username="your_username"
)

API Client:

from forgejo_sync_manager_core.core.api_client import ForgejoAPIClient

client = ForgejoAPIClient(auth)
user_info = client.get_user_info()
repositories = client.get_user_repos()

Sync Manager for GUI Applications:

from forgejo_sync_manager_core.core.sync_manager_gui import GUISyncManager

sync_manager = GUISyncManager(auth)
sync_manager.ensure_directories()

for repo in repositories:
    status = sync_manager.sync_repository(repo)
    # status: "CLONED", "UPDATED", "FAILED"

Sync Manager for CLI Applications:

from forgejo_sync_manager_core.core.sync_manager_cli import CLISyncManager

sync_manager = CLISyncManager(auth)
results = sync_manager.sync_all_repositories(repositories)
# results: {"cloned": 0, "updated": 0, "failed": 0}

StatusDescription
CLONEDRepository was successfully cloned
UPDATEDExisting repository was successfully updated
RECLONEDRepository was deleted and re-cloned
FAILEDOperation failed

  1. Authentication — Token-based authentication via Forgejo API
  2. Repository Discovery — Fetches complete repository list with pagination (50 per page)
  3. Update Detection (CLI only) — Executes git fetch and compares HEAD with FETCH_HEAD
  4. Sync Operations — Uses authenticated URLs with embedded token for Git operations
  5. Directory Structure~/forgejo-sync-manager/{username}/repositories/

Configuration is stored in ~/forgejo-sync-manager/config.json:

{
    "token": "your_access_token",
    "server_url": "http://localhost:3000",
    "username": "your_username"
}

This core library is used in the following projects:

By using this software, you agree to the full disclaimer terms.

Software provided "AS IS" without warranty. You assume all risks.

Full legal disclaimer: See DISCLAIMER.md

License: BSD 3-Clause License