configs.py 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. #!/usr/bin/env/python
  2. # -*- coding:utf-8 -*-
  3. import logging
  4. import time
  5. import os
  6. import sys
  7. import datetime
  8. class myLog(object):
  9. """
  10. 封装后的logging
  11. """
  12. def __init__(self, logger=None, log_cate='my_log'):
  13. """
  14. 指定保存日志的文件路径,日志级别,以及调用文件
  15. 将日志存入到指定的文件中
  16. :param logger:
  17. :param log_cate: 日志名
  18. """
  19. # 创建一个logger
  20. self.logger = logging.getLogger(logger)
  21. self.logger.setLevel(logging.INFO) # DEBUG
  22. # 创建一个handler,用于写入日志文件
  23. # self.log_time = time.strftime("%Y_%m_%d")
  24. # file_dir = os.getcwd() + '/../log'
  25. # if not os.path.exists(file_dir):
  26. # os.mkdir(file_dir)
  27. # self.log_path = file_dir
  28. # self.log_name = self.log_path + "/" + log_cate + "." + self.log_time + '.log'
  29. # self.log_name = os.path.join(log_dir, 'parse_log.log') # 日志地址
  30. self.log_name = os.path.join(parse_log_dir, '{}.log'.format(log_cate)) # 日志地址
  31. if os.path.exists(self.log_name): # 设置日志定长自动新建
  32. logsize = os.path.getsize(self.log_name)
  33. if logsize > 180000000: # 180M
  34. os.rename(self.log_name, os.path.join(parse_log_dir, '{}_{}.log'.format(log_cate,
  35. datetime.datetime.now().strftime('%m_%d'))))
  36. # fh = logging.FileHandler(self.log_name, 'a') # 追加模式 这个是python2的
  37. fh = logging.FileHandler(self.log_name, mode='a', encoding='utf-8', delay=True)
  38. # fh = logging.FileHandler(self.log_name, 'a', encoding='utf-8') # 这个是python3的
  39. fh.setLevel(logging.INFO)
  40. # 再创建一个handler,用于输出到控制台
  41. # ch = logging.StreamHandler()
  42. # ch.setLevel(logging.INFO)
  43. # 定义handler的输出格式
  44. # formatter = logging.Formatter(
  45. # '[%(asctime)s] %(filename)s->%(funcName)s line:%(lineno)d [%(levelname)s]%(message)s')
  46. # formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
  47. formatter = logging.Formatter('{"host-ip": ' + '"{}"'.format(external_ip)
  48. + ', "log-msg": %(message)s, "other-msg": "%(filename)s-%(lineno)s-%(asctime)s"}')
  49. fh.setFormatter(formatter)
  50. # ch.setFormatter(formatter)
  51. # 给logger添加handler
  52. self.logger.addHandler(fh)
  53. # self.logger.addHandler(ch)
  54. # 添加下面一句,在记录日志之后移除句柄
  55. # self.logger.removeHandler(ch)
  56. # self.logger.removeHandler(fh)
  57. # 关闭打开的文件
  58. fh.close()
  59. # ch.close()
  60. def getlog(self):
  61. return self.logger
  62. class TestingCfg140: # testing
  63. internal_ip = '192.168.1.140' # internal
  64. external_ip = '192.168.1.140' # external
  65. server_port = 11068
  66. public_bucket = 'zxhx-1302712961' # 桶名称
  67. region = "ap-shanghai" # 存储桶地域
  68. public_bucket_addr = 'zxhx-1302712961.cos.ap-shanghai.myqcloud.com'
  69. FAIL_FOLDER = "F:/zwj/Text_Structure/fail_files"
  70. IMG_FOLDER = "F:/zwj/Text_Structure/img_folder"
  71. RES_FOLDER = "F:/zwj/Text_Structure/res_folder"
  72. parse_log_dir = "F:/zwj/Text_Structure/logs_art"
  73. accept_files_dir = "F:/zwj/Text_Structure/accept_files"
  74. raw_img_upload_folder = 'F:/zwj/word_folder'
  75. old_img_ip = "http://192.168.1.140:8800/ser_static"
  76. mathpix_ip = "http://192.168.1.208:8001/segment/formula/"
  77. kps_phy_ip = "http://192.168.1.86:11088/phy_mark_and_connect"
  78. repeat_ip = "http://192.168.1.192:8866/api/repeat/subject"
  79. # callback_url_taskcheck = "http://zsytk3api.testing.xueping.com/v1/interior-api/record"
  80. callback_url_taskcheck = "http://zsytk3api.dev.xueping.com/v1/interior-api/record"
  81. class TestingCfg: # testing
  82. internal_ip = '192.168.1.65' # internal
  83. external_ip = '192.168.1.65' # external
  84. server_port = 11068
  85. public_bucket = 'zxhx-1302712961' # 桶名称
  86. region = "ap-shanghai" # 存储桶地域
  87. public_bucket_addr = 'zxhx-1302712961.cos.ap-shanghai.myqcloud.com'
  88. FAIL_FOLDER = "G:/zwj/WL/Text_Structure/fail_files"
  89. IMG_FOLDER = "G:/zwj/WL/Text_Structure/img_folder"
  90. RES_FOLDER = "G:/zwj/WL/Text_Structure/res_folder"
  91. parse_log_dir = "G:/zwj/WL/Text_Structure/logs_art"
  92. accept_files_dir = "G:/zwj/WL/Text_Structure/accept_files"
  93. raw_img_upload_folder = 'G:/zwj/WL/word_folder'
  94. old_img_ip = "http://192.168.1.140:8800/ser_static"
  95. mathpix_ip = "http://192.168.1.208:8001/segment/formula/"
  96. kps_phy_ip = "http://192.168.1.86:11088/phy_mark_and_connect"
  97. repeat_ip = "http://192.168.1.192:8866/api/repeat/subject"
  98. # callback_url_taskcheck = "http://zsytk3api.testing.xueping.com/v1/interior-api/record"
  99. callback_url_taskcheck = "http://zsytk3api.dev.xueping.com/v1/interior-api/record"
  100. class ProductionCfg: # production
  101. internal_ip = '0.0.0.0' # internal
  102. external_ip = '82.156.255.225' # external
  103. server_port = 11088
  104. public_bucket = 'zxhx-pro-1302712961' # 桶名称
  105. region = "ap-beijing" # 存储桶地域
  106. public_bucket_addr = 'zxhx-pro-1302712961.cos.ap-beijing.myqcloud.com' # 桶地址
  107. FAIL_FOLDER = "E:/Text_Structure/fail_files"
  108. IMG_FOLDER = "E:/Text_Structure/img_folder"
  109. RES_FOLDER = "E:/Text_Structure/res_folder"
  110. parse_log_dir = "E:/Text_Structure/logs_art"
  111. accept_files_dir = "E:/Text_Structure/accept_files"
  112. raw_img_upload_folder = 'E:/new_word_parse_2021/word_uploads'
  113. old_img_ip = "http://82.156.255.225:11086/ser_static"
  114. mathpix_ip = "http://10.19.1.11:7080/segment/formula/"
  115. kps_phy_ip = "http:/49.232.72.198:11088/phy_mark_and_connect"
  116. repeat_ip = "http://10.19.1.18:8866/api/repeat/subject"
  117. callback_url_taskcheck = "http://api.tk.zhixinhuixue.com/v1/interior-api/record"
  118. class ProductionCfg175: # production
  119. internal_ip = '0.0.0.0' # internal
  120. external_ip = '82.156.91.175' # external
  121. server_port = 11088
  122. public_bucket = 'zxhx-pro-1302712961' # 桶名称
  123. region = "ap-beijing" # 存储桶地域
  124. public_bucket_addr = 'zxhx-pro-1302712961.cos.ap-beijing.myqcloud.com' # 桶地址
  125. FAIL_FOLDER = "E:/zwj/Text_Structure/fail_files"
  126. IMG_FOLDER = "E:/zwj/Text_Structure/img_folder"
  127. RES_FOLDER = "E:/zwj/Text_Structure/res_folder"
  128. parse_log_dir = "E:/zwj/Text_Structure/logs"
  129. accept_files_dir = "E:/zwj/Text_Structure/accept_files"
  130. raw_img_upload_folder = 'E:/zwj/new_word_parse_2021/word_uploads'
  131. old_img_ip = "http://82.156.255.225:11086/ser_static"
  132. mathpix_ip = "http://10.19.1.11:7080/segment/formula/"
  133. kps_phy_ip = "http:/49.232.72.198:11088/phy_mark_and_connect"
  134. repeat_ip = "http://10.19.1.18:8866/api/repeat/subject"
  135. callback_url_taskcheck = "http://api.tk.zhixinhuixue.com/v1/interior-api/record"
  136. # sys.argv:从控制台窗台运行程序,程序后加参数,以空格隔开,sys.argv[0]即程序本身
  137. config_class = TestingCfg140 # 没有参数时,默认按测试环境
  138. if len(sys.argv) > 1:
  139. print(sys.argv, sys.argv[0])
  140. if sys.argv[1] == 'test':
  141. config_class = TestingCfg
  142. elif sys.argv[1] == 'product':
  143. config_class = ProductionCfg
  144. if sys.argv[-1] == '175':
  145. config_class = ProductionCfg175
  146. else:
  147. print('cmd should be: python server.py test')
  148. print('or: python server.py product')
  149. raise ValueError("命令不正确")
  150. server_ip = config_class.internal_ip
  151. external_ip = config_class.external_ip
  152. server_port = config_class.server_port
  153. public_bucket_addr = config_class.public_bucket_addr
  154. public_bucket = config_class.public_bucket
  155. region = config_class.region
  156. parse_log_dir = config_class.parse_log_dir
  157. if not os.path.isdir(parse_log_dir):
  158. os.makedirs(parse_log_dir)
  159. # 定义结构化失败文件保存路径
  160. FAIL_FOLDER = config_class.FAIL_FOLDER
  161. if not os.path.isdir(FAIL_FOLDER):
  162. os.makedirs(FAIL_FOLDER)
  163. # 定义再结构化文件中新图片(base64)的保存路径及访问目录
  164. IMG_FOLDER = config_class.IMG_FOLDER
  165. if not os.path.isdir(IMG_FOLDER):
  166. os.makedirs(IMG_FOLDER)
  167. # 回调结果保存路径
  168. RES_FOLDER = config_class.RES_FOLDER
  169. if not os.path.isdir(RES_FOLDER):
  170. os.makedirs(RES_FOLDER)
  171. # 接收文件保存路径
  172. accept_files_dir = config_class.accept_files_dir
  173. if not os.path.isdir(accept_files_dir):
  174. os.makedirs(accept_files_dir)
  175. new_img_ip = "http://{0}:{1}/ser_static".format(external_ip, server_port)
  176. old_img_ip = config_class.old_img_ip
  177. RawImg_UploadFolder = config_class.raw_img_upload_folder
  178. mathpix_ip = config_class.mathpix_ip
  179. callback_url_taskcheck = config_class.callback_url_taskcheck
  180. kps_phy_ip = config_class.kps_phy_ip
  181. repeat_ip = config_class.repeat_ip
  182. # 作答类型
  183. answer_type = {"选择题": 1, "填空题": 2, "解答题": 3, "判断题": 4,
  184. "英语作文": 5, "语文作文": 6}