Repository for M.A.I.L system's recording client.
Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. import subprocess
  2. import tkinter
  3. import json
  4. import paramiko
  5. import time
  6. from datetime import datetime
  7. from tkinter import messagebox
  8. import os
  9. import git
  10. from paramiko import file
  11. import pymssql
  12. window = tkinter.Tk()
  13. settings =[]
  14. customer_code = ''
  15. surgery_date = str(time.strftime('%Y%m%d', time.localtime(time.time())))
  16. cnxn = pymssql.connect('52.231.39.219' , 'mc365', 'tkadbrdhmc1!', 'tsfmc_data')
  17. cursor = cnxn.cursor()
  18. with open('./settings.json', encoding='utf-8')as json_file:
  19. json_data = json.load(json_file)
  20. settings.append(json_data['window_name'])
  21. settings.append(json_data['window_position'])
  22. settings.append(json_data['branch_location'])
  23. settings.append(json_data['surgery_room_number'])
  24. settings.append(json_data['ddns'])
  25. settings.append(json_data['account']) #settings[5]
  26. settings.append(json_data['password']) #settings[6]
  27. window.title(settings[0])
  28. window.geometry(settings[1])
  29. window.resizable(False,False)
  30. def sshConnect(cs, sd):
  31. cs = cs
  32. sd = sd
  33. filepath = './log.txt'
  34. ssh = paramiko.SSHClient()
  35. ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
  36. ssh.connect(settings[4],port= settings[3], username=settings[5], password=settings[6])
  37. data_root_dir = './data/'+cs+sd
  38. stdin, stdout, stderr = ssh.exec_command('mkdir ' + data_root_dir)
  39. #TODO: 여기에 도커 명령어 및 동시 녹화 코드 입력
  40. cmd = 'python3 /home/mc365/sources/rec_ubuntu.py'
  41. stdin, stdout, stderr = ssh.exec_command(cmd)
  42. f = open(filepath, 'w')
  43. r_time = time.ctime(time.time())
  44. f.write('record succesfully started at ' + str(r_time) + '\n')
  45. f.close()
  46. def sshQuit(cs, sd):
  47. cs = cs
  48. sd = sd
  49. filepath = './log.txt'
  50. data_root_dir = './data/'+cs+sd
  51. f = open(filepath, 'a')
  52. r_time = time.ctime(time.time())
  53. f.write('record succesfully stopped at ' + str(r_time)+ '\n')
  54. f.close()
  55. transport = paramiko.Transport((settings[4], settings[3]))
  56. transport.connect(username=settings[5], password=settings[6])
  57. sftp = paramiko.SFTPClient.from_transport(transport)
  58. sftp.put(filepath, data_root_dir + filepath[1:])
  59. sftp.close()
  60. transport.close()
  61. os.remove(filepath)
  62. ssh = paramiko.SSHClient()
  63. ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
  64. ssh.connect(settings[4],port= settings[3], username=settings[5], password=settings[6])
  65. t = ssh.get_transport()
  66. c = t.open_session()
  67. c.exec_command('docker stop mail_recorder && mv ' + data_root_dir + ' /hdd/')
  68. label_branch = tkinter.Label(window, text = '지점 위치: ' + settings[2] + ' / 수술방 번호: ' + str(settings[3]))
  69. label_customer_code = tkinter.Label(window, text="고객번호(지점 번호 포함 9자리)")
  70. def dummyexit():
  71. pass
  72. def askInformation(customer_code,surgery_date, customer_name):
  73. cs = customer_code
  74. sd = surgery_date
  75. global pk
  76. pk = cs + sd
  77. if len(cs) != 9:
  78. err_box = messagebox.showerror("고객 번호 오류", '지점 번호를 포함한 9자리를 입력해주세요.')
  79. else:
  80. msg_box = messagebox.askquestion("입력 정보 확인", "\n고객 이름 : " + customer_name + "\n\n고객 번호 : " + customer_code + '\n\n맞으면 Yes를 눌러 기록시작을,\n 틀리면 No를 눌러 수정해주세요.')
  81. #TODO: try: 형태로 고칠 것. Err 메세지도 종류 정할 것
  82. if msg_box == 'yes':
  83. global start_time
  84. start_time = datetime.now().strftime('%Y-%m-%d %H:%M:%S')
  85. err_status = True
  86. if err_status == False:
  87. label_recording = tkinter.Label(window, text='분석 PC에 문제가 발생하였습니다.\nHOBIT LAB으로 연락 부탁드립니다.\n내선번호: 1103 \n에러 코드: REQUEST TIME OUT')
  88. label_recording.pack()
  89. else:
  90. #TODO: paramiko로 ssh 접속 후 도커 명령어 보낼 것
  91. sshConnect(cs, sd)
  92. button_confirm['text'] = '기록 종료'
  93. window.protocol('WM_DELETE_WINDOW', dummyexit)
  94. label_recording = tkinter.Label(window, text='MAIL system에 수술을 기록 중입니다.\n기록 중단을 원할 시 \n기록 종료 버튼을 눌러주세요.')
  95. label_recording.pack()
  96. def askQuit(cn, sd):
  97. customer_number = cn
  98. surgery_date = sd
  99. msg_box = messagebox.askquestion("기록 중지 확인", '기록을 중지하시겠습니까?')
  100. if msg_box == 'yes':
  101. end_time = datetime.now().strftime('%Y-%m-%d %H:%M:%S')
  102. # print(str(end_time))
  103. data = [(pk, json_data['branch_location'], json_data['surgery_room_number'], str(start_time), str(end_time))]
  104. cursor.executemany("INSERT into tsfmc_mailsystem.dbo.MAIL_SURGERYCOUNT values ( %s, %s, %d, %s, %s)", data)
  105. cnxn.commit()
  106. #TODO: docker 중지 명령어 보내기
  107. sshQuit(customer_number, surgery_date)
  108. window.destroy()
  109. def buttonAction(event):
  110. customer_code = str(entry_customer_code.get())
  111. cursor.execute("SELECT PSNAME FROM ADM010T WHERE PSENTRY='{}';".format(customer_code) )
  112. customer_name = cursor.fetchone()[0]
  113. if button_confirm['text'] == '입력완료':
  114. askInformation(customer_code, surgery_date, customer_name)
  115. else:
  116. askQuit(customer_code,surgery_date)
  117. # def fillSurgeryDate():
  118. entry_customer_code = tkinter.Entry(window)
  119. entry_surgery_date = tkinter.Entry(window)
  120. button_confirm = tkinter.Button(window, text="입력완료", width=20, height=2)
  121. button_confirm.bind("<Button-1>", buttonAction)
  122. label_branch.pack()
  123. label_customer_code.pack()
  124. entry_customer_code.pack()
  125. button_confirm.pack()
  126. if __name__ == "__main__":
  127. check_git = subprocess.Popen(['git','merge','origin/alpha'], stdout=subprocess.PIPE, universal_newlines=True)
  128. stdout, stderr = check_git.communicate()
  129. if (stdout != "Already up to date.\n"):
  130. print('stdout not match')
  131. messagebox.showinfo("365mc MAIL System","프로그램이 업데이트되었습니다. 프로그램을 재시작해주세요.")
  132. pass
  133. else:
  134. window.mainloop()