Skip to content

services.py — Constants, Helpers, Extension Mapping, and Pipelines #44

@whisper67265

Description

@whisper67265

Problem

The service layer is the core of the add-or-update workflow. It needs foundational infrastructure: constants (supported file extensions, default branch names, Weblate API base URLs), helper functions (slug generation, path normalization, VCS workspace management), extension-to-format mapping (.qbk -> QuickBook, .adoc -> AsciiDoc, .po -> gettext), and the construction logic that assembles a processing pipeline. This is the first half of the services module, focused on setup and scanning.

Acceptance Criteria

  • src/boost_weblate/services.py defines constants: SUPPORTED_EXTENSIONS, DEFAULT_BRANCH, WORKSPACE_ROOT, format-class mapping
  • Helper functions: slugify_component(path) -> deterministic slug, normalize_repo_url(url) -> canonical form, ensure_workspace(project_slug) -> local clone path
  • Extension mapping: given a file path, return the correct Weblate format class (QuickBook, AsciiDoc, gettext, JSON, etc.)
  • scan_repository(workspace_path, extensions) walks the repo tree and returns a list of (relative_path, format_class) tuples
  • Workspace management: clone or pull the repo into a temp/workspace directory, handle branch checkout
  • All functions are importable and testable in isolation (no global state, no Django ORM calls in helpers)

Implementation Notes

Keep constants at module top level. The extension mapping should be a dict, not a chain of if/elif. scan_repository should use pathlib.Path.rglob() and filter against SUPPORTED_EXTENSIONS. Workspace management can use subprocess + git or dulwich — match whatever the existing codebase uses. This module will be extended in the next services item (project/component/translation flows), so design for composability.

References

  • Related files: src/boost_weblate/services.py, src/boost_weblate/formats/quickbook.py
  • Depends on: Week 20 QuickBook format and utility modules

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions