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

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