Repository for M.A.I.L system's recording client.
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

main.py 5.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. import tkinter
  2. import json
  3. import paramiko
  4. import time
  5. from tkinter import messagebox
  6. import os
  7. from paramiko import file
  8. window = tkinter.Tk()
  9. settings =[]
  10. customer_code = ''
  11. surgery_date = str(time.strftime('%Y%m%d', time.localtime(time.time())))
  12. with open('./settings.json', encoding='utf-8')as json_file:
  13. json_data = json.load(json_file)
  14. settings.append(json_data['window_name'])
  15. settings.append(json_data['window_position'])
  16. settings.append(json_data['branch_location'])
  17. settings.append(json_data['surgery_room_number'])
  18. settings.append(json_data['ddns'])
  19. settings.append(json_data['account']) #settings[5]
  20. settings.append(json_data['password']) #settings[6]
  21. window.title(settings[0])
  22. window.geometry(settings[1])
  23. window.resizable(False,False)
  24. def sshConnect(cs, sd):
  25. cs = cs
  26. sd = sd
  27. filepath = './log.txt'
  28. ssh = paramiko.SSHClient()
  29. ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
  30. ssh.connect(settings[4],port= settings[3], username=settings[5], password=settings[6])
  31. data_root_dir = './data/'+cs+sd
  32. stdin, stdout, stderr = ssh.exec_command('mkdir ' + data_root_dir)
  33. #TODO: 여기에 도커 명령어 및 동시 녹화 코드 입력
  34. 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')
  35. f = open(filepath, 'w')
  36. r_time = time.ctime(time.time())
  37. f.write('record succesfully started at ' + str(r_time) + '\n')
  38. f.close()
  39. def sshQuit(cs, sd):
  40. cs = cs
  41. sd = sd
  42. filepath = './log.txt'
  43. data_root_dir = './data/'+cs+sd
  44. f = open(filepath, 'a')
  45. r_time = time.ctime(time.time())
  46. f.write('record succesfully stopped at ' + str(r_time)+ '\n')
  47. f.close()
  48. transport = paramiko.Transport((settings[4], settings[3]))
  49. transport.connect(username=settings[5], password=settings[6])
  50. sftp = paramiko.SFTPClient.from_transport(transport)
  51. sftp.put(filepath, data_root_dir + filepath[1:])
  52. sftp.close()
  53. transport.close()
  54. os.remove(filepath)
  55. ssh = paramiko.SSHClient()
  56. ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
  57. ssh.connect(settings[4],port= settings[3], username=settings[5], password=settings[6])
  58. stdin, stdout, stderr = ssh.exec_command('docker stop mail_recorder')
  59. time.sleep(10)
  60. stdin, stdout, stderr = ssh.exec_command('mv ' + data_root_dir + ' /hdd/')
  61. label_branch = tkinter.Label(window, text = '지점 위치: ' + settings[2] + ' / 수술방 번호: ' + str(settings[3]))
  62. label_customer_code = tkinter.Label(window, text="고객번호(지점 번호 포함 9자리)")
  63. def dummyexit():
  64. pass
  65. def askInformation(customer_code,surgery_date):
  66. cs = customer_code
  67. sd = surgery_date
  68. if len(cs) != 9:
  69. err_box = messagebox.showerror("고객 번호 오류", '지점 번호를 포함한 9자리를 입력해주세요.')
  70. else:
  71. msg_box = messagebox.askquestion("입력 정보 확인", "입력하신 정보가 정확한지 확인해주세요.\n고객 번호: "+customer_code + '\n 수술일자: ' + surgery_date +'\n\nYes를 눌러 기록 시작을,\n입력 정보의 수정을 원하시면 No을 눌러 변경해주세요.')
  72. #TODO: try: 형태로 고칠 것. Err 메세지도 종류 정할 것
  73. if msg_box == 'yes':
  74. err_status = True
  75. if err_status == False:
  76. label_recording = tkinter.Label(window, text='분석 PC에 문제가 발생하였습니다.\nHOBIT LAB으로 연락 부탁드립니다.\n내선번호: 1237 \n에러 코드: REQUEST TIME OUT')
  77. label_recording.pack()
  78. else:
  79. #TODO: paramiko로 ssh 접속 후 도커 명령어 보낼 것
  80. sshConnect(cs, sd)
  81. button_confirm['text'] = '기록 종료'
  82. window.protocol('WM_DELETE_WINDOW', dummyexit)
  83. label_recording = tkinter.Label(window, text='MAIL system에 수술을 기록 중입니다.\n기록 중단을 원할 시 \n기록 종료 버튼을 눌러주세요.')
  84. label_recording.pack()
  85. def askQuit(cn, sd):
  86. customer_number = cn
  87. surgery_date = sd
  88. msg_box = messagebox.askquestion("기록 중지 확인", '기록을 중지하시겠습니까?')
  89. if msg_box == 'yes':
  90. #TODO: docker 중지 명령어 보내기
  91. sshQuit(customer_number, surgery_date)
  92. window.destroy()
  93. def buttonAction(event):
  94. customer_code = str(entry_customer_code.get())
  95. if button_confirm['text'] == '입력완료':
  96. askInformation(customer_code, surgery_date)
  97. else:
  98. askQuit(customer_code,surgery_date)
  99. # def fillSurgeryDate():
  100. entry_customer_code = tkinter.Entry(window)
  101. entry_surgery_date = tkinter.Entry(window)
  102. button_confirm = tkinter.Button(window, text="입력완료", width=20, height=2)
  103. button_confirm.bind("<Button-1>", buttonAction)
  104. label_branch.pack()
  105. label_customer_code.pack()
  106. entry_customer_code.pack()
  107. button_confirm.pack()
  108. window.mainloop()