How to use list_grep method in autotest

Best Python code snippet using autotest_python Github


Full Screen

...151 """Return true if file contains the specified egrep pattern"""152 if not os.path.isfile(file):153 raise NameError('file %s does not exist' % file)154 return not utils.system('egrep -q "' + pattern + '" ' + file, ignore_status=True)155def list_grep(list, pattern):156 """True if any item in list matches the specified pattern."""157 compiled = re.compile(pattern)158 for line in list:159 match = if (match):161 return 1162 return 0163def get_os_vendor():164 """Try to guess what's the os vendor165 """166 if os.path.isfile('/etc/SuSE-release'):167 return 'SUSE'168 issue = '/etc/issue'169 if not os.path.isfile(issue):170 return 'Unknown'171 if file_contains_pattern(issue, 'Red Hat'):172 return 'Red Hat'173 elif file_contains_pattern(issue, 'Fedora'):174 return 'Fedora Core'175 elif file_contains_pattern(issue, 'SUSE'):176 return 'SUSE'177 elif file_contains_pattern(issue, 'Ubuntu'):178 return 'Ubuntu'179 elif file_contains_pattern(issue, 'Debian'):180 return 'Debian'181 else:182 return 'Unknown'183def get_cc():184 try:185 return os.environ['CC']186 except KeyError:187 return 'gcc'188def get_vmlinux():189 """Return the full path to vmlinux190 Ahem. This is crap. Pray harder. Bad Martin.191 """192 vmlinux = '/boot/vmlinux-%s' % utils.system_output('uname -r')193 if os.path.isfile(vmlinux):194 return vmlinux195 vmlinux = '/lib/modules/%s/build/vmlinux' % utils.system_output('uname -r')196 if os.path.isfile(vmlinux):197 return vmlinux198 return None199def get_systemmap():200 """Return the full path to System.map201 Ahem. This is crap. Pray harder. Bad Martin.202 """203 map = '/boot/' % utils.system_output('uname -r')204 if os.path.isfile(map):205 return map206 map = '/lib/modules/%s/build/' % utils.system_output('uname -r')207 if os.path.isfile(map):208 return map209 return None210def get_modules_dir():211 """Return the modules dir for the running kernel version"""212 kernel_version = utils.system_output('uname -r')213 return '/lib/modules/%s/kernel' % kernel_version214_CPUINFO_RE = re.compile(r'^(?P<key>[^\t]*)\t*: ?(?P<value>.*)$')215def get_cpuinfo():216 """Read /proc/cpuinfo and convert to a list of dicts."""217 cpuinfo = []218 with open('/proc/cpuinfo', 'r') as f:219 cpu = {}220 for line in f:221 line = line.strip()222 if not line:223 cpuinfo.append(cpu)224 cpu = {}225 continue226 match = _CPUINFO_RE.match(line)227 cpu['key')] ='value')228 if cpu:229 # cpuinfo usually ends in a blank line, so this shouldn't happen.230 cpuinfo.append(cpu)231 return cpuinfo232def get_cpu_arch():233 """Work out which CPU architecture we're running on"""234 f = open('/proc/cpuinfo', 'r')235 cpuinfo = f.readlines()236 f.close()237 if list_grep(cpuinfo, '^cpu.*(RS64|POWER3|Broadband Engine)'):238 return 'power'239 elif list_grep(cpuinfo, '^cpu.*POWER4'):240 return 'power4'241 elif list_grep(cpuinfo, '^cpu.*POWER5'):242 return 'power5'243 elif list_grep(cpuinfo, '^cpu.*POWER6'):244 return 'power6'245 elif list_grep(cpuinfo, '^cpu.*POWER7'):246 return 'power7'247 elif list_grep(cpuinfo, '^cpu.*PPC970'):248 return 'power970'249 elif list_grep(cpuinfo, 'ARM'):250 return 'arm'251 elif list_grep(cpuinfo, '^flags.*:.* lm .*'):252 return 'x86_64'253 elif list_grep(cpuinfo, 'CPU.*implementer.*0x41'):254 return 'arm'255 else:256 return 'i386'257def get_arm_soc_family_from_devicetree():258 """259 Work out which ARM SoC we're running on based on the 'compatible' property260 of the base node of devicetree, if it exists.261 """262 devicetree_compatible = '/sys/firmware/devicetree/base/compatible'263 if not os.path.isfile(devicetree_compatible):264 return None265 f = open(devicetree_compatible, 'r')266 compatible = f.readlines()267 f.close()268 if list_grep(compatible, 'rk3399'):269 return 'rockchip'270 elif list_grep(compatible, 'mt8173'):271 return 'mediatek'272 return None273def get_arm_soc_family():274 """Work out which ARM SoC we're running on"""275 family = get_arm_soc_family_from_devicetree()276 if family is not None:277 return family278 f = open('/proc/cpuinfo', 'r')279 cpuinfo = f.readlines()280 f.close()281 if list_grep(cpuinfo, 'EXYNOS5'):282 return 'exynos5'283 elif list_grep(cpuinfo, 'Tegra'):284 return 'tegra'285 elif list_grep(cpuinfo, 'Rockchip'):286 return 'rockchip'287 return 'arm'288def get_cpu_soc_family():289 """Like get_cpu_arch, but for ARM, returns the SoC family name"""290 f = open('/proc/cpuinfo', 'r')291 cpuinfo = f.readlines()292 f.close()293 family = get_cpu_arch()294 if family == 'arm':295 family = get_arm_soc_family()296 if list_grep(cpuinfo, '^vendor_id.*:.*AMD'):297 family = 'amd'298 return family299INTEL_UARCH_TABLE = {300 '06_1C': 'Atom',301 '06_26': 'Atom',302 '06_36': 'Atom',303 '06_4C': 'Braswell',304 '06_3D': 'Broadwell',305 '06_0D': 'Dothan',306 '06_3A': 'IvyBridge',307 '06_3E': 'IvyBridge',308 '06_3C': 'Haswell',309 '06_3F': 'Haswell',310 '06_45': 'Haswell',...

Full Screen

Full Screen

Automation Testing Tutorials

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.

LambdaTest Learning Hubs:


You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run autotest automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?