config_updater.py 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. # This Python file uses the following encoding: utf-8
  2. # @author runhey
  3. # github https://github.com/runhey
  4. import re
  5. from copy import deepcopy
  6. from cached_property import cached_property
  7. from deploy.utils import DEPLOY_TEMPLATE, poor_yaml_read, poor_yaml_write
  8. from module.base.timer import timer
  9. from module.config.utils import *
  10. class ConfigUpdater:
  11. @cached_property
  12. def args(self):
  13. return read_file(filepath_args(filename='args'))
  14. @timer
  15. def update_template(self, template_name: str = "template") -> None:
  16. """
  17. 更新模板 。从args.json更新
  18. :param template_name:
  19. :return:
  20. """
  21. pass
  22. @timer
  23. def update_config(self, config_name: str) -> None:
  24. """
  25. 更新配置文件.从template更新
  26. :param config_name:
  27. :return:
  28. """
  29. pass
  30. def read_file(self, config_name, is_template=False):
  31. """
  32. Read and update config file.
  33. Args:
  34. config_name (str): ./config/{file}.json
  35. is_template (bool):
  36. Returns:
  37. dict:
  38. """
  39. old = read_file(filepath_config(config_name))
  40. # new = self.config_update(old, is_template=is_template)
  41. # The updated config did not write into file, although it doesn't matters.
  42. # Commented for performance issue
  43. # self.write_file(config_name, new)
  44. return old
  45. @staticmethod
  46. def write_file(config_name, data, mod_name='alas'):
  47. """
  48. Write config file.
  49. Args:
  50. config_name (str): ./config/{file}.json
  51. data (dict):
  52. mod_name (str):
  53. """
  54. write_file(filepath_config(config_name, mod_name), data)