src\wily\archivers\filesystem.py
-- -- --- --- --- --- --- --- ------- ------- ------- | """
-- -- --- --- --- --- --- --- ------- ------- ------- | Filesystem Archiver.
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- -- --- --- --- --- --- --- ------- ------- ------- | Implementation of the archiver API for a standard directory (no revisions)
-- -- --- --- --- --- --- --- ------- ------- ------- | """
-- -- --- --- --- --- --- --- ------- ------- ------- | import hashlib
-- -- --- --- --- --- --- --- ------- ------- ------- | import logging
-- -- --- --- --- --- --- --- ------- ------- ------- | import os.path
-- -- --- --- --- --- --- --- ------- ------- ------- | from typing import Any, Dict, List
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- -- --- --- --- --- --- --- ------- ------- ------- | from wily.archivers import BaseArchiver, Revision
-- -- --- --- --- --- --- --- ------- ------- ------- | from wily.config.types import WilyConfig
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- -- --- --- --- --- --- --- ------- ------- ------- | logger = logging.getLogger(__name__)
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- -- --- --- --- --- --- --- ------- ------- ------- |
02 -- --- --- --- --- --- --- ------- ------- ------- | class FilesystemArchiver(BaseArchiver):
02 -- --- --- --- --- --- --- ------- ------- ------- | """Basic implementation of the base archiver."""
02 -- --- --- --- --- --- --- ------- ------- ------- |
02 -- --- --- --- --- --- --- ------- ------- ------- | name = "filesystem"
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 | """
02 01 000 000 000 000 000 000 0000.00 0000.00 0000.00 | Instantiate a new Filesystem Archiver.
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 config: The wily configuration
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 | self.config = config
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 | :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 | mtime = os.path.getmtime(path)
02 01 000 000 000 000 000 000 0000.00 0000.00 0000.00 | key = hashlib.sha1(str(mtime).encode()).hexdigest()[:7]
02 01 000 000 000 000 000 000 0000.00 0000.00 0000.00 | return [
02 01 000 000 000 000 000 000 0000.00 0000.00 0000.00 | Revision(
02 01 000 000 000 000 000 000 0000.00 0000.00 0000.00 | key=key,
02 01 000 000 000 000 000 000 0000.00 0000.00 0000.00 | author_name="Local User", # Don't want to leak local data
02 01 000 000 000 000 000 000 0000.00 0000.00 0000.00 | author_email="-", # as above
02 01 000 000 000 000 000 000 0000.00 0000.00 0000.00 | date=int(mtime),
02 01 000 000 000 000 000 000 0000.00 0000.00 0000.00 | message="None",
02 01 000 000 000 000 000 000 0000.00 0000.00 0000.00 | tracked_files=[],
02 01 000 000 000 000 000 000 0000.00 0000.00 0000.00 | tracked_dirs=[],
02 01 000 000 000 000 000 000 0000.00 0000.00 0000.00 | added_files=[],
02 01 000 000 000 000 000 000 0000.00 0000.00 0000.00 | modified_files=[],
02 01 000 000 000 000 000 000 0000.00 0000.00 0000.00 | deleted_files=[],
02 -- 000 000 000 000 000 000 0000.00 0000.00 0000.00 | )
02 -- 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 | # effectively noop since there are no revision
02 01 000 000 000 000 000 000 0000.00 0000.00 0000.00 | pass