From 74ebed80c65ebeaf7cd74a338e47fd3c5dd3ff6e Mon Sep 17 00:00:00 2001 From: Daniel K Lyons <dlyons@nrao.edu> Date: Thu, 8 Apr 2021 14:18:00 -0600 Subject: [PATCH] Document a few things, break out the subdirectory decorator even though it isn't used currently --- .../executables/delivery/delivery/deliverer.py | 9 --------- .../delivery/delivery/destinations/checksum.py | 5 +++++ .../delivery/destinations/subdirectory.py | 16 ++++++++++++++++ .../delivery/delivery/destinations/tar.py | 8 ++++++++ 4 files changed, 29 insertions(+), 9 deletions(-) create mode 100644 apps/cli/executables/delivery/delivery/destinations/subdirectory.py diff --git a/apps/cli/executables/delivery/delivery/deliverer.py b/apps/cli/executables/delivery/delivery/deliverer.py index 36e6ca276..778f0615e 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 f680ae67a..15873c5fe 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 000000000..00edc26a1 --- /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 2e0b12690..141edd7a8 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 -- GitLab