Skip to content
Snippets Groups Projects
Commit e44266a3 authored by Reid Givens's avatar Reid Givens Committed by Andrew Kapuscinski
Browse files

localdelivery of raw exec block with passing test

parent ee9dfb2d
No related branches found
Tags 2.8.0
1 merge request!47local delivery of raw exec block with passing test
Pipeline #391 passed
......@@ -79,7 +79,7 @@ class DeliveryContext:
def create_finder(self) -> ProductFinder:
if self.rawdata:
return HeuristicProductFinder(self.source / "rawdata")
return HeuristicProductFinder(self.source)
else:
raise NotImplementedError
......
......@@ -111,7 +111,7 @@ class LocalDestination(Destination):
:param relative_path: Relative path to new directory location in destination
"""
try:
shutil.copytree(directory, relative_path, dirs_exist_ok=True)
shutil.copytree(directory, str(self.path) + "/" + relative_path, dirs_exist_ok=True)
except shutil.Error as err:
raise err
......
......@@ -32,13 +32,11 @@ class Delivery:
"""
# make the destination
destination = context.create_destination()
# find the products
finder = context.create_finder()
# loop over the products and deliver them
for product in finder.find_products():
# ProductDeliverer(context)
product.deliver_to(destination)
# the last thing we should do is return the URL to the delivered stuff.
......@@ -53,5 +51,5 @@ class Delivery:
def main(args=None):
"""CLI entry point"""
context = DeliveryContext.parse_commandline(args)
print(context)
#print(context)
Delivery().deliver(context)
......@@ -4,6 +4,7 @@
#
# -------------------------------------------------------------------------
import abc
import os
import pathlib
from typing import Iterator
......@@ -36,4 +37,5 @@ class HeuristicProductFinder(ProductFinder):
:return: List of products
"""
for subdir in self.path.glob("*"):
yield ExecutionBlock(subdir)
if os.path.isdir(subdir):
yield ExecutionBlock(subdir)
......@@ -46,8 +46,9 @@ class ExecutionBlock(SpooledProduct):
"""
def deliver_to(self, destination: Destination):
eb_name = self.path.absolute().name
# let's use our directory name as the relative path
destination.add_directory(self.path, self.path.absolute().name)
destination.add_directory((self.path / "rawdata" / eb_name), eb_name)
# Future types of product that might be needed:
......
......@@ -7,24 +7,26 @@ from delivery.deliverer import LocalDestination
def test_local_delivery_add_file(tmpdir):
"""Ensure that local delivery does something"""
file_name = "test.txt"
temp_file = tmpdir.mkdir("prior").join(file_name)
temp_file.write_text("content", encoding=None)
dest_dir = tmpdir.mkdir("after")
temp_file = tmpdir.mkdir("prior").join(file_name) # place a file into the source
temp_file.write_text("content", encoding=None) # write something into that file
dest_dir = tmpdir.mkdir("after") # create a destination
local_dest = LocalDestination(None, dest_dir)
local_dest.add_file(temp_file, str(dest_dir / file_name))
# see if the source file eneded up in the destination
assert path.exists(dest_dir / file_name)
# see if the content of the file is intact
assert (dest_dir / file_name).read_text(encoding=None) == "content"
def test_local_delivery_add_directory(tmpdir):
"""Ensure that local delivery does something"""
source_dir = tmpdir.mkdir("prior")
temp_file = source_dir.join("test.txt")
temp_file.write_text("content", encoding=None)
temp_file2 = source_dir.join("test2.txt")
temp_file2.write_text("more content", encoding=None)
dest_dir = tmpdir.mkdir("after")
local_dest = LocalDestination(None, str(dest_dir))
local_dest.add_directory(source_dir, str(dest_dir))
compare_dirs = filecmp.dircmp(source_dir, dest_dir)
source_dir = tmpdir.mkdir("prior") # create a source
temp_file = source_dir.join("test.txt") # add a file to the source dir
temp_file.write_text("content", encoding=None) # add some content to the file
temp_file2 = source_dir.join("test2.txt") # make another file in source
temp_file2.write_text("more content", encoding=None) # add some content to the second file
local_dest = LocalDestination(None, str(tmpdir))
local_dest.add_directory(source_dir, "after") # destination is defined here
compare_dirs = filecmp.dircmp(source_dir, tmpdir / "after")
# see if the destination got all the files from source
assert len(compare_dirs.left_only) == 0 and len(compare_dirs.right_only) == 0 and \
len(compare_dirs.funny_files) == 0
......@@ -11,9 +11,10 @@ def test_basic_rawdata_no_tar(tmpdir_factory):
"""
temp_directory = str(tmpdir_factory.mktemp('test_basic_rawdata_no_tar'))
test_data_path = '../../../../shared/workspaces/test/test_data/spool/724126739/'
eb_name = "17A-109.sb33151331.eb33786546.57892.65940042824"
delivery.delivery.main(["-r", "-l", temp_directory, test_data_path])
compare_dirs = filecmp.dircmp(temp_directory, test_data_path)
print(compare_dirs.report())
compare_dirs = filecmp.dircmp(temp_directory + "/" + eb_name, \
(test_data_path + eb_name + "/rawdata/" + eb_name))
assert len(compare_dirs.left_only) == 0 and len(compare_dirs.right_only) == 0 and \
len(compare_dirs.funny_files) == 0
......
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