Beispiel #1
0
    def test_unchanged(self):
        nbar = _build_ls8_nbar()
        new_nbar = ptype.rebase_paths(Path('/not-exist'), Path('/not-exist2'),
                                      nbar)

        # Should return a new object
        assert nbar is not new_nbar
        self.assert_same(nbar, new_nbar)
Beispiel #2
0
    def test_rewrite_paths(self):
        class TestObj(ptype.SimpleObject):
            def __init__(self, a, b=None, c=3):
                self.a = a
                self.b = b
                self.c = c

        o = ptype.rebase_paths(Path('/tmp/from'), Path('/tmp/to'),
                               TestObj(Path('/tmp/from/test.txt')))

        assert o == TestObj(Path('/tmp/to/test.txt'))
Beispiel #3
0
    def test_rewrite_mixed_paths(self):
        class TestObj(ptype.SimpleObject):
            def __init__(self, a, b=None, c=3):
                self.a = a
                self.b = b
                self.c = c

        o = ptype.rebase_paths(
            Path('/tmp/from'), Path('/tmp/to'),
            TestObj(Path('/tmp/other'), b=TestObj(Path('relative.txt')), c=2))
        self.assert_same(
            o, TestObj(Path('/tmp/other'),
                       b=TestObj(Path('relative.txt')),
                       c=2))
Beispiel #4
0
    def test_rewrite_paths_nested(self):
        class TestObj(ptype.SimpleObject):
            def __init__(self, a, b=None, c=3):
                self.a = a
                self.b = b
                self.c = c

        o = TestObj(Path('/tmp/from/test1.txt'),
                    b=TestObj(Path('/tmp/from/test2.txt')))
        o2 = ptype.rebase_paths(Path('/tmp/from'), Path('/tmp/to'), o)
        assert o is not o2
        self.assert_same(
            o2,
            TestObj(Path('/tmp/to/test1.txt'),
                    b=TestObj(Path('/tmp/to/test2.txt'))))
Beispiel #5
0
    def test_rewrite_within_lists(self):
        class TestObj(ptype.SimpleObject):
            def __init__(self, a, b=None, c=3):
                self.a = a
                self.b = b
                self.c = c

        o = [
            TestObj(Path('/tmp/from/test1.txt'),
                    b={'a': TestObj(Path('/tmp/from/test2.txt'))})
        ]
        o2 = ptype.rebase_paths(Path('/tmp/from'), Path('/tmp/to'), o)
        assert o is not o2
        self.assert_same(o2, [
            TestObj(Path('/tmp/to/test1.txt'),
                    b={'a': TestObj(Path('/tmp/to/test2.txt'))})
        ])
Beispiel #6
0
def package_dataset(dataset_driver,
                    dataset,
                    image_path,
                    target_path,
                    hard_link=False,
                    additional_files=None):
    """
    Package the given dataset folder.

    This includes copying the dataset into a folder, generating
    metadata and checksum files, as well as optionally generating
    a browse image.

    Validates, and *Modifies* the passed in dataset with extra metadata.

    :type hard_link: bool
    :type dataset_driver: eodatasets.drivers.DatasetDriver
    :type dataset: ptype.Dataset
    :type image_path: Path
    :type target_path: Path
    :param additional_files: Additional files to record in the package.
    :type additional_files: tuple[Path]

    :raises IncompletePackage: If not enough metadata can be extracted from the dataset.
    :return: The generated GA Dataset ID (ga_label)
    :rtype: str
    """
    if additional_files is None:
        additional_files = []
    _check_additional_files_exist(additional_files)

    dataset_driver.fill_metadata(dataset,
                                 image_path,
                                 additional_files=additional_files)

    checksums = verify.PackageChecksum()

    target_path = target_path.absolute()
    image_path = image_path.absolute()

    target_metadata_path = documents.find_metadata_path(target_path)
    if target_metadata_path is not None and target_metadata_path.exists():
        _LOG.info('Already packaged? Skipping %s', target_path)
        return None

    _LOG.debug('Packaging %r -> %r', image_path, target_path)
    package_directory = target_path.joinpath('product')

    file_paths = []

    def save_target_checksums_and_paths(source_path, target_paths):
        _LOG.debug('%r -> %r', source_path, target_paths)
        checksums.add_files(target_paths)
        file_paths.extend(target_paths)

    prepare_target_imagery(image_path,
                           destination_directory=package_directory,
                           include_path=dataset_driver.include_file,
                           translate_path=partial(
                               dataset_driver.translate_path, dataset),
                           after_file_copy=save_target_checksums_and_paths,
                           hard_link=hard_link)

    write_additional_files(additional_files, checksums, target_path)

    validate_metadata(dataset)
    dataset = expand_driver_metadata(dataset_driver, dataset, file_paths)

    #: :type: ptype.DatasetMetadata
    dataset = ptype.rebase_paths(image_path, package_directory, dataset)

    create_dataset_browse_images(dataset_driver,
                                 dataset,
                                 target_path,
                                 after_file_creation=checksums.add_file)

    target_checksums_path = target_path / GA_CHECKSUMS_FILE_NAME
    dataset.checksum_path = target_checksums_path

    target_metadata_path = serialise.write_dataset_metadata(
        target_path, dataset)

    checksums.add_file(target_metadata_path)
    checksums.write(target_checksums_path)

    return dataset.ga_label