Beispiel #1
0
def _extract_and_check_maven_artifacts_to_beetmove(artifacts, zip_max_file_size_in_mb, mapping_manifest=None, artifact_map=None):
    expected_files = maven_utils.get_maven_expected_files_per_archive_per_task_id(
        artifacts, mapping_manifest=mapping_manifest, artifact_map=artifact_map
    )

    extracted_paths_per_archive = zip.check_and_extract_zip_archives(
        artifacts, expected_files, zip_max_file_size_in_mb, mapping_manifest
    )

    number_of_extracted_archives = len(extracted_paths_per_archive)
    if number_of_extracted_archives == 0:
        raise ScriptWorkerTaskException('No archive extracted')
    elif number_of_extracted_archives > 1:
        raise NotImplementedError('More than 1 archive extracted. Only 1 is supported at once')
    extracted_paths_per_relative_path = list(extracted_paths_per_archive.values())[0]

    if artifact_map:
        return {
            'en-US': extracted_paths_per_relative_path
        }
    else:
        return {
            'en-US': {
                os.path.basename(path_in_archive): full_path
                for path_in_archive, full_path in extracted_paths_per_relative_path.items()
            }
        }
Beispiel #2
0
def test_check_and_extract_zip_archives():
    first_task_id_archive1_files_and_content = {
        'some_file1': 'some content 1',
        'some/subfolder/file1': 'some other content 1',
    }
    first_task_id_archive2_files_and_content = {
        'some_file2': 'some content 2',
        'some/subfolder/file2': 'some other content 2',
    }
    third_task_id_archive1_files_and_content = {
        'some_file3': 'some content 3',
        'some/subfolder/file3': 'some other content 3',
    }

    with tempfile.TemporaryDirectory() as d:
        first_task_id_archive1_path = _create_zip(
            d,
            first_task_id_archive1_files_and_content,
            archive_name='firstTaskId-archive1.zip')
        first_task_id_archive2_path = _create_zip(
            d,
            first_task_id_archive2_files_and_content,
            archive_name='firstTaskId-archive2.zip')
        third_task_id_archive1_path = _create_zip(
            d,
            third_task_id_archive1_files_and_content,
            archive_name='thirdTaskId-archive1.zip')

        artifacts_per_task_id = {
            'firstTaskId': [{
                'paths': ['/a/non/archive', '/another/non/archive'],
                'zip_extract': False,
            }, {
                'paths':
                [first_task_id_archive1_path, first_task_id_archive2_path],
                'zip_extract':
                True,
            }],
            'secondTaskId': [{
                'paths': ['/just/another/regular/file'],
                'zip_extract': False,
            }],
            'thirdTaskId': [{
                'paths': [third_task_id_archive1_path],
                'zip_extract': True,
            }],
        }

        expected_files_per_archive_per_task_id = {
            'firstTaskId': {
                first_task_id_archive1_path:
                list(first_task_id_archive1_files_and_content.keys()),
                first_task_id_archive2_path:
                list(first_task_id_archive2_files_and_content.keys()),
            },
            'thirdTaskId': {
                third_task_id_archive1_path:
                list(third_task_id_archive1_files_and_content.keys()),
            },
        }

        files_once_extracted = check_and_extract_zip_archives(
            artifacts_per_task_id,
            expected_files_per_archive_per_task_id,
            zip_max_size_in_mb=100)

        assert files_once_extracted == {
            os.path.join(d, 'firstTaskId-archive1.zip'): {
                'some_file1':
                os.path.join(d, 'firstTaskId-archive1.zip.out', 'some_file1'),
                'some/subfolder/file1':
                os.path.join(d, 'firstTaskId-archive1.zip.out', 'some',
                             'subfolder', 'file1'),
            },
            os.path.join(d, 'firstTaskId-archive2.zip'): {
                'some_file2':
                os.path.join(d, 'firstTaskId-archive2.zip.out', 'some_file2'),
                'some/subfolder/file2':
                os.path.join(d, 'firstTaskId-archive2.zip.out', 'some',
                             'subfolder', 'file2'),
            },
            os.path.join(d, 'thirdTaskId-archive1.zip'): {
                'some_file3':
                os.path.join(d, 'thirdTaskId-archive1.zip.out', 'some_file3'),
                'some/subfolder/file3':
                os.path.join(d, 'thirdTaskId-archive1.zip.out', 'some',
                             'subfolder', 'file3'),
            },
        }