import tkinter import json import paramiko import time from tkinter import messagebox import os from paramiko import file window = tkinter.Tk() settings =[] customer_code = '' surgery_date = str(time.strftime('%Y%m%d', time.localtime(time.time()))) with open('./settings.json', encoding='utf-8')as json_file: json_data = json.load(json_file) settings.append(json_data['window_name']) settings.append(json_data['window_position']) settings.append(json_data['branch_location']) settings.append(json_data['surgery_room_number']) settings.append(json_data['ddns']) settings.append(json_data['account']) #settings[5] settings.append(json_data['password']) #settings[6] window.title(settings[0]) window.geometry(settings[1]) window.resizable(False,False) def sshConnect(cs, sd): cs = cs sd = sd filepath = './log.txt' ssh = paramiko.SSHClient() ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy()) ssh.connect(settings[4],port= settings[3], username=settings[5], password=settings[6]) data_root_dir = './data/'+cs+sd stdin, stdout, stderr = ssh.exec_command('mkdir ' + data_root_dir) #TODO: 여기에 도커 명령어 및 동시 녹화 코드 입력 stdin, stdout, stderr = ssh.exec_command('docker run --rm --name mail_recorder --gpus 1 --privileged -v /dev:/dev -v /home/mc365/sources:/sources -v /home/mc365/data/'+cs+sd+':/data/'+cs+sd+' stereolabs/zed:3.5-gl-devel-cuda11.1-ubuntu18.04 python3 /sources/recorder.py') f = open(filepath, 'w') r_time = time.ctime(time.time()) f.write('record succesfully started at ' + str(r_time) + '\n') f.close() def sshQuit(cs, sd): cs = cs sd = sd filepath = './log.txt' data_root_dir = './data/'+cs+sd f = open(filepath, 'a') r_time = time.ctime(time.time()) f.write('record succesfully stopped at ' + str(r_time)+ '\n') f.close() transport = paramiko.Transport((settings[4], settings[3])) transport.connect(username=settings[5], password=settings[6]) sftp = paramiko.SFTPClient.from_transport(transport) sftp.put(filepath, data_root_dir + filepath[1:]) sftp.close() transport.close() os.remove(filepath) ssh = paramiko.SSHClient() ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy()) ssh.connect(settings[4],port= settings[3], username=settings[5], password=settings[6]) stdin, stdout, stderr = ssh.exec_command('docker stop mail_recorder') time.sleep(10) stdin, stdout, stderr = ssh.exec_command('mv ' + data_root_dir + ' /hdd/') label_branch = tkinter.Label(window, text = '지점 위치: ' + settings[2] + ' / 수술방 번호: ' + str(settings[3])) label_customer_code = tkinter.Label(window, text="고객번호(지점 번호 포함 9자리)") def dummyexit(): pass def askInformation(customer_code,surgery_date): cs = customer_code sd = surgery_date if len(cs) != 9: err_box = messagebox.showerror("고객 번호 오류", '지점 번호를 포함한 9자리를 입력해주세요.') else: msg_box = messagebox.askquestion("입력 정보 확인", "입력하신 정보가 정확한지 확인해주세요.\n고객 번호: "+customer_code + '\n 수술일자: ' + surgery_date +'\n\nYes를 눌러 기록 시작을,\n입력 정보의 수정을 원하시면 No을 눌러 변경해주세요.') #TODO: try: 형태로 고칠 것. Err 메세지도 종류 정할 것 if msg_box == 'yes': err_status = True if err_status == False: label_recording = tkinter.Label(window, text='분석 PC에 문제가 발생하였습니다.\nHOBIT LAB으로 연락 부탁드립니다.\n내선번호: 1237 \n에러 코드: REQUEST TIME OUT') label_recording.pack() else: #TODO: paramiko로 ssh 접속 후 도커 명령어 보낼 것 sshConnect(cs, sd) button_confirm['text'] = '기록 종료' window.protocol('WM_DELETE_WINDOW', dummyexit) label_recording = tkinter.Label(window, text='MAIL system에 수술을 기록 중입니다.\n기록 중단을 원할 시 \n기록 종료 버튼을 눌러주세요.') label_recording.pack() def askQuit(cn, sd): customer_number = cn surgery_date = sd msg_box = messagebox.askquestion("기록 중지 확인", '기록을 중지하시겠습니까?') if msg_box == 'yes': #TODO: docker 중지 명령어 보내기 sshQuit(customer_number, surgery_date) window.destroy() def buttonAction(event): customer_code = str(entry_customer_code.get()) if button_confirm['text'] == '입력완료': askInformation(customer_code, surgery_date) else: askQuit(customer_code,surgery_date) # def fillSurgeryDate(): entry_customer_code = tkinter.Entry(window) entry_surgery_date = tkinter.Entry(window) button_confirm = tkinter.Button(window, text="입력완료", width=20, height=2) button_confirm.bind("", buttonAction) label_branch.pack() label_customer_code.pack() entry_customer_code.pack() button_confirm.pack() window.mainloop()