configs.py 8.8 KB

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