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

from PyQt4.QtCore import SIGNAL, QThread
import os
import globalfunc
from logrecord import LogRecord

class RestartNetworkThread(QThread):
    def __init__(self, parent=None):
        super(RestartNetworkThread,self).__init__(parent)

        
    def run(self):
        LogRecord.instance().logger.info(u"开始启动网络")
        self.emit(SIGNAL("restartNetwork"), "Start")
        ok = -1

        #根据系统类型执行重启网络服务命令
        sysType = globalfunc.getLinuxOperationSystemType()
        LogRecord.instance().logger.info(u"系统的操作类型：%s" % sysType)
        if sysType and sysType == "Ubuntu 12.04":
            ok = os.system("/etc/init.d/networking restart")
        elif sysType and sysType == "Ubuntu 13.04":
            ok = os.system("/etc/init.d/networking restart")
        elif sysType and sysType == "Ubuntu 14.04":
            ok = os.system("ifdown eth0 && ifup eth0")
        elif sysType and sysType == "CentOS 6.5":
            ok = os.system("service network restart")
        elif sysType and sysType == "CentOS 7.0":
            ok = os.system("systemctl restart network.service")
        else:
            ok = os.system("service network restart")


        if ok != 0:
            self.emit(SIGNAL("restartNetwork"), "Failed")
        else:
            self.emit(SIGNAL("restartNetwork"), "Success")
        
        