# -*- coding: utf-8 -*-
import contextlib
import shutil

from ppms import ppms
from ppms.migration import SQLPacket, PacketCategory


class DeleteTargetFolder(SQLPacket):
    """Delete the target folder"""
    done_after_success = True
    run_on_startup = True
    category = PacketCategory.CATEGORY_MANDATORY
    wi_number = 19711
        
    def fix(self, packet_runner):
        with contextlib.suppress(OSError):
            shutil.rmtree('target')

        self.log('Removed target folder')

        return self.success()

# Delete the target folder so the POJOs are forced to recompile
# And the MigrateCostsAndBudget does not fail due to outdated POJOs
