configs.py 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  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. '''
  18. # 创建一个logger
  19. self.logger = logging.getLogger(logger)
  20. self.logger.setLevel(logging.INFO) # DEBUG
  21. # 创建一个handler,用于写入日志文件
  22. # self.log_time = time.strftime("%Y_%m_%d")
  23. # file_dir = os.getcwd() + '/../log'
  24. # if not os.path.exists(file_dir):
  25. # os.mkdir(file_dir)
  26. # self.log_path = file_dir
  27. # self.log_name = self.log_path + "/" + log_cate + "." + self.log_time + '.log'
  28. # self.log_name = os.path.join(log_dir, 'parse_log.log') # 日志地址
  29. self.log_name = os.path.join(parse_log_dir, '{}.log'.format(log_cate)) # 日志地址
  30. # if os.path.exists(self.log_name): # 设置日志定长自动新建
  31. # logsize = os.path.getsize(self.log_name)
  32. # if logsize > 180000000: # 180M
  33. # os.rename(self.log_name, os.path.join(parse_log_dir, '{}_{}.log'.format(log_cate,
  34. # datetime.datetime.now().strftime('%m_%d'))))
  35. fh = logging.FileHandler(self.log_name, mode='a', encoding='utf8', delay=True)
  36. fh = logging.handlers.RotatingFileHandler(self.log_name, maxBytes=150000000, backupCount=3,
  37. mode='a', encoding='utf-8', delay=True)
  38. fh.setLevel(logging.INFO)
  39. # 再创建一个handler,用于输出到控制台
  40. # ch = logging.StreamHandler()
  41. # ch.setLevel(logging.INFO)
  42. # 定义handler的输出格式
  43. # formatter = logging.Formatter(
  44. # '[%(asctime)s] %(filename)s->%(funcName)s line:%(lineno)d [%(levelname)s]%(message)s')
  45. # formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
  46. # formatter = logging.Formatter('{"[%(asctime)s-%(levelname)s-%(filename)s-%(lineno)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 TestingCfg: # testing
  63. internal_ip = '192.168.1.140' # internal
  64. external_ip = '192.168.1.140' # external
  65. server_port = 11066
  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"
  73. raw_img_upload_folder = 'F:/zwj/word_folder'
  74. old_img_ip = "http://192.168.1.140:8800/ser_static"
  75. mathpix_ip = "http://192.168.1.208:8001/segment/formula/"
  76. kps_phy_ip = "http://192.168.1.86:11088/phy_mark_and_connect"
  77. kps_Hmath_ip = "http://192.168.1.192:13356/auto_labels"
  78. repeat_ip = "http://192.168.1.192:8866/api/repeat/subject"
  79. topic_segment_ip = "http://192.168.1.204:10622/math_phy_TopicSegment_predict"
  80. phy_topicType_ip = "http://192.168.1.204:10611/phy_topicType_predict"
  81. # repeaty_ip = "http://82.156.68.22:8888/repeat/subject" # 全学科查重
  82. # repeat_ip = "http://82.156.68.22:8888/api/repeat/subject" # 保存入库查重
  83. # callback_url_taskcheck = "http://zsytk3api.dev.xueping.com/v1/interior-api/record"
  84. callback_url_taskcheck = "http://zsytk3api.testing.xueping.com/v1/interior-api/record"
  85. class ProductionCfg: # production
  86. internal_ip = '0.0.0.0' # internal
  87. external_ip = '82.156.255.225' # external
  88. server_port = 11088
  89. public_bucket = 'zxhx-pro-1302712961' # 桶名称
  90. region = "ap-beijing" # 存储桶地域
  91. public_bucket_addr = 'zxhx-pro-1302712961.cos.ap-beijing.myqcloud.com' # 桶地址
  92. FAIL_FOLDER = "E:/Text_Structure/fail_files"
  93. IMG_FOLDER = "E:/Text_Structure/img_folder"
  94. RES_FOLDER = "E:/Text_Structure/res_folder"
  95. parse_log_dir = "E:/Text_Structure/logs"
  96. raw_img_upload_folder = 'E:/word_uploads'
  97. old_img_ip = "http://82.156.255.225:11086/ser_static"
  98. mathpix_ip = "http://10.19.1.11:7080/segment/formula/"
  99. kps_phy_ip = "http:/49.232.72.198:11088/phy_mark_and_connect"
  100. kps_Hmath_ip = "http://172.16.2.5:13356/auto_labels"
  101. repeat_ip = "http://10.19.1.18:8866/api/repeat/subject"
  102. # topic_segment_ip = "http://10.19.1.14:10622/math_phy_TopicSegment_predict" #CPU
  103. topic_segment_ip = "http://10.19.1.10:10622/math_phy_TopicSegment_predict" #GPU
  104. # topic_segment_ip = "http://49.232.72.198:10622/math_phy_TopicSegment_predict"
  105. phy_topicType_ip = "http://10.19.1.6:10611/phy_topicType_predict"
  106. callback_url_taskcheck = "http://api.tk.zhixinhuixue.com/v1/interior-api/record"
  107. # sys.argv:从控制台窗台运行程序,程序后加参数,以空格隔开,sys.argv[0]即程序本身
  108. config_class = ProductionCfg # 没有参数时,默认按测试环境
  109. if len(sys.argv) > 1:
  110. print(sys.argv, sys.argv[0])
  111. print(sys.argv[1])
  112. if sys.argv[1] == 'test':
  113. config_class = TestingCfg
  114. elif sys.argv[1] == 'product':
  115. config_class = ProductionCfg
  116. else:
  117. print('cmd should be: python server.py test')
  118. print('or: python server.py product')
  119. raise ValueError("命令不正确")
  120. server_ip = config_class.internal_ip
  121. external_ip = config_class.external_ip
  122. server_port = config_class.server_port
  123. public_bucket_addr = config_class.public_bucket_addr
  124. public_bucket = config_class.public_bucket
  125. region = config_class.region
  126. parse_log_dir = config_class.parse_log_dir
  127. # 定义结构化失败文件保存路径
  128. FAIL_FOLDER = config_class.FAIL_FOLDER
  129. if not os.path.isdir(FAIL_FOLDER):
  130. os.makedirs(FAIL_FOLDER)
  131. # 定义再结构化文件中新图片(base64)的保存路径及访问目录
  132. IMG_FOLDER = config_class.IMG_FOLDER
  133. if not os.path.isdir(IMG_FOLDER):
  134. os.makedirs(IMG_FOLDER)
  135. # 回调结果保存路径
  136. RES_FOLDER = config_class.RES_FOLDER
  137. if not os.path.isdir(RES_FOLDER):
  138. os.makedirs(RES_FOLDER)
  139. new_img_ip = "http://{0}:{1}/ser_static".format(external_ip, server_port)
  140. old_img_ip = config_class.old_img_ip
  141. RawImg_UploadFolder = config_class.raw_img_upload_folder
  142. mathpix_ip = config_class.mathpix_ip
  143. kps_phy_ip = config_class.kps_phy_ip
  144. kps_Hmath_ip = config_class.kps_Hmath_ip
  145. callback_url_taskcheck = config_class.callback_url_taskcheck
  146. repeat_ip = config_class.repeat_ip
  147. topic_segment_ip = config_class.topic_segment_ip
  148. phy_topicType_ip = config_class.phy_topicType_ip
  149. # 注意:
  150. # 单题解析中,线上css_conflict_deal与线下不一样
  151. # 作答类型
  152. answer_type = {"选择题": 1, "填空题": 2, "解答题": 3, "判断题": 4,
  153. "英语作文": 5, "语文作文": 6}