-- -- --- --- --- --- --- --- ------- ------- ------- |
"""
-- -- --- --- --- --- --- --- ------- ------- ------- |
Archivers module.
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- -- --- --- --- --- --- --- ------- ------- ------- |
Specifies a standard interface for finding revisions (versions) of a path and switching to them.
-- -- --- --- --- --- --- --- ------- ------- ------- |
"""
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- -- --- --- --- --- --- --- ------- ------- ------- |
from dataclasses import dataclass
-- -- --- --- --- --- --- --- ------- ------- ------- |
from typing import Any, Dict, Generic, List, Optional, Type, TypeVar
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- -- --- --- --- --- --- --- ------- ------- ------- |
from wily.config.types import WilyConfig
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- -- --- --- --- --- --- --- ------- ------- ------- |
@dataclass
01 -- --- --- --- --- --- --- ------- ------- ------- |
class Revision:
01 -- --- --- --- --- --- --- ------- ------- ------- |
"""Represents a revision in the archiver."""
01 -- --- --- --- --- --- --- ------- ------- ------- |
01 -- --- --- --- --- --- --- ------- ------- ------- |
key: str
01 -- --- --- --- --- --- --- ------- ------- ------- |
author_name: Optional[str]
01 -- --- --- --- --- --- --- ------- ------- ------- |
author_email: Optional[str]
01 -- --- --- --- --- --- --- ------- ------- ------- |
date: int
01 -- --- --- --- --- --- --- ------- ------- ------- |
message: str
01 -- --- --- --- --- --- --- ------- ------- ------- |
tracked_files: List[str]
01 -- --- --- --- --- --- --- ------- ------- ------- |
tracked_dirs: List[str]
01 -- --- --- --- --- --- --- ------- ------- ------- |
added_files: List[str]
01 -- --- --- --- --- --- --- ------- ------- ------- |
modified_files: List[str]
01 -- --- --- --- --- --- --- ------- ------- ------- |
deleted_files: List[str]
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- -- --- --- --- --- --- --- ------- ------- ------- |
02 -- --- --- --- --- --- --- ------- ------- ------- |
class BaseArchiver:
02 -- --- --- --- --- --- --- ------- ------- ------- |
"""Abstract Archiver Class."""
02 -- --- --- --- --- --- --- ------- ------- ------- |
02 -- --- --- --- --- --- --- ------- ------- ------- |
name: str
02 -- --- --- --- --- --- --- ------- ------- ------- |
02 01 000 000 000 000 000 000 0000.00 0000.00 0000.00 |
def __init__(self, config: "WilyConfig"):
02 01 000 000 000 000 000 000 0000.00 0000.00 0000.00 |
"""Initialise the archiver."""
02 01 000 000 000 000 000 000 0000.00 0000.00 0000.00 |
...
02 -- --- --- --- --- --- --- ------- ------- ------- |
02 01 000 000 000 000 000 000 0000.00 0000.00 0000.00 |
def revisions(self, path: str, max_revisions: int) -> List[Revision]:
02 01 000 000 000 000 000 000 0000.00 0000.00 0000.00 |
"""
02 01 000 000 000 000 000 000 0000.00 0000.00 0000.00 |
Get the list of revisions.
02 01 000 000 000 000 000 000 0000.00 0000.00 0000.00 |
02 01 000 000 000 000 000 000 0000.00 0000.00 0000.00 |
:param path: the path to target.
02 01 000 000 000 000 000 000 0000.00 0000.00 0000.00 |
:param max_revisions: the maximum number of revisions.
02 01 000 000 000 000 000 000 0000.00 0000.00 0000.00 |
02 01 000 000 000 000 000 000 0000.00 0000.00 0000.00 |
:return: A list of revisions.
02 01 000 000 000 000 000 000 0000.00 0000.00 0000.00 |
"""
02 01 000 000 000 000 000 000 0000.00 0000.00 0000.00 |
...
02 -- --- --- --- --- --- --- ------- ------- ------- |
02 01 000 000 000 000 000 000 0000.00 0000.00 0000.00 |
def checkout(self, revision: Revision, options: Dict[Any, Any]) -> None:
02 01 000 000 000 000 000 000 0000.00 0000.00 0000.00 |
"""
02 01 000 000 000 000 000 000 0000.00 0000.00 0000.00 |
Checkout a specific revision.
02 01 000 000 000 000 000 000 0000.00 0000.00 0000.00 |
02 01 000 000 000 000 000 000 0000.00 0000.00 0000.00 |
:param revision: The revision identifier.
02 01 000 000 000 000 000 000 0000.00 0000.00 0000.00 |
:param options: Any additional options.
02 01 000 000 000 000 000 000 0000.00 0000.00 0000.00 |
"""
02 01 000 000 000 000 000 000 0000.00 0000.00 0000.00 |
...
02 -- --- --- --- --- --- --- ------- ------- ------- |
02 01 000 000 000 000 000 000 0000.00 0000.00 0000.00 |
def finish(self):
02 01 000 000 000 000 000 000 0000.00 0000.00 0000.00 |
"""Clean up any state if processing completed/failed."""
02 01 000 000 000 000 000 000 0000.00 0000.00 0000.00 |
pass
02 -- --- --- --- --- --- --- ------- ------- ------- |
02 01 000 000 000 000 000 000 0000.00 0000.00 0000.00 |
def find(self, search: str) -> Revision:
02 01 000 000 000 000 000 000 0000.00 0000.00 0000.00 |
"""
02 01 000 000 000 000 000 000 0000.00 0000.00 0000.00 |
Search a string and return a single revision.
02 01 000 000 000 000 000 000 0000.00 0000.00 0000.00 |
02 01 000 000 000 000 000 000 0000.00 0000.00 0000.00 |
:param search: The search term.
02 01 000 000 000 000 000 000 0000.00 0000.00 0000.00 |
:type search: ``str``
02 01 000 000 000 000 000 000 0000.00 0000.00 0000.00 |
02 01 000 000 000 000 000 000 0000.00 0000.00 0000.00 |
:return: An instance of revision.
02 01 000 000 000 000 000 000 0000.00 0000.00 0000.00 |
:rtype: Instance of :class:`Revision`
02 01 000 000 000 000 000 000 0000.00 0000.00 0000.00 |
"""
02 01 000 000 000 000 000 000 0000.00 0000.00 0000.00 |
...
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- -- --- --- --- --- --- --- ------- ------- ------- |
from wily.archivers.filesystem import FilesystemArchiver
-- -- --- --- --- --- --- --- ------- ------- ------- |
from wily.archivers.git import GitArchiver
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- -- --- --- --- --- --- --- ------- ------- ------- |
"""Type for an Archiver"""
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- -- --- --- --- --- --- --- ------- ------- ------- |
T = TypeVar("T")
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- -- --- --- --- --- --- --- ------- ------- ------- |
02 -- --- --- --- --- --- --- ------- ------- ------- |
class Archiver(Generic[T]):
02 -- --- --- --- --- --- --- ------- ------- ------- |
"""Holder for archivers."""
02 -- --- --- --- --- --- --- ------- ------- ------- |
02 -- --- --- --- --- --- --- ------- ------- ------- |
name: str
02 -- --- --- --- --- --- --- ------- ------- ------- |
archiver_cls: Type[T]
02 -- --- --- --- --- --- --- ------- ------- ------- |
description: str
02 -- --- --- --- --- --- --- ------- ------- ------- |
02 01 000 000 000 000 000 000 0000.00 0000.00 0000.00 |
def __init__(self, name: str, archiver_cls: Type[T], description: str):
02 01 000 000 000 000 000 000 0000.00 0000.00 0000.00 |
"""Initialise the archiver."""
02 01 000 000 000 000 000 000 0000.00 0000.00 0000.00 |
self.name = name
02 01 000 000 000 000 000 000 0000.00 0000.00 0000.00 |
self.archiver_cls = archiver_cls
02 01 000 000 000 000 000 000 0000.00 0000.00 0000.00 |
self.description = description
02 -- --- --- --- --- --- --- ------- ------- ------- |
02 01 000 000 000 000 000 000 0000.00 0000.00 0000.00 |
def __str__(self):
02 01 000 000 000 000 000 000 0000.00 0000.00 0000.00 |
"""Return the name of the archiver."""
02 01 000 000 000 000 000 000 0000.00 0000.00 0000.00 |
return self.name
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- -- --- --- --- --- --- --- ------- ------- ------- |
"""Git Archiver defined in `wily.archivers.git`"""
-- -- --- --- --- --- --- --- ------- ------- ------- |
ARCHIVER_GIT = Archiver(
-- -- --- --- --- --- --- --- ------- ------- ------- |
name="git", archiver_cls=GitArchiver, description="Git archiver"
-- -- --- --- --- --- --- --- ------- ------- ------- |
)
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- -- --- --- --- --- --- --- ------- ------- ------- |
"""Filesystem archiver"""
-- -- --- --- --- --- --- --- ------- ------- ------- |
ARCHIVER_FILESYSTEM = Archiver(
-- -- --- --- --- --- --- --- ------- ------- ------- |
name="filesystem",
-- -- --- --- --- --- --- --- ------- ------- ------- |
archiver_cls=FilesystemArchiver,
-- -- --- --- --- --- --- --- ------- ------- ------- |
description="Filesystem archiver",
-- -- --- --- --- --- --- --- ------- ------- ------- |
)
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- -- --- --- --- --- --- --- ------- ------- ------- |
"""Set of all available archivers"""
-- -- --- --- --- --- --- --- ------- ------- ------- |
ALL_ARCHIVERS = {a.name: a for a in [ARCHIVER_GIT, ARCHIVER_FILESYSTEM]}
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- 02 001 002 001 002 003 003 0004.75 0002.38 0000.50 |
def resolve_archiver(name: str) -> Archiver:
-- 02 001 002 001 002 003 003 0004.75 0002.38 0000.50 |
"""
-- 02 001 002 001 002 003 003 0004.75 0002.38 0000.50 |
Get the :class:`wily.archivers.Archiver` for a given name.
-- 02 001 002 001 002 003 003 0004.75 0002.38 0000.50 |
-- 02 001 002 001 002 003 003 0004.75 0002.38 0000.50 |
:param name: The name of the archiver
-- 02 001 002 001 002 003 003 0004.75 0002.38 0000.50 |
:type name: ``str``
-- 02 001 002 001 002 003 003 0004.75 0002.38 0000.50 |
:return: The archiver type
-- 02 001 002 001 002 003 003 0004.75 0002.38 0000.50 |
"""
-- 02 001 002 001 002 003 003 0004.75 0002.38 0000.50 |
if name not in ALL_ARCHIVERS:
-- 02 001 002 001 002 003 003 0004.75 0002.38 0000.50 |
raise ValueError(f"Resolver {name} not recognised.")
-- 02 001 002 001 002 003 003 0004.75 0002.38 0000.50 |
else:
-- 02 001 002 001 002 003 003 0004.75 0002.38 0000.50 |
return ALL_ARCHIVERS[name.lower()]