def comando_vfpe(self, template, **kwargs): if kwargs['numero_identificador'] != 'False': numero_identificador = kwargs.get( 'numero_sessao', kwargs['numero_identificador'], ) else: numero_identificador = kwargs.get( 'numero_sessao', self.gerar_numero_sessao(), ) kwargs['numero_identificador'] = numero_identificador path_file = self.biblioteca.caminho + 'input/' + str( numero_identificador) + '-' + template.lower() # remove arquivo se ele existir if os.path.isfile(path_file): os.remove(path_file) observer = Observer() observer.numero_identificador = False observer.src_path = False observer.schedule(MonitorIntegrador(observer), path=self.biblioteca.caminho + 'output') observer.start() xml = render_xml(self._path, template, True, **kwargs) xml.write(path_file, xml_declaration=True, encoding='UTF-8') cont_time = 0 while True: # Analisa a pasta a cada um segundo. # entra10 vezes e sai da verificacao time.sleep(1) cont_time = cont_time + 1 if (str(numero_identificador) == str(observer.numero_identificador) and \ observer.src_path): # Ao encontrar um arquivo de retorno com o mesmo numero identificador da remessa sai do loop. break if cont_time == 10: observer.resposta = str(numero_identificador) + '|' + str( numero_identificador ) + '|' + '0' + '|' + 'Erro interno' + '|' + '0' + '|' + 'ERRO' # Ao nao encontrar um arquivo de retorno com o mesmo numero identificador break observer.stop() observer.join() return observer.resposta