def upgrade(pckg: str, dutl: int, ntry: int = 0) -> bool: if ntry == 0: print('Upgrading', pckg) try: subproc(pip('install', '-U', pckg), check=True) return True except CalledProcessError: return False if ntry == dutl else upgrade(pckg, dutl, ntry + 1)
def send_images(self): ## Send images command = '../../bash/wait_and_list_images.sh ' + self.cach_path simulation_process = subproc(command, stdout=PIPE, shell=True) out, err = simulation_process.communicate() simulation_process.terminate() images_str = out.decode() images_list = images_str.split(',') print(images_list) #### for image in images_list[1:]: print("Enviando nombre de la imagen") image_name = image[:-4] + '\n' image_name = image_name.encode('utf-8') self.socket.send(image_name) print("Recibiendo la confirmación del usuario") print(self.socket.recv(512).decode()) with open(self.cach_path + '/' + image, "rb") as imageFile: image_hex = imageFile.read() self.socket.sendall(image_hex) self.socket.send("END".encode('utf-8'))
def send_model_comparison(self): ## Send model simulation command = '../../bash/wait_and_send_model_comparison.sh ' + self.cach_path simulation_process = subproc(command, stdout=PIPE, shell=True) out, err = simulation_process.communicate() simulation_process.terminate() result = out.decode() + "\nEOF\n" ## Receive client ack self.socket.sendall(result.encode('utf-8')) print(self.socket.recv(512).decode('utf-8'))
def send_simulation_vectors(self): ## Send images command = '../../bash/wait_and_send_vectors.sh ' + self.cach_path simulation_process = subproc(command, stdout=PIPE, shell=True) out, err = simulation_process.communicate() simulation_process.terminate() vectors_str = out.decode() + "\nEOF\n" ## Receive client ack self.socket.sendall(vectors_str.encode('utf-8')) print(self.socket.recv(512).decode('utf-8'))
def send_error_indexes(self): ## Wait for file command = '../../bash/wait_error_indexes.sh ' + self.cach_path simulation_process = subproc(command, stdout=PIPE, shell=True) out, err = simulation_process.communicate() simulation_process.terminate() ## Open error indexes file file_path = self.cach_path + "/error_indexes.txt" results_file = open(file_path) results_file = ''.join(results_file.readlines()) ## Send file content self.socket.send(results_file.encode('utf-8')) ## Read client ack response print(self.socket.recv(512).decode('utf-8'))
def compute_controller_params_and_simulations(self): # Send tuning results ## Ejecutar el subprocess if self.model_flags['type'] == 'model_fotf': command = '../../bash/compute_request.sh '\ +self.model_flags['output_format']+' '+self.model_str elif self.model_flags['type'] == 'model_file': command = '../../bash/compute_request.sh '\ +self.model_flags['output_format']+' << EOF\n'\ +self.step_response+'\nEOF\n' else: pass tuning_process = subproc(command, stdout=PIPE, shell=True) out, err = tuning_process.communicate() tuning_process.terminate() self.cach_path = out.decode().split('\n')[0] print(self.cach_path)
def get_outdated_pckgs() -> List[str]: res = subproc(pip('list', '-o'), capture_output=True, text=True) return [line.split(' ')[0] for line in res.stdout.split('\n')[2:]]