Best Python code snippet using fMBT_python
eyenfinger.py
Source: eyenfinger.py
...1066 press, release = 1, 11067 else:1068 raise ValueError('Invalid keySpec "%s"' % (a,))1069 if inputKeySeq:1070 _writeInputKeySeq(_deviceFilename(device), inputKeySeq, hold=hold, delay=delay)1071def _deviceFilename(deviceName):1072 if not _deviceFilename.deviceCache:1073 _deviceFilename.deviceCache = dict(_listInputDevices())1074 if not deviceName in _deviceFilename.deviceCache:1075 return deviceName1076 else:1077 return _deviceFilename.deviceCache[deviceName]1078_deviceFilename.deviceCache = {}1079def _listInputDevices():1080 nameAndFile = []1081 for l in file("/proc/bus/input/devices"):1082 if l.startswith("N: Name="):1083 nameAndFile.append([l.split('"')[1]])1084 elif l.startswith("H: Handlers=") and "event" in l:1085 try:...
__init__.py
Source: __init__.py
1# Copyright Qwilt, 20122# 3# The code contained in this file may not be used by any other entities without explicit written permission from Qwilt.4# 5# Author: effiz6G_NAME_MODULE_SYS_HARDWARE_PCI = "sys-hardware-pci"7G_NAME_GROUP_SYS_HARDWARE_PCI_HAL = "hal"8import os9from a.infra.basic.return_codes import ReturnCodes10if __package__ is None:11 G_NAME_MODULE_SYS_HARDWARE_PCI = "unknown"12 G_NAME_GROUP_SYS_HARDWARE_PCI_HAL = "unknown"13else:14 from . import G_NAME_MODULE_SYS_HARDWARE_PCI15 from . import G_NAME_GROUP_SYS_HARDWARE_PCI_HAL16# Constants17DEFAULT_SYS_PCI_DEVICE_DIR = "/sys/bus/pci/devices/"18DEFAULT_VENDOR_FILE_NAME = "vendor"19DEFAULT_DEVICE_FILE_NAME = "device"20class PciHal(object):21 def __init__ (self, logger):22 self._log = logger.createLogger(G_NAME_MODULE_SYS_HARDWARE_PCI, G_NAME_GROUP_SYS_HARDWARE_PCI_HAL)23 def init(self,deviceDir=DEFAULT_SYS_PCI_DEVICE_DIR, vendorFileName=DEFAULT_VENDOR_FILE_NAME, deviceFileName=DEFAULT_DEVICE_FILE_NAME):24 if not os.path.isdir(deviceDir):25 self._log("bad-device-dir").error("Bad device directory '%s' - non existent or not a dir",deviceDir)26 return False # TODO - change to return codes or exception27 self._deviceDir = deviceDir28 self._vendorFileName = vendorFileName29 self._deviceFileName = deviceFileName30 return True # TODO - change to return codes or exception31 def getDevicePciAddressByDeviceId(self,vendorId,deviceId,index):32 """33 Get a pci device id by vendorId, deviceId and index.34 35 Args:36 vendorId (number)37 deviceId (number)38 index39 Returns:40 A string representing the pci address (in the form of xxxx:xx:xx.x , e.g. 0000:03:00.0)41 or None if no much was found.42 """43 return self.getDevicePciAddressByDeviceIdList(vendorId,[deviceId],index)44 45 def getDevicePciAddressByDeviceIdList(self,vendorId,deviceIds,index):46 """47 Get a pci device id by vendorId, multiple deviceIds and index.48 49 Args:50 vendorId (number)51 deviceId list (number,...)52 index53 Returns:54 A string representing the pci address (in the form of xxxx:xx:xx.x , e.g. 0000:03:00.0)55 or None if no much was found.56 """57 deviceIdStrList = ['0x%04x' % deviceId for deviceId in deviceIds]58 try:59 matchCount = 060 # Scan the device directory for a match on vendor id and device id61 for pciAddress in sorted(os.listdir(self._deviceDir)):62 curVendorPath = os.path.join(self._deviceDir,pciAddress,self._vendorFileName)63 curDevicePath = os.path.join(self._deviceDir,pciAddress,self._deviceFileName)64 65 # Read the files' content of vendor and device66 curVendorFd = open(curVendorPath,"r")67 curVendorId = int(curVendorFd.readline(),16)68 curVendorFd.close()69 curDeviceFd = open(curDevicePath,"r")70 curDeviceId = int(curDeviceFd.readline(),16)71 curDeviceFd.close()72 self._log("a-device-found").debug4("a device with vendorId=0x%04x and deviceId=0x%04x was found in pci address %s.",vendorId,deviceId,pciAddress)73 74 # handle found match - append to list of potential matches75 if ((curVendorId==vendorId) and (curDeviceId in deviceIds)):76 if (index == matchCount):77 self._log("matching-device-found-on-index").debug1("matching device with vendorId=0x%04x ,deviceId=0x%04x and index=%d was found in pci address %s.",curVendorId,curDeviceId,index,pciAddress)78 return pciAddress79 else:80 self._log("matching-device-found-not-on-index").debug2("matching device with vendorId=0x%04x ,deviceIds=%s and index=%d (requestedIndex was %d) was found in pci address %s.",vendorId,deviceIdStrList,matchCount,index,pciAddress)81 matchCount+=182 except:83 self._log("scan-failed-on-device-dir").exception("Failed to scan %s for pci id.",self._deviceDir)84 return None85 # if you got here, you didn't find the device86 self._log("no-matching-device-found").warning("Matching device with vendorId=0x%04x, deviceId=%s and index=%d was not found.",vendorId,deviceIdStrList,index)...
Check out the latest blogs from LambdaTest on this topic:
Collecting and examining data from multiple sources can be a tedious process. The digital world is constantly evolving. To stay competitive in this fast-paced environment, businesses must frequently test their products and services. While it’s easy to collect raw data from multiple sources, it’s far more complex to interpret it properly.
Hola Testers! Hope you all had a great Thanksgiving weekend! To make this time more memorable, we at LambdaTest have something to offer you as a token of appreciation.
When I started writing tests with Cypress, I was always going to use the user interface to interact and change the application’s state when running tests.
So, now that the first installment of this two fold article has been published (hence you might have an idea of what Agile Testing is not in my opinion), I’ve started feeling the pressure to explain what Agile Testing actually means to me.
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!!