Skip to content
Snippets Groups Projects
Commit 74ebed80 authored by Daniel Lyons's avatar Daniel Lyons
Browse files

Document a few things, break out the subdirectory decorator even though it isn't used currently

parent 298cc45d
No related branches found
No related tags found
No related merge requests found
Pipeline #1197 passed
......@@ -11,15 +11,6 @@ from .destinations.sharedweb import SharedWebDestination
from .destinations.fetchfile import FetchFileGenerator
# class SubdirectoryDecorator(DestinationDecorator):
# def __init__(self, underlying: Destination, subdirectory: str):
# super().__init__(underlying)
# self.subdirectory = subdirectory
#
# def add_file(self, relative_path: str, file: pathlib.Path):
# self.underlying.add_file(self.subdirectory + "/" + relative_path, file)
class DestinationBuilder:
"""
To facilitate building a stack of destination and its decorators.
......
......@@ -32,6 +32,11 @@ class ChecksumDecorator(DestinationDecorator):
@staticmethod
def hash_file(file: pathlib.Path):
"""
Hash the supplied file
:param file: file to hash
:return: string in SHA1SUMS format (hexdigest)
"""
# You would expect performance to be worse than calling a C program here, but in my own testing I found
# that the ensuing block is somewhat *faster* than calling "shasum" directly. I was able to hash a 1 GB
# random file in 1.2 seconds with the following code, versus 1.8 seconds with shasum. This is across about 10
......
import pathlib
from .interfaces import DestinationDecorator, Destination
class SubdirectoryDecorator(DestinationDecorator):
"""
A wrapper for making it easy to descend to subdirectories during delivery.
"""
def __init__(self, underlying: Destination, subdirectory: str):
super().__init__(underlying)
self.subdirectory = subdirectory
def add_file(self, file: pathlib.Path, relative_path: str):
self.underlying.add_file(file, self.subdirectory + "/" + relative_path)
......@@ -25,6 +25,14 @@ class TarArchiver(DestinationDecorator):
self.archive.add(file, relative_path)
def ensure_archive_created(self, relative_path: str):
"""
This method guarantees that we have an open archive for writing.
If we do have an archive open, nothing happens; if we do not,
the archive is opened with a name derived from the supplied relative_path.
:param relative_path: path to the first file going into the archive
"""
# if we don't have the archive property yet, we must create the archive now
if not self.archive:
# the filename we generate will be the path to the first thing we're delivering with ".tar" appended
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment