wily\archivers\filesystem.py
-- -- --- --- --- --- --- --- ------- ------- ------- | """
-- -- --- --- --- --- --- --- ------- ------- ------- | Filesystem Archiver.
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- -- --- --- --- --- --- --- ------- ------- ------- | Implementation of the archiver API for a standard directory (no revisions)
-- -- --- --- --- --- --- --- ------- ------- ------- | """
-- -- --- --- --- --- --- --- ------- ------- ------- | import logging
-- -- --- --- --- --- --- --- ------- ------- ------- | import os.path
-- -- --- --- --- --- --- --- ------- ------- ------- | import hashlib
-- -- --- --- --- --- --- --- ------- ------- ------- | from wily.archivers import BaseArchiver, Revision
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- -- --- --- --- --- --- --- ------- ------- ------- | 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):
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 | :type config: :class:`wily.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 | self.config = config
02 -- --- --- --- --- --- --- ------- ------- ------- |
02 01 000 000 000 000 000 000 0000.00 0000.00 0000.00 | def revisions(self, path, max_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 | 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 | :type path: ``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 | :param max_revisions: the maximum number of revisions.
02 01 000 000 000 000 000 000 0000.00 0000.00 0000.00 | :type max_revisions: ``int``
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 | :rtype: ``list`` 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 | 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 | 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, 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 | 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 | :type revision: :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 | :param options: Any additional options.
02 01 000 000 000 000 000 000 0000.00 0000.00 0000.00 | :type options: ``dict``
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