Exemple #1
0
	def waitForFolder(self, path, folder, timeout=1.0, watchEvery=0.5):
		"""
		Wait for folder, regexp supported on folder name
		
		@param path: current path folder
		@type path: string
		
		@param folder: folder to look up
		@type folder: string		

		@param timeout: time max to wait to receive event in second (default=1s)
		@type timeout: float				
	
		@param watchEvery: watch folder every xx seconds (default=0.5s)
		@type watchEvery: float				
		"""
		if not ( isinstance(timeout, int) or isinstance(timeout, float) ) or isinstance(timeout,bool): 
			raise TestAdapter.ValueException(TestAdapter.caller(), "timeout argument is not a float or integer (%s)" % type(timeout) )
		
		ret = False
		if not self.__logged:
			self.warning( "not logged" )
			return False

		tpl = self.encapsule( sftp_event=templates.wait_folder(path=path, folder=folder), cmd=WAIT_FOLDER)
		if path is not None: tpl.addRaw( path )
		self.logSentEvent( shortEvt = "wait for folder (%s sec.)" % timeout, tplEvt = tpl )
		
		if self.cfg['agent-support']:
			agent_cmd = {'cmd':  WAIT_FOLDER, 'path': path, 'folder': folder, 'timeout': timeout, 'watch-every': watchEvery}
			self.ssh().notifyAgent(cfg=agent_cmd)
		else:
			timeoutEvent = False
			startTime = time.time()
			try:
				true_folder=''
				while (not timeoutEvent):
					if (time.time() - startTime) >= timeout:
						timeoutEvent = True
					if not timeoutEvent:
						# list path
						ret_tmp = self.ssh().channel().listdir_attr(path=path)
						for f in ret_tmp:
							if stat.S_ISDIR(f.st_mode):
								if re.match( folder, f.filename):
									true_folder = f.filename
									ret = True
									timeoutEvent=True
					if not timeoutEvent: time.sleep(watchEvery)
			except Exception as e:
				tpl = self.encapsule( sftp_event=templates.response_error(rsp=str(e)), cmd=WAIT_FOLDER )
				tpl.addRaw( str(e) )
				self.logRecvEvent( shortEvt = "response error", tplEvt = tpl )
			else:
				tpl = self.encapsule( sftp_event=templates.wait_folder(path=path, folder=true_folder, result=ret), cmd=WAIT_FOLDER )
				self.logRecvEvent( shortEvt = "wait folder", tplEvt = tpl )
Exemple #2
0
	def hasDetectedFolder(self, path=None, folder=None, timeout=1.0):
		"""
		Wait to receive "detected" folder event
		
		@param path: path of the folder
		@type path: string/none	
		
		@param folder: folder detected
		@type folder: string/none	
		
		@param timeout: time max to wait to receive event in second (default=1s)
		@type timeout: float	

		@return: an event matching with the template or None otherwise
		@rtype: templatemessage		
		"""
		if not ( isinstance(timeout, int) or isinstance(timeout, float) ) or isinstance(timeout,bool): 
			raise TestAdapter.ValueException(TestAdapter.caller(), "timeout argument is not a float or integer (%s)" % type(timeout) )
		
		if not self.__logged:
			self.warning( "not logged" )
			return
		
		tpl_expected = self.encapsule( sftp_event=templates.wait_folder(path=path, folder=folder, result=True), cmd=WAIT_FOLDER)
		evt = self.received( expected = tpl_expected, timeout = timeout )
		return evt
Exemple #3
0
	def hasDetectedFolder(self, path=None, folder=None, timeout=1.0):
		"""
		Wait to receive "detected" folder event
		
		@param path: path of the folder
		@type path: string/none	
		
		@param folder: folder detected
		@type folder: string/none	
		
		@param timeout: time max to wait to receive event in second (default=1s)
		@type timeout: float	

		@return: an event matching with the template or None otherwise
		@rtype: templatemessage		
		"""
		TestAdapter.check_timeout(caller=TestAdapter.caller(), timeout=timeout)
		
		if not self.__logged:
			self.warning( "not logged" )
			return
		
		tpl_expected = self.encapsule( sftp_event=templates.wait_folder(path=path, folder=folder, result=True), cmd=WAIT_FOLDER)
		evt = self.received( expected = tpl_expected, timeout = timeout )
		return evt
Exemple #4
0
	def onSftpEvent(self, event):
		"""
		"""
		if 'sftp-event' in event:
			
			if event['sftp-event'] == 'response-error' :
				tpl = self.encapsule( sftp_event=templates.response_error(rsp=event['err']), cmd=event['cmd'] )
				tpl.addRaw( event['err'] )
				self.logRecvEvent( shortEvt = "response error", tplEvt = tpl )
				
			if event['sftp-event'] == 'folder-listing':
				tpl = self.encapsule( sftp_event=templates.response(rsp=event['rsp'] ), cmd=LISTING_FOLDER )
				tpl.addRaw( event['rsp'] )
				self.logRecvEvent( shortEvt = "folder listing", tplEvt = tpl )
				
			if event['sftp-event'] == 'folder-added':
				tpl = self.encapsule( sftp_event=templates.response(), cmd=ADD_FOLDER )
				self.logRecvEvent( shortEvt = "folder added", tplEvt = tpl )

			if event['sftp-event'] == 'file-renamed':
				tpl = self.encapsule( sftp_event=templates.response(), cmd=RENAME_FILE  )
				self.logRecvEvent( shortEvt = "file renamed", tplEvt = tpl )
				
			if event['sftp-event'] == 'file-deleted':
				tpl = self.encapsule( sftp_event=templates.response(), cmd=DELETE_FILE  )
				self.logRecvEvent( shortEvt = "file deleted", tplEvt = tpl )
				
			if event['sftp-event'] == 'folder-renamed':
				tpl = self.encapsule( sftp_event=templates.response() , cmd=RENAME_FOLDER )
				self.logRecvEvent( shortEvt = "folder renamed", tplEvt = tpl )
				
			if event['sftp-event'] == 'folder-deleted':
				tpl = self.encapsule( sftp_event=templates.response(), cmd=DELETE_FOLDER )
				self.logRecvEvent( shortEvt = "folder deleted", tplEvt = tpl )

			if event['sftp-event'] == 'file-downloaded':
				tpl = self.encapsule( sftp_event=templates.response(content=event['content']), cmd=GET_FILE )
				tpl.addRaw( event['content'] )
				self.logRecvEvent( shortEvt = "file downloaded", tplEvt = tpl )
				
			if event['sftp-event'] == 'file-uploaded':
				tpl = self.encapsule( sftp_event=templates.response(rsp=event['rsp']), cmd=PUT_FILE )
				tpl.addRaw( event['rsp'] )
				self.logRecvEvent( shortEvt = "file uploaded", tplEvt = tpl )
				
			if event['sftp-event'] == 'folder-downloaded':
				tpl = self.encapsule( sftp_event=templates.response(content=event['content']), cmd=GET_FOLDER )
				tpl.addRaw( event['content'] )
				self.logRecvEvent( shortEvt = "folder downloaded", tplEvt = tpl )
				
			if event['sftp-event'] == 'folder-uploaded':
				tpl = self.encapsule( sftp_event=templates.response(rsp=event['rsp']), cmd=PUT_FOLDER )
				tpl.addRaw( event['rsp'] )
				self.logRecvEvent( shortEvt = "folder uploaded", tplEvt = tpl )
				
			if event['sftp-event'] == 'wait-file':
				tpl = self.encapsule( sftp_event=templates.wait_file(path=event['path'], filename=event['filename'], result=event['result']), cmd=WAIT_FILE )
				self.logRecvEvent( shortEvt = "wait file", tplEvt = tpl )
				
			if event['sftp-event'] == 'wait-folder':
				tpl = self.encapsule( sftp_event=templates.wait_folder(path=event['path'], folder=event['folder'], result=event['result']), cmd=WAIT_FOLDER )
				self.logRecvEvent( shortEvt = "wait folder", tplEvt = tpl )