def __init__(self, host=None, port=5555, retryLimit=5, packageName='fennec', adbPath='adb', deviceSerial=None, deviceRoot=None, logLevel=mozlog.ERROR, autoconnect=True, runAdbAsRoot=False, **kwargs): DeviceManager.__init__(self, logLevel=logLevel, deviceRoot=deviceRoot) self.host = host self.port = port self.retryLimit = retryLimit # the path to adb, or 'adb' to assume that it's on the PATH self._adbPath = adbPath # The serial number of the device to use with adb, used in cases # where multiple devices are being managed by the same adb instance. self._deviceSerial = deviceSerial # Some devices do no start adb as root, if allowed you can use # this to reboot adbd on the device as root automatically self._runAdbAsRoot = runAdbAsRoot if packageName == 'fennec': if os.getenv('USER'): self._packageName = 'org.mozilla.fennec_' + os.getenv('USER') else: self._packageName = 'org.mozilla.fennec_' elif packageName: self._packageName = packageName # verify that we can run the adb command. can't continue otherwise self._verifyADB() if autoconnect: self.connect()
def main(): dm_none = DeviceManager(None, None) automation = RemoteAutomation(dm_none) parser = RemoteOptions(automation) options, args = parser.parse_args() if (options.deviceIP == None): print "Error: you must provide a device IP to connect to via the --device option" sys.exit(1) dm = DeviceManager(options.deviceIP, options.devicePort) automation.setDeviceManager(dm) if (options.remoteProductName != None): automation.setProduct(options.remoteProductName) # Set up the defaults and ensure options are set options = parser.verifyRemoteOptions(options) if (options == None): print "ERROR: Invalid options specified, use --help for a list of valid options" sys.exit(1) parts = dm.getInfo('screen')['screen'][0].split() width = int(parts[0].split(':')[1]) height = int(parts[1].split(':')[1]) if (width < 1050 or height < 1050): print "ERROR: Invalid screen resolution %sx%s, please adjust to 1366x1050 or higher" % (width, height) sys.exit(1) automation.setAppName(options.app) automation.setRemoteProfile(options.remoteProfile) automation.setRemoteLog(options.remoteLogFile) reftest = RemoteReftest(automation, dm, options, SCRIPT_DIRECTORY) # Start the webserver reftest.startWebServer(options) # Hack in a symbolic link for jsreftest os.system("ln -s ../jsreftest " + str(os.path.join(SCRIPT_DIRECTORY, "jsreftest"))) # Dynamically build the reftest URL if possible, beware that args[0] should exist 'inside' the webroot manifest = args[0] if os.path.exists(os.path.join(SCRIPT_DIRECTORY, args[0])): manifest = "http://" + str(options.remoteWebServer) + ":" + str(options.httpPort) + "/" + args[0] elif os.path.exists(args[0]): manifestPath = os.path.abspath(args[0]).split(SCRIPT_DIRECTORY)[1].strip('/') manifest = "http://" + str(options.remoteWebServer) + ":" + str(options.httpPort) + "/" + manifestPath procName = options.app.split('/')[-1] if (dm.processExist(procName)): dm.killProcess(procName) #an example manifest name to use on the cli # manifest = "http://" + options.remoteWebServer + "/reftests/layout/reftests/reftest-sanity/reftest.list" reftest.runTests(manifest, options) reftest.stopWebServer(options)
def __init__(self, host=None, port=5555, retryLimit=5, packageName='fennec', adbPath='adb', deviceSerial=None, deviceRoot=None, logLevel=mozlog.ERROR, **kwargs): DeviceManager.__init__(self, logLevel) self.host = host self.port = port self.retryLimit = retryLimit self.deviceRoot = deviceRoot # the path to adb, or 'adb' to assume that it's on the PATH self._adbPath = adbPath # The serial number of the device to use with adb, used in cases # where multiple devices are being managed by the same adb instance. self._deviceSerial = deviceSerial if packageName == 'fennec': if os.getenv('USER'): self._packageName = 'org.mozilla.fennec_' + os.getenv('USER') else: self._packageName = 'org.mozilla.fennec_' elif packageName: self._packageName = packageName # verify that we can run the adb command. can't continue otherwise self._verifyADB() # try to connect to the device over tcp/ip if we have a hostname if self.host: self._connectRemoteADB() # verify that we can connect to the device. can't continue self._verifyDevice() # set up device root self._setupDeviceRoot() # Some commands require root to work properly, even with ADB (e.g. # grabbing APKs out of /data). For these cases, we check whether # we're running as root. If that isn't true, check for the # existence of an su binary self._checkForRoot() # Can we use run-as? (not required) try: self._verifyRunAs() except DMError: pass # can we use zip to speed up some file operations? (currently not # required) try: self._verifyZip() except DMError: pass
def __init__(self, host, port=20701, retryLimit=5, deviceRoot=None, logLevel=logging.ERROR, **kwargs): DeviceManager.__init__(self, logLevel=logLevel, deviceRoot=deviceRoot) self.host = host self.port = port self.retryLimit = retryLimit self._sock = None self._everConnected = False # Get version verstring = self._runCmds([{'cmd': 'ver'}]) ver_re = re.match('(\S+) Version (\S+)', verstring) self.agentProductName = ver_re.group(1) self.agentVersion = ver_re.group(2)
def __init__(self, host, port=20701, retryLimit=5, deviceRoot=None, logLevel=mozlog.ERROR, **kwargs): DeviceManager.__init__(self, logLevel) self.host = host self.port = port self.retryLimit = retryLimit self._sock = None self._everConnected = False self.deviceRoot = deviceRoot # Initialize device root self.getDeviceRoot() # Get version verstring = self._runCmds([{"cmd": "ver"}]) ver_re = re.match("(\S+) Version (\S+)", verstring) self.agentProductName = ver_re.group(1) self.agentVersion = ver_re.group(2)
def __init__(self, host=None, port=5555, retryLimit=5, packageName='fennec', adbPath=None, deviceSerial=None, deviceRoot=None, logLevel=logging.ERROR, autoconnect=True, runAdbAsRoot=False, serverHost=None, serverPort=None, **kwargs): DeviceManager.__init__(self, logLevel=logLevel, deviceRoot=deviceRoot) self.host = host self.port = port self.retryLimit = retryLimit self._serverHost = serverHost self._serverPort = serverPort # the path to adb, or 'adb' to assume that it's on the PATH self._adbPath = adbPath or 'adb' # The serial number of the device to use with adb, used in cases # where multiple devices are being managed by the same adb instance. self._deviceSerial = deviceSerial # Some devices do no start adb as root, if allowed you can use # this to reboot adbd on the device as root automatically self._runAdbAsRoot = runAdbAsRoot if packageName == 'fennec': if os.getenv('USER'): self._packageName = 'org.mozilla.fennec_' + os.getenv('USER') else: self._packageName = 'org.mozilla.fennec_' elif packageName: self._packageName = packageName # verify that we can run the adb command. can't continue otherwise self._verifyADB() if autoconnect: self.connect()
def __init__(self, context=None, case=None): self.logger = Logger.getLogger() self.assertion = assertion() self.logger.debug('init store') self.store = store(context, case) self.device = DeviceManager.getInstance().getDevice() self._isRecord = context.isRecording() self._checkpoint = -1
def open_connection(self, args): host = args[0] port = args[1] device_class = args[2] profiles_path = args[3] self.fpm = None dm = DeviceManager(host, port) dm.debug = 3 if not dm._sock: dm = None wx.PostEvent(self.notify_window, FptEvent('conn_failed', ('%s:%d' % (host, port),))) if dm: self.fpm = FennecProfileTool(profiles_path, device_class, dm, self.set_status) if not self.fpm.default_profile: self.fpm = None wx.PostEvent(self.notify_window, FptEvent('no_default_profile', (host,))) else: wx.PostEvent(self.notify_window, FptEvent('connected', (dm.host,)))
def __init__(self, host, port = 20701, retryLimit = 5, deviceRoot = None, logLevel = mozlog.ERROR, **kwargs): DeviceManager.__init__(self, logLevel) self.host = host self.port = port self.retryLimit = retryLimit self._sock = None self._everConnected = False self.deviceRoot = deviceRoot # Initialize device root self.getDeviceRoot() # Get version verstring = self._runCmds([{ 'cmd': 'ver' }]) ver_re = re.match('(\S+) Version (\S+)', verstring) self.agentProductName = ver_re.group(1) self.agentVersion = ver_re.group(2)
class testWorker: """ provides the executing ability of each command-line in TestCase """ def __init__(self, context=None, case=None): self.logger = Logger.getLogger() self.assertion = assertion() self.logger.debug('init store') self.store = store(context, case) self.device = DeviceManager.getInstance().getDevice() self._isRecord = context.isRecording() self._checkpoint = -1
def __init__(self, host=None, port=5555, retryLimit=5, packageName='fennec', adbPath='adb', deviceSerial=None, deviceRoot=None, logLevel=mozlog.ERROR, autoconnect=True, **kwargs): DeviceManager.__init__(self, logLevel) self.host = host self.port = port self.retryLimit = retryLimit self.deviceRoot = deviceRoot # the path to adb, or 'adb' to assume that it's on the PATH self._adbPath = adbPath # The serial number of the device to use with adb, used in cases # where multiple devices are being managed by the same adb instance. self._deviceSerial = deviceSerial if packageName == 'fennec': if os.getenv('USER'): self._packageName = 'org.mozilla.fennec_' + os.getenv('USER') else: self._packageName = 'org.mozilla.fennec_' elif packageName: self._packageName = packageName # verify that we can run the adb command. can't continue otherwise self._verifyADB() if autoconnect: self.connect()
import logging import pulsectl from devicemanager import DeviceManager logger = logging.getLogger('default') logger.setLevel(logging.DEBUG) logger.addHandler(logging.StreamHandler()) pulse_server = pulsectl.Pulse('sony_disconnect') device_manager = DeviceManager() def get_sink_by_index(sink_list, sink_index): for sink in sink_list: if sink.index == sink_index: return sink return False # TODO: check that 'bt-device' installed with pulsectl.Pulse('event-printer') as pulse: def print_events(ev): event_type = ev.t if ev.facility == pulsectl.PulseEventFacilityEnum.sink: sink = get_sink_by_index(pulse_server.sink_list(), ev.index) if event_type == pulsectl.PulseEventTypeEnum.new: logger.info(f'New sink found: {sink}') device_manager.add_device(sink)
def parseMessage(msg_type=None, session_id=None, caseresult_id=None, test_info=None, file_path=None): logger = Logger.getLogger() if msg_type == 'sessiondata': logger.debug( '********************session request***********************') url = SendUtils._session_create_url % session_id sessionStarttime = TestBuilder.getBuilder().getStartTime() deviceId = DeviceManager.getInstance().getDevice().getDeviceId() properties = DeviceManager.getInstance().getDevice().getDeviceInfo( ) logger.debug( '********************session starttime*********************' + sessionStarttime) postData = { 'planname': 'plan', 'starttime': sessionStarttime, 'deviceid': deviceId, 'deviceinfo': properties } contentType = 'application/json' method = 'POST' return { 'url': url, 'data': postData, 'content_type': contentType, 'method': method } if msg_type == 'caseresult': logger.debug( '********************case result*********************') sid = session_id tid = caseresult_id info = test_info path = file_path if info: if info[0] == 'startTest': logger.debug( '********************start test*********************') url = (SendUtils._caseresult_create_url) % (sid, tid) caseName = info[1][1]._testMethodName startTime = time.strftime('%Y-%m-%d %H:%M:%S ', time.localtime(time.time())) postData = {'casename': caseName, 'starttime': startTime} contentType = 'application/json' method = 'POST' return [{ 'url': url, 'data': postData, 'content_type': contentType, 'method': method }] elif info[0] == 'addSuccess': logger.debug( '********************add success***********************' ) url = (SendUtils._caseresult_update_url) % (sid, tid) _time = time.strftime('%Y-%m-%d %H:%M:%S ', time.localtime(time.time())) postData = {'result': 'pass', 'time': _time} contentType = 'application/json' method = 'POST' return [{ 'url': url, 'data': postData, 'content_type': contentType, 'method': method }] elif info[0] == 'addFailure': logger.debug( '********************add failure***********************' ) resultUrl = (SendUtils._caseresult_update_url) % (sid, tid) resultTime = time.strftime('%Y-%m-%d %H:%M:%S ', time.localtime(time.time())) resultPostData = {'result': 'fail', 'time': resultTime} resultContentType = 'application/json' resultMethod = 'POST' resultRequest = { 'url': resultUrl, 'data': resultPostData, 'content_type': resultContentType, 'method': resultMethod } #log file logUrl = (SendUtils._upload_file_url) % (sid, tid) logfolder = os.path.join( info[1][1].worker.store.getFailDir(), 'log') zipName = '%s_%s.%s' % (sid, tid, 'zip') zipFolder(logfolder, zipName) logPostData = _openFile(zipName) logContentType = 'application/zip' logMethod = 'PUT' fileRequest = { 'url': logUrl, 'data': logPostData, 'content_type': logContentType, 'method': logMethod } return [resultRequest, fileRequest] elif info[0] == 'addError': logger.debug( '********************add error***********************') resultUrl = (SendUtils._caseresult_update_url) % (sid, tid) resultTime = time.strftime('%Y-%m-%d %H:%M:%S ', time.localtime(time.time())) resultPostData = {'result': 'error', 'time': resulTime} resultContentType = 'application/json' resultMethod = 'POST' resultRequest = { 'url': resultUrl, 'data': resultPostData, 'content_type': resultContentType, 'method': resultMethod } #log file #logUrl = (SendUtils._upload_file_url) % (sid,tid) #logfolder = os.path.join(info[1][1].device.workspace_result_fail,'log') #zipName = '%s_%s.%s'%(sid,tid,'zip') #zipFolder(logfolder,_zipname) #logPostData = _openFile(_zipname) #logContentType = 'application/zip' #logMethod = 'PUT' #fileRequest = {'url':logUrl,'data':logPostData,'content_type':logContentType,'method':logMethod} return [resultRequest] elif file_path: logger.debug( '********************upload snapshot***********************' ) sid = session_id tid = caseresult_id url = (SendUtils._upload_file_url) % (sid, tid) postData = _openFile(file_path) contentType = 'image/png' method = 'PUT' return [{ 'url': url, 'data': postData, 'content_type': contentType, 'method': method }]
eveapp.test_client().post( '/devices', data=json.dumps({ 'name': device, 'queries': [ "_".join([device, query]) for query in devicemanager.get_queries(device) ] }), content_type='application/json') for query in devicemanager.get_queries(device): eveapp.test_client().post('/queries', data=json.dumps({ 'name': "_".join([device, query]), 'device': device, 'value': 0 }), content_type='application/json') devices = DeviceManager(ConfigBundle("conf")) # pylint: disable=invalid-name pysattuner = Eve(settings='dev_settings.py') # pylint: disable=invalid-name spawn_device_resources(devices, pysattuner) if __name__ == '__main__': pysattuner.run(host='0.0.0.0', port=5000, debug=True)
#!/usr/bin/env python # -*- coding: utf-8 -*- from twisted.internet import reactor from twisted.web import static, server from twisted.web.resource import Resource import logging logging.basicConfig(format='%(asctime)s %(message)s', level=logging.DEBUG) from devicemanager import DeviceManager devices = DeviceManager() import sys class WritableObject: def __init__(self): self.content = [] def write(self, string): self.content.append(string) def dump(self): dump = self.content self.content = [] return str(''.join(dump)) WritableObject = WritableObject()
def parseMessage(msg_type=None,session_id=None,caseresult_id=None,test_info=None,file_path=None): logger = Logger.getLogger() if msg_type == 'sessiondata': logger.debug('********************session request***********************') url = SendUtils._session_create_url % session_id sessionStarttime = TestBuilder.getBuilder().getStartTime() deviceId = DeviceManager.getInstance().getDevice().getDeviceId() properties = DeviceManager.getInstance().getDevice().getDeviceInfo() logger.debug('********************session starttime*********************'+sessionStarttime) postData = {'planname':'plan','starttime':sessionStarttime,'deviceid':deviceId,'deviceinfo':properties} contentType = 'application/json' method = 'POST' return {'url':url,'data':postData,'content_type':contentType,'method':method} if msg_type == 'caseresult': logger.debug('********************case result*********************') sid = session_id tid = caseresult_id info = test_info path = file_path if info: if info[0] == 'startTest': logger.debug('********************start test*********************') url = (SendUtils._caseresult_create_url) % (sid,tid) caseName = info[1][1]._testMethodName startTime = time.strftime('%Y-%m-%d %H:%M:%S ', time.localtime(time.time())) postData = {'casename':caseName,'starttime':startTime} contentType = 'application/json' method = 'POST' return [{'url':url,'data':postData,'content_type':contentType,'method':method}] elif info[0] == 'addSuccess': logger.debug('********************add success***********************') url = (SendUtils._caseresult_update_url) % (sid,tid) _time = time.strftime('%Y-%m-%d %H:%M:%S ', time.localtime(time.time())) postData = {'result':'pass','time':_time} contentType = 'application/json' method = 'POST' return [{'url':url,'data':postData,'content_type':contentType,'method':method}] elif info[0] == 'addFailure': logger.debug('********************add failure***********************') resultUrl = (SendUtils._caseresult_update_url) % (sid,tid) resultTime = time.strftime('%Y-%m-%d %H:%M:%S ', time.localtime(time.time())) resultPostData = {'result':'fail','time':resultTime} resultContentType = 'application/json' resultMethod = 'POST' resultRequest = {'url':resultUrl,'data':resultPostData,'content_type':resultContentType,'method':resultMethod} #log file logUrl = (SendUtils._upload_file_url) % (sid,tid) logfolder = os.path.join(info[1][1].worker.store.getFailDir(),'log') zipName = '%s_%s.%s'%(sid,tid,'zip') zipFolder(logfolder,zipName) logPostData = _openFile(zipName) logContentType = 'application/zip' logMethod = 'PUT' fileRequest = {'url':logUrl,'data':logPostData,'content_type':logContentType,'method':logMethod} return [resultRequest,fileRequest] elif info[0] == 'addError': logger.debug('********************add error***********************') resultUrl = (SendUtils._caseresult_update_url) % (sid,tid) resultTime = time.strftime('%Y-%m-%d %H:%M:%S ', time.localtime(time.time())) resultPostData = {'result':'error','time':resulTime} resultContentType = 'application/json' resultMethod = 'POST' resultRequest = {'url':resultUrl,'data':resultPostData,'content_type':resultContentType,'method':resultMethod} #log file #logUrl = (SendUtils._upload_file_url) % (sid,tid) #logfolder = os.path.join(info[1][1].device.workspace_result_fail,'log') #zipName = '%s_%s.%s'%(sid,tid,'zip') #zipFolder(logfolder,_zipname) #logPostData = _openFile(_zipname) #logContentType = 'application/zip' #logMethod = 'PUT' #fileRequest = {'url':logUrl,'data':logPostData,'content_type':logContentType,'method':logMethod} return [resultRequest] elif file_path: logger.debug('********************upload snapshot***********************') sid = session_id tid = caseresult_id url = (SendUtils._upload_file_url) % (sid,tid) postData = _openFile(file_path) contentType = 'image/png' method = 'PUT' return [{'url':url,'data':postData,'content_type':contentType,'method':method}]
from devicemanager import DeviceManager from device import Device device1 = Device("Lamp 1", False) device2 = Device("Lamp 2", False) device3 = Device("Philips hue", True) device4 = Device("Nest", False) manager = DeviceManager() manager.add_device(1, device1) manager.add_device(2, device2) manager.add_device(3, device3) manager.add_device(4, device4) manager.switch_everything_off() for id, device in manager.device_dict.items(): print(id) print(device)