Example #1
0
    def save(self, **new_data):
        instance = self.instance
        instance.save()

        # Saving positions
        position_list = [strip(position_id) for position_id in new_data['positions'].split(',')]
        models.ResumePositionR.objects.filter(resume=instance).delete()
        for position_id in position_list:
            if position_id != '':
                position_obj = models.Position.objects.get(id=position_id)
                resume_position_r = models.ResumePositionR(resume=instance, position=position_obj)
                resume_position_r.save()
Example #2
0
    def save(self, **new_data):
        instance = self.instance
        instance.save()

        # Saving positions
        position_list = [strip(position_id) for position_id in new_data['positions'].split(',')]
        models.ResumePositionR.objects.filter(resume=instance).delete()
        for position_id in position_list:
            if position_id != '':
                position_obj = models.Position.objects.get(id=position_id)
                resume_position_r = models.ResumePositionR(resume=instance, position=position_obj)
                resume_position_r.save()
Example #3
0
	def _setup(out_file, args):
	    import strop
	    in_file = args[0]
	    # open file as specified in uu file and 
	    # assign out_file for later use
	    i = in_file.readline()
	    i = strop.strip(i)
	    if 'begin' != i[:5]:
		raise IOError, 'input file not in UUencoded format'
	    [dummy, mode, filename] = strop.split(i)
	    mode = strop.atoi(mode, 8)
	    out_file = open(filename,'w',mode)
	    _out_file_orig = 0
	    return (out_file,_out_file_orig)
Example #4
0
 def _setup(out_file, args):
     import strop
     in_file = args[0]
     # open file as specified in uu file and
     # assign out_file for later use
     i = in_file.readline()
     i = strop.strip(i)
     if 'begin' != i[:5]:
         raise IOError, 'input file not in UUencoded format'
     [dummy, mode, filename] = strop.split(i)
     mode = strop.atoi(mode, 8)
     out_file = open(filename, 'w', mode)
     _out_file_orig = 0
     return (out_file, _out_file_orig)
Example #5
0
                    def doSet():
                        isTest = False

                        if strip(arrInput[0]) == "":
                            isTest = True
                        else:
                            if chkIp(arrInput[0]):
                                if chkIp(arrInput[1]):
                                    if strip(arrInput[2]) == "":  # 可以不填写网关
                                        isTest = True
                                    else:

                                        if chkIp(arrInput[2]):
                                            isTest = True
                                        else:
                                            showMsg_Retrun(
                                                Constants.TXT_GATEWAY + " " +
                                                Constants.TXT_IP_ERROR)
                                else:
                                    showMsg_Retrun(Constants.TXT_NETMASK +
                                                   " " +
                                                   Constants.TXT_IP_ERROR)
                            else:
                                showMsg_Retrun(Constants.TXT_IP + " " +
                                               Constants.TXT_IP_ERROR)

                        if isTest:
                            strCode = objDig.infobox(
                                Constants.TXT_MESSAGE_NETWORK)
                            strSm = ""
                            # 得到所选网卡的MAC地址
                            for strName, strMac in arrChoices:
                                if strName == strSelNet:
                                    strSm = strMac
                                    break

                            write_network_conf(arrInput, strSelNet, strSm)
 def test_strip(self):
     self.assertTrue(strop.strip(" \t\n hello \t\n ") == "hello")
Example #7
0
import warnings
 def test_strip(self):
     self.assertTrue(strop.strip(" \t\n hello \t\n ") == "hello")
Example #9
0
def ReadRcm(rcm_path):
    with open(rcm_path, "r") as rcm_file:
        ids_and_clusters = [strop.strip(line).split('\t') for line in rcm_file]
        return zip(*ids_and_clusters)
Example #10
0
import warnings
Example #11
0
def show_network_dialog():
    """
    打开网络配置窗口
    :return:
    low()方法是把字符串转换为小写
    append()追加
    """
    arrChoices = []
    arrNet = netifaces.interfaces()
    for strNet in arrNet:
        if strNet.lower() != "lo":
            arrIp = netifaces.ifaddresses(strNet)

            if arrIp.has_key(netifaces.AF_LINK):

                arrIp = arrIp[netifaces.AF_LINK]
                if len(arrIp) > 0:
                    arrChoices.append((strNet, arrIp[0]["addr"]))

    strCode, strSelNet = objDig.menu(Constants.TXT_SELECT_INTERFACE,
                                     choices=arrChoices)

    if strCode == Dialog.OK:

        def getIp():
            """
            得到IP及网关
            :return: 
            """
            strI = ""
            strN = ""
            try:
                arrIp = netifaces.ifaddresses(strSelNet)

                if len(arrIp) > 0:
                    if arrIp.has_key(netifaces.AF_INET):
                        arrTmp = arrIp[netifaces.AF_INET]

                        if len(arrTmp) > 0:
                            arrTmp = arrTmp[0]
                            strI = arrTmp["addr"]
                            strN = arrTmp["netmask"]

            except Exception:
                pass
            return strI, strN

        def getGw():
            """
            得到网关地址
            :return: 
            """
            strW = ""
            try:
                arrIp = netifaces.gateways()

                if arrIp.has_key(netifaces.AF_INET):

                    arrIp = arrIp[netifaces.AF_INET]

                    for strG, strN, isDef in arrIp:
                        if strN == strSelNet:
                            strW = strG
                            break

            except Exception:
                pass
            return strW

        def showMsg_Retrun(strMsg):
            """
            验证错误时提示
            :param strMsg:  提示消息
            :return: true是
            """
            objDig.msgbox(strMsg)
            show_option_dialog()

        strIp, strNetMask = getIp()
        strGw = getGw()

        while True:
            try:
                strCode, arrInput = objDig.form(
                    Constants.TXT_CONFIG_STATIC_TITLE + strSelNet,
                    [(Constants.TXT_IP, 1, 1, strIp, 1, 20, 15, 15),
                     (Constants.TXT_NETMASK, 2, 1, strNetMask, 2, 20, 15, 15),
                     (Constants.TXT_GATEWAY, 3, 1, strGw, 3, 20, 15, 15)],
                    width=70)

                if strCode == Dialog.OK:

                    def doSet():
                        isTest = False

                        if strip(arrInput[0]) == "":
                            isTest = True
                        else:
                            if chkIp(arrInput[0]):
                                if chkIp(arrInput[1]):
                                    if strip(arrInput[2]) == "":  # 可以不填写网关
                                        isTest = True
                                    else:

                                        if chkIp(arrInput[2]):
                                            isTest = True
                                        else:
                                            showMsg_Retrun(
                                                Constants.TXT_GATEWAY + " " +
                                                Constants.TXT_IP_ERROR)
                                else:
                                    showMsg_Retrun(Constants.TXT_NETMASK +
                                                   " " +
                                                   Constants.TXT_IP_ERROR)
                            else:
                                showMsg_Retrun(Constants.TXT_IP + " " +
                                               Constants.TXT_IP_ERROR)

                        if isTest:
                            strCode = objDig.infobox(
                                Constants.TXT_MESSAGE_NETWORK)
                            strSm = ""
                            # 得到所选网卡的MAC地址
                            for strName, strMac in arrChoices:
                                if strName == strSelNet:
                                    strSm = strMac
                                    break

                            write_network_conf(arrInput, strSelNet, strSm)

                    if strip(arrInput[0]) == "":
                        code = objDig.yesno(Constants.TXT_CONF_NULLIP,
                                            height="5",
                                            width=65,
                                            yes_label="Yes",
                                            no_label="No")

                        if code == Dialog.CANCEL or code == Dialog.ESC:
                            show_option_dialog()
                        else:
                            doSet()

                    else:
                        doSet()
                else:
                    show_option_dialog()
            except Exception, e:
                strCode = objDig.msgbox(text=Constants.TXT_MESSAGE_ERROR % e,
                                        colors=True)
Example #12
0
def write_network_conf(arrIf, strSelIface, strMac):
    """
    写网络配置文件
    :param arrIf: 配置内容  [ip,mask,gw]
    :param strMac:选择的网卡MAC地址
    :param strSelIface:选择的网卡名称
    :return:
    """
    strFn = "/etc/sysconfig/network-scripts/ifcfg-" + strSelIface

    if os.path.isfile(strFn):  # 有可能网卡配置文件不存在,如果strFN是一个文件返回True
        run_process("sed -i '/BOOTPROTO/d' " + strFn)
        run_process("sed -i '/ONBOOT/d' " + strFn)
        run_process("sed -i '/IPADDR/d'  " + strFn)
        run_process("sed -i '/NETMASK/d'  " + strFn)
        run_process("sed -i '/GATEWAY/d'  " + strFn)
        run_process("sed -i '/IPV6INIT/d'  " + strFn)
        run_process("sed -i '/DEFROUTE/d'  " + strFn)

        run_process("sed -i '/IPV4_FAILURE_FATAL/d'  " + strFn)
        run_process("sed -i '/IPV6INIT/d'  " + strFn)
        run_process("sed -i '/IPV6_AUTOCONF/d'  " + strFn)
        run_process("sed -i '/IPV6_DEFROUTE/d'  " + strFn)
        run_process("sed -i '/IPV6_PEERDNS/d'  " + strFn)
        run_process("sed -i '/IPV6_PEERROUTES/d'  " + strFn)
        run_process("sed -i '/IPV6_FAILURE_FATAL/d'  " + strFn)
    else:
        run_process("echo 'TYPE=Ethernet' > " + strFn)
        run_process("echo 'PEERDNS=yes' >> " + strFn)
        run_process("echo 'PEERROUTES=yes' >> " + strFn)
        run_process("echo 'NAME=" + strSelIface + "' >> " + strFn)
        run_process("echo 'DEVICE=" + strSelIface + "' >> " + strFn)
        run_process("echo 'HWADDR=" + strMac + "' >> " + strFn)

    # 使用该管理工具配置时,没有网关就会写入no,
    #   如果通过管理平台其它的网卡时,CMON会写入DEFROUTE=yes,这样可以保证外网是默认路由(但是目前解决不了,在管理平台配置多个的问题后面要改,20170411)
    #   如果通过该工具配置时,配置网关就会写入yes,这样可以先配置内网不指定网关,再配置外网指定网关
    if strip(arrIf[2]) == "":
        run_process("echo 'DEFROUTE=no' >> " + strFn)
    else:
        run_process("echo 'DEFROUTE=yes' >> " + strFn)

    run_process("echo 'IPV4_FAILURE_FATAL=no' >> " + strFn)
    run_process("echo 'IPV6INIT=no' >> " + strFn)
    run_process("echo 'IPV6_AUTOCONF=no' >> " + strFn)
    run_process("echo 'IPV6_DEFROUTE=no' >> " + strFn)
    run_process("echo 'IPV6_PEERDNS=no' >> " + strFn)
    run_process("echo 'IPV6_PEERROUTES=no' >> " + strFn)
    run_process("echo 'IPV6_FAILURE_FATAL=no' >> " + strFn)

    if strip(arrIf[0]) != "":  # IP为空表示清空配置
        if strip(arrIf[2]) != "":  # 可以不输入GW,所以要判断下
            run_process("sed -i '1i GATEWAY=" + arrIf[2] + "' " + strFn)
            res_other_nic_defroute(strSelIface)

        run_process("sed -i '1i NETMASK=" + arrIf[1] + "' " + strFn)
        run_process("sed -i '1i IPADDR=" + arrIf[0] + "' " + strFn)
        run_process("sed -i '1i BOOTPROTO=static' " + strFn)
        run_process("sed -i '1i ONBOOT=yes' " + strFn)
    else:
        run_process("sed -i '1i ONBOOT=no' " + strFn)

    results = network_restart(strSelIface)

    strFinMsg = Constants.TXT_NETWORK_CFG_ERROR
    if results['retcode'] == 0:
        strFinMsg = Constants.TXT_NETWORK_CFG_SUCCESS

    strCode = objDig.msgbox(strFinMsg)
    show_option_dialog()