Best Python code snippet using avocado_python
__init__.py
Source:__init__.py
...103 @property104 def is_available(self):105 return PortManager().is_available(self)106 @property107 def is_bond(self):108 return 'eth_bond' in self.name109 @property110 def is_dpdk(self):111 return self.driver == self.dpdk_driver or \112 self.is_bond or self.is_ring113 @property114 def is_netmap(self):115 return self.driver == self.netmap_driver116 @property117 def is_ring(self):118 return 'eth_ring' in self.name119 @property120 def is_virtual(self):121 return self.is_bond or self.is_ring...
models.py
Source:models.py
1# -*- coding:utf-8 -*-2import logging3import traceback4from django.conf import settings5from utils.utils import is_private_ip, mask_repr6# å
åä¿¡æ¯7class MemInfo(object):8 def __init__(self):9 # 5.1 ç产åå10 self.mem_mf = ''11 # 5.2 åå·12 self.mem_model = ''13 # 5.3 容é (GB)14 self.mem_size = 015 # 5.4 æ°é16 self.mem_number = 017 18class HardDiskInfo(object):19 def __init__(self):20 # 6.1 ç¼å·21 self.hd_sn = ''22 # 6.2 ç产åå23 self.hd_mf = ''24 # 6.3 æ¥å£ç±»å25 self.hd_interface = ''26 # 6.4 åå·27 self.hd_model = ''28 # 6.5 转é29 self.hd_speed = 030 # 6.6 åç容é(G)31 self.hd_size = 032 # 6.7 æ°é33 self.hd_number = 034# 主æºç¡¬ä»¶ä¿¡æ¯35class HostHardware(object):36 def __init__(self):37 # 1. æºå¨ä¿¡æ¯38 # 1.1 æºå¨ç产åå39 self.machine_mf = ''40 # 1.2 æºå¨åå·41 self.machine_model = ''42 # 1.3 æºå¨åºåå·43 self.machine_sn = ''44 45 # 2. æä½ç³»ç»46 # 2.1 OSç±»å47 self.os_type = ''48 # 2.2 OSä½æ°49 self.os_bit = ''50 # 2.3 OSçæ¬51 self.os_version = ''52 53 # 3. IPä¿¡æ¯54 # 3.1 管çIP 55 self.manage_ip = ''56 # 3.2 å
ç½IP (æå¤ä¸ªåéå·åé)57 self.private_ip = ''58 # 3.3 å¤ç½IP (æå¤ä¸ªåéå·åé)59 self.public_ip = ''60 # 3.4 æ¯å¦Bond61 self.is_bond = False62 # 3.5 ååæå¡å¨63 self.nameserver = ''64 65 # 4. CPUä¿¡æ¯66 # 4.1 CPUç产åå67 self.processor_mf = ''68 # 4.2 åå·69 self.processor_model = ''70 # 4.3 å
æ ¸æ°71 self.processor_cores = 072 # 4.4 æ°é(个æ°)73 self.processor_number = 074 75 # 5. å
åä¿¡æ¯76 self.mem_list = []77 78 # 6. ç£çä¿¡æ¯79 self.hard_disk_list = []80def parse_ip_info(data):81 private_ip_list = []82 public_ip_list = []83 item_list = data.split(';')84 for item in item_list:85 temp_list = item.split(':')86 tt = '%s/%s %s' % (temp_list[1], mask_repr(temp_list[2]), temp_list[3])87 88 if is_private_ip(temp_list[1]):89 private_ip_list.append(tt)90 else:91 public_ip_list.append(tt)92 93 data = data.lower() 94 95 is_bond = True96 if data.find('bond') == -1:97 is_bond = False98 99 return ','.join(private_ip_list), ','.join(public_ip_list), is_bond100 101 102def parse_mem_info(data):103 res_list = []104 item_list = data.split(';')105 for item in item_list:106 temp_list = item.split(':')107 m = MemInfo()108 m.mem_mf = temp_list[0]109 m.mem_model = temp_list[1]110 m.mem_size = temp_list[2]111 m.mem_number = temp_list[3]112 res_list.append(m)113 return res_list114 115# å°å¤æææºå¨ç硬件信æ¯å表 116def export_hardware_info():117 logger = logging.getLogger("django")118 pipe = settings.REDIS_DB.pipeline()119 120 # éè¿ç¡¬ä»¶æ£æ¥ç»æå¾å°121 ip_host_dict = settings.REDIS_DB.hgetall("ip_host")122 123 host_set = set()124 logger.info("è·åip_hostå表")125 for ip in ip_host_dict:126 logger.info("IP:%s, host_id:%s", ip, ip_host_dict[ip])127 host = ip_host_dict[ip]128 # åªæåçå®ä¸»æºçä¿¡æ¯129 if host.startswith('GD'):130 host_set.add(host)131 132 host_list = list(host_set) 133 for host in host_list:134 pipe.hgetall(host + '_hc') 135 136 item_list = pipe.execute()137 res_list = []138 # 失败æ°139 fail_count = 0140 count = len(item_list)141 for i in range(len(item_list)):142 host = host_list[i]143 logger.info("å¼å§å¤ç主æºç¡¬ä»¶ä¿¡æ¯, host_id:%s", host)144 145 item = item_list[i]146 if not item:147 continue148 try: 149 temp = HostHardware()150 temp.machine_mf = item['MANUFACTURER'] 151 temp.machine_model = item['PRODUCT_NAME']152 temp.machine_sn = item['SERIAL_NUMBER']153 154 temp.os_type = item['OS_TYPE']155 temp.os_bit = item['OS_BIT']156 temp.os_version = item['OS_VERSION']157 158 temp.manage_ip = item['MANAGE_IP']159 #temp.manage_ip = ''160 temp.private_ip, temp.public_ip, temp.is_bond = parse_ip_info(item['SYS_NETWORK'])161 162 #temp.private_ip = item['IP']163 164 temp.nameserver = item['NAMESERVER']165 166 temp.processor_mf = item['PROCESSOR_MANUFACTURER']167 temp.processor_model = item['PROCESSOR_TYPE']168 temp.processor_cores = item['PROCESSOR_CORES']169 temp.processor_number = item['PROCESSOR_NUMBER']170 171 temp.mem_list = parse_mem_info(item['MEM_INFO'])172 173 # ç®å没æåå¾ç¡¬çä¿¡æ¯, æå
¥ä¸æ¡ç©ºè®°å½174 hd = HardDiskInfo()175 hd.hd_sn = ''176 hd.hd_mf = ''177 hd.hd_interface = ''178 hd.hd_model = ''179 hd.hd_speed = ''180 hd.hd_size = ''181 hd.hd_number = ''182 183 temp.hard_disk_list = [hd]184 185 res_list.append(temp)186 except BaseException:187 fail_count = fail_count + 1188 logger.error("å¤ç主æºç¡¬ä»¶ä¿¡æ¯å¼å¸¸,host_id:%s, éå ä¿¡æ¯:\n%s", host, traceback.format_exc())189 190 logger.error("å
±å¤ç主æºæ°:%s, 失败æ°:%s", count, fail_count)191 return res_list192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 ...
connectivity.py
Source:connectivity.py
1import numpy as np2from math import *3from .util import *4from .molecule import *5import sys6write = sys.stdout.write7def print_distance_and_connectivity(distances, connectivity, molecule):8 write("Covalent bonds in the molecule:\n")9 natoms = molecule.natoms10 for k in range(0, natoms):11 for l in range(k+1, natoms):12 if connectivity[k+l*natoms] == 1:13 write(" %2s%-3d - %2s%-3d: %9.5f Ang\n" % 14 (molecule.atmsym[k], k+1, molecule.atmsym[l], l+1, distances[k+l*natoms]))15 write("\n")16def print_distances_2_img(xyzfile, distances, connectivity, molecule):17 spt = open("connect.spt", "w")18 spt.write("background = white\n")19 spt.write("load "+xyzfile+"\n")20 spt.write("label %a\n")21 spt.write("defaultDistanceLabel = \"%6.4VALUE\"\n")22 spt.write("set measurements angstroms\n")23 spt.write("set measurementnumbers on\n")24 natoms = molecule.natoms25 for k in range(0, natoms):26 for l in range(k+1, natoms):27 if connectivity[k+l*natoms] == 1 and molecule.atmsym[k] != 'H' and molecule.atmsym[l] != 'H':28 spt.write("measure (atomno=%3d) (atomno=%3d)\n" % (k+1, l+1))29 spt.write("write image "+xyzfile[:-3]+"png\n")30 spt.close()31 os.system("jmol -n connect.spt")32def get_distance_and_connectivity(distances, connectivity, molecule):33 natoms = molecule.natoms34 #write("natoms=%d\n" % (natoms))35 connect = []36 for k in range(0, natoms*natoms):37 connect.append(0)38 # nearest neighbors39 for i in range(0, natoms):40 for j in range(i+1, natoms):41 #compute distance42 r2 = 043 for k in range(0, 3):44 diff = molecule.coords[3*i+k] - molecule.coords[3*j+k]45 r2 += diff*diff46 dist = sqrt(r2)*BOHR47 distances[i+j*natoms] = distances[j+i*natoms] = dist48 #connectivitity49 #this is a little bit arbitrary, need to fix later50 is_bond = 051 if molecule.atmsym[i] != 'H' and molecule.atmsym[j] != 'H':52 is_bond = dist < 1.953 elif molecule.atmsym[i] != 'H' or molecule.atmsym[j] != 'H':54 if molecule.atmsym[i] == 'O' or molecule.atmsym[j] == 'O': #O-H bond55 is_bond = dist < 1.256 else:57 is_bond = dist < 1.658 else:59 is_bond = dist < 1.260 if is_bond: 61 connect[i+j*natoms] = connect[j+i*natoms] = 162 # second-nearest neighbors63 for i in range(0, natoms):64 for j in range(0, natoms):65 if connect[i+j*natoms] == 1:66 for k in range(0, natoms):67 if k != i and k != j and connect[k+j*natoms] == 1 and connect[k+i*natoms] == 0:68 connect[k+i*natoms] = connect[i+k*natoms] = 269 # third-nearest neighbors70 for i in range(0, natoms):71 for j in range(0, natoms):72 if connect[i+j*natoms] == 2:73 for k in range(0, natoms):74 if k != i and k != j and connect[k+j*natoms] == 1 and connect[k+i*natoms] == 0:75 connect[k+i*natoms] = connect[i+k*natoms] = 376 connectivity[:] = connect77def fragment_analysis(frag_index, natoms, connectivity):78 ifrag = -179 for m in range(0, natoms): frag_index.append(-1)80 for m in range(0, natoms): 81 iatom = -182 for n in range(0, natoms):83 if frag_index[n] == -1: 84 iatom = n 85 ifrag += 186 break87 #print("iatom: ", iatom, "ifrag=", ifrag)88 if iatom == -1: break89 frag_index[iatom] = ifrag90 for n in range(0, natoms):91 if frag_index[n] == -1:92 for k in range(0, natoms):93 if frag_index[k] == ifrag and connectivity[k+n*natoms] == 1:94 frag_index[n] = ifrag...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!