Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Zip with title cannot be parsed #2683

Merged
merged 1 commit into from
Mar 26, 2025
Merged

Conversation

shaohuzhang1
Copy link
Contributor

fix: Zip with title cannot be parsed

Copy link

f2c-ci-robot bot commented Mar 26, 2025

Adding the "do-not-merge/release-note-label-needed" label because no release-note block was detected, please follow our release note process to remove it.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

Copy link

f2c-ci-robot bot commented Mar 26, 2025

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:

The full list of commands accepted by this bot can be found here.

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@@ -75,6 +76,7 @@ def get_image_list(result_list: list, zip_files: List[str]):
if search:
new_image_id = str(uuid.uuid1())
source_image_path = search.group().replace('(', '').replace(')', '')
source_image_path = source_image_path.strip().split(" ")[0]
image_path = urljoin(result.get('name'), '.' + source_image_path if source_image_path.startswith(
'/') else source_image_path)
if not zip_files.__contains__(image_path):
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The provided code snippet has a few inconsistencies:

  1. The FileBufferHandle class should be defined properly with parameters such as path, size, etc.

  2. There seems to be an indentation issue between line 74 and 75 due to missing tab character (\t) after source_image_path.

  3. In the get_image_list method:

    • The return type of functions is recommended to be explicitly specified using type hints.
    • Consider adding docstrings to methods for better readability and maintainability.
    • Remove unnecessary whitespace around operators like = when checking conditions (e.g., <).

Here's the optimized version with these corrections:

from dataset.models import Image
from django.utils.translation import gettext_lazy as _

class FileBufferHandle:
    buffer = None

def get_image_list(result_list: list, zip_files: List[str]) -> list:
    """Process image lists based on the result list and zip files."""
    filtered_images = []
    
    # Process each result item in result_list
    for result in result_list:
        if 'search' in result and isinstance(result['search'], re.Match):
            new_image_id = str(uuid.uuid1())
            
            # Extract and clean up source image path
            search_group = result['search'].group()
            source_image_path = (
                search_group.replace('(', '').replace(')', '') 
                .strip().split(" ")[0]
            )
            image_path = urljoin(result.get('name'), '.' + source_image_path) if \
                        source_image_path.startswith('/') else source_image_path
            
            # Check and add image if it's not already in zip_files
            if image_path not in zip_files:
                filtered_images.append(image_path)
                
    return filtered_images

This version includes improvements to clarity and correctness while maintaining performance and efficiency.

@shaohuzhang1 shaohuzhang1 merged commit 55cdd0a into main Mar 26, 2025
4 of 5 checks passed
@shaohuzhang1 shaohuzhang1 deleted the pr@main@fix_import_zip branch March 26, 2025 02:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant