configs.py 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. #!/usr/bin/env/python
  2. # -*- coding:utf-8 -*-
  3. import logging
  4. import time
  5. import os
  6. import sys
  7. # 日志路径
  8. # log_dir = os.getcwd() + '\logs'
  9. # if not os.path.exists(log_dir):
  10. # os.mkdir(log_dir)
  11. class myLog(object):
  12. '''
  13. 封装后的logging
  14. '''
  15. def __init__(self, logger=None, log_cate='my_log'):
  16. '''
  17. 指定保存日志的文件路径,日志级别,以及调用文件
  18. 将日志存入到指定的文件中
  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. # print(self.log_name)
  33. # fh = logging.FileHandler(self.log_name, 'a') # 追加模式 这个是python2的
  34. fh = logging.FileHandler(self.log_name, mode='a', encoding='utf-8', delay=True)
  35. # fh = logging.FileHandler(self.log_name, 'a', encoding='utf-8') # 这个是python3的
  36. fh.setLevel(logging.INFO)
  37. # 再创建一个handler,用于输出到控制台
  38. # ch = logging.StreamHandler()
  39. # ch.setLevel(logging.INFO)
  40. # 定义handler的输出格式
  41. # formatter = logging.Formatter(
  42. # '[%(asctime)s] %(filename)s->%(funcName)s line:%(lineno)d [%(levelname)s]%(message)s')
  43. formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
  44. fh.setFormatter(formatter)
  45. # ch.setFormatter(formatter)
  46. # 给logger添加handler
  47. self.logger.addHandler(fh)
  48. # self.logger.addHandler(ch)
  49. # 添加下面一句,在记录日志之后移除句柄
  50. # self.logger.removeHandler(ch)
  51. # self.logger.removeHandler(fh)
  52. # 关闭打开的文件
  53. fh.close()
  54. # ch.close()
  55. def getlog(self):
  56. return self.logger
  57. class TestingCfg: # testing
  58. internal_ip = '192.168.1.140' # internal
  59. external_ip = '192.168.1.140' # external
  60. server_port = 11066
  61. public_bucket = 'zxhx-1302712961' # 桶名称
  62. region = "ap-shanghai" # 存储桶地域
  63. public_bucket_addr = 'zxhx-1302712961.cos.ap-shanghai.myqcloud.com'
  64. FAIL_FOLDER = "F:/zwj/Text_Structure/fail_files"
  65. IMG_FOLDER = "F:/zwj/Text_Structure/img_folder"
  66. RES_FOLDER = "F:/zwj/Text_Structure/res_folder"
  67. parse_log_dir = "F:/zwj/Text_Structure/logs"
  68. raw_img_upload_folder = 'F:/zwj/word_folder'
  69. old_img_ip = "http://192.168.1.140:8800/ser_static"
  70. mathpix_ip = "http://192.168.1.208:8001/segment/formula/"
  71. class ProductionCfg: # production
  72. internal_ip = '0.0.0.0' # internal
  73. external_ip = '82.156.255.225' # external
  74. server_port = 11088
  75. public_bucket = 'zxhx-pro-1302712961' # 桶名称
  76. region = "ap-beijing" # 存储桶地域
  77. public_bucket_addr = 'zxhx-pro-1302712961.cos.ap-beijing.myqcloud.com' # 桶地址
  78. FAIL_FOLDER = "E:/Text_Structure/fail_files"
  79. IMG_FOLDER = "E:/Text_Structure/img_folder"
  80. RES_FOLDER = "E:/Text_Structure/res_folder"
  81. parse_log_dir = "E:/Text_Structure/logs"
  82. raw_img_upload_folder = 'E:/new_word_parse_2021/word_uploads'
  83. old_img_ip = "http://82.156.255.225:11086/ser_static"
  84. mathpix_ip = "http://10.19.1.11:7080/segment/formula/"
  85. # sys.argv:从控制台窗台运行程序,程序后加参数,以空格隔开,sys.argv[0]即程序本身
  86. config_class = TestingCfg # 没有参数时,默认按测试环境
  87. if len(sys.argv) > 1:
  88. print(sys.argv, sys.argv[0])
  89. print(sys.argv[1])
  90. if sys.argv[1] == 'test':
  91. config_class = TestingCfg
  92. elif sys.argv[1] == 'product':
  93. config_class = ProductionCfg
  94. else:
  95. print('cmd should be: python server.py test')
  96. print('or: python server.py product')
  97. raise ValueError("命令不正确")
  98. server_ip = config_class.internal_ip
  99. external_ip = config_class.external_ip
  100. server_port = config_class.server_port
  101. public_bucket_addr = config_class.public_bucket_addr
  102. public_bucket = config_class.public_bucket
  103. region = config_class.region
  104. parse_log_dir = config_class.parse_log_dir
  105. # 定义结构化失败文件保存路径
  106. FAIL_FOLDER = config_class.FAIL_FOLDER
  107. if not os.path.isdir(FAIL_FOLDER):
  108. os.makedirs(FAIL_FOLDER)
  109. # 定义再结构化文件中新图片(base64)的保存路径及访问目录
  110. IMG_FOLDER = config_class.IMG_FOLDER
  111. if not os.path.isdir(IMG_FOLDER):
  112. os.makedirs(IMG_FOLDER)
  113. # 回调结果保存路径
  114. RES_FOLDER = config_class.RES_FOLDER
  115. if not os.path.isdir(RES_FOLDER):
  116. os.makedirs(RES_FOLDER)
  117. new_img_ip = "http://{0}:{1}/ser_static".format(external_ip, server_port)
  118. old_img_ip = config_class.old_img_ip
  119. RawImg_UploadFolder = config_class.raw_img_upload_folder
  120. mathpix_ip = config_class.mathpix_ip