# -*- coding: utf-8 -*-

from ppms.migration.packet import *

class FixRestartServerFunctionality(MigratePythonPacket):
    '''Update the restart server functionality to work in Venus'''
    version = 1
    done_after_success = True
    run_on_startup = True
    category = PacketCategory.CATEGORY_MANDATORY
    wi_number = 10654

    BEFORE_HASH = 'c690a315fb4c21d280e8bd09df3218cf'
    AFTER_HASH = 'c27910af41425b6177f35685e57b92e3'
   
    NEW_MACRO = """# Should the server be restarted?
message = ppms.ui_message_id("0763")
msg = ppms.msg_pop()
if msg.get_reply() != 1:
    pass
else:
    ppms.reload_server()        
    ppms.ui_message_id("0764")"""

    def fix(self, runner):
        fix = lambda code: self.NEW_MACRO

        if self.migrate_python(self.BEFORE_HASH, self.AFTER_HASH, self.CU_TYPE_MODULE,
                               '009BAZ', fix):
            return self.success()

        return self.fail('See above')