# -*- coding: utf-8 -*-
import re

from ppms.migration.packet import *
from ppms.migration import MaxVersionDependency, VersionType


class FindCodeThatUsesPLANTADE(DeprecatedPythonPacket):
    """Find code that imports from PLANTA DE

    Because of the change to the folder structure this code might not work anymore.
    Please replace the section with planta_de to point at the new code location.
    """
    wi_number = 16442
    category = PacketCategory.CATEGORY_HELPER
    done_after_success = False

    def get_dependencies(self):
        return (MaxVersionDependency(version='39.5.7', version_type=VersionType.CUSTOMIZING))

    def get_matching_objects(self, iterable_to_filter):
        matching_objects = list(filter(lambda x: re.search('from planta_de', x.source), iterable_to_filter)) + \
                           list(filter(lambda x: re.search('planta_de.', x.source), iterable_to_filter))

        return list(set(matching_objects))