diff --git a/apps/cli/executables/delivery/delivery/deliverer.py b/apps/cli/executables/delivery/delivery/deliverer.py index 36e6ca2765720fbd144cf5901b6c401519bbc27b..778f0615ea164fc3de7101d8358822f2bc5ca8ec 100644 --- a/apps/cli/executables/delivery/delivery/deliverer.py +++ b/apps/cli/executables/delivery/delivery/deliverer.py @@ -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. diff --git a/apps/cli/executables/delivery/delivery/destinations/checksum.py b/apps/cli/executables/delivery/delivery/destinations/checksum.py index f680ae67a11a273e0e22a6498dc8172fe9079260..15873c5fe664a640ba9a948bb6d87e3a0d41b6ea 100644 --- a/apps/cli/executables/delivery/delivery/destinations/checksum.py +++ b/apps/cli/executables/delivery/delivery/destinations/checksum.py @@ -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 diff --git a/apps/cli/executables/delivery/delivery/destinations/subdirectory.py b/apps/cli/executables/delivery/delivery/destinations/subdirectory.py new file mode 100644 index 0000000000000000000000000000000000000000..00edc26a1857c5cd06e91a20d90e2a5cf61dfffa --- /dev/null +++ b/apps/cli/executables/delivery/delivery/destinations/subdirectory.py @@ -0,0 +1,16 @@ +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) diff --git a/apps/cli/executables/delivery/delivery/destinations/tar.py b/apps/cli/executables/delivery/delivery/destinations/tar.py index 2e0b126905f660a602a7e2a4080aa2b1e446bfcf..141edd7a8f10ff03164d2ad155790522cf1216ee 100644 --- a/apps/cli/executables/delivery/delivery/destinations/tar.py +++ b/apps/cli/executables/delivery/delivery/destinations/tar.py @@ -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