You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

config_utils.py 2.4 kB

5 years ago
5 years ago
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. # -*- coding: UTF-8 -*-
  2. # Copyright 2020 Zhejiang Lab. All Rights Reserved.
  3. #
  4. # Licensed under the Apache License, Version 2.0 (the "License");
  5. # you may not use this file except in compliance with the License.
  6. # You may obtain a copy of the License at
  7. #
  8. # http://www.apache.org/licenses/LICENSE-2.0
  9. #
  10. # Unless required by applicable law or agreed to in writing, software
  11. # distributed under the License is distributed on an "AS IS" BASIS,
  12. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. # See the License for the specific language governing permissions and
  14. # limitations under the License.
  15. # =============================================================
  16. import configparser
  17. from os import path
  18. # Singleton mode
  19. class ConfigUtils:
  20. def __init__(self, config_name):
  21. if not path.exists(config_name):
  22. raise FileNotFoundError("Configuration file not found!")
  23. config = configparser.RawConfigParser()
  24. config.read(config_name)
  25. self.config = config
  26. def conf_django_debug(self):
  27. try:
  28. _debug = self.config['httpserver']['DjangoDebug']
  29. return _debug == 'True'
  30. except Exception:
  31. return True
  32. def conf_logdir_base(self):
  33. try:
  34. return self.config['parser']['LogdirBase']
  35. except KeyError:
  36. raise Exception(
  37. 'The root path of the visualization log must be set'
  38. )
  39. def conf_redis_host(self):
  40. try:
  41. return self.config['common']['RedisHost']
  42. except KeyError:
  43. return "localhost"
  44. def conf_redis_port(self):
  45. try:
  46. _port = self.config['common']['RedisPort']
  47. return int(_port)
  48. except Exception:
  49. return 6379
  50. def conf_redis_db(self):
  51. try:
  52. _db = self.config['common']['RedisDB']
  53. return int(_db)
  54. except Exception:
  55. return 1
  56. def conf_redis_password(self):
  57. try:
  58. return self.config['common']['RedisPassword']
  59. except KeyError:
  60. return None
  61. def conf_user_expiration_time(self):
  62. try:
  63. _time = self.config['common']['UserExpirationTime']
  64. return int(_time)
  65. except Exception:
  66. return 60
  67. ConfigInstance = ConfigUtils(
  68. path.split(path.realpath(__file__))[0] + '/../../config.ini'
  69. )

一站式算法开发平台、高性能分布式深度学习框架、先进算法模型库、视觉模型炼知平台、数据可视化分析平台等一系列平台及工具,在模型高效分布式训练、数据处理和可视分析、模型炼知和轻量化等技术上形成独特优势,目前已在产学研等各领域近千家单位及个人提供AI应用赋能

Contributors (1)