config.py 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. import os
  2. from pathlib import Path
  3. from dataclasses import dataclass
  4. @dataclass
  5. class MailConfig:
  6. server: str
  7. port: int
  8. secure: str
  9. username: str
  10. password: str
  11. email: str
  12. @dataclass
  13. class Cognos7Config:
  14. program_dir: str
  15. iqd_dir: str
  16. models_dir: str
  17. cube_dir: str
  18. report_dir: str
  19. publish_dir: str
  20. prot_dir: str
  21. @dataclass
  22. class Cognos11Config:
  23. logs_dir: str
  24. reportoutput_dir: str
  25. specs_dir: str
  26. webservice: str
  27. config_dir: str
  28. folders_file: str
  29. reports_file: str
  30. jobs_file: str
  31. def joinpath(path, *other):
  32. return str(Path(path).joinpath(*other)).lower()
  33. class Config:
  34. kunde = 'Test'
  35. version = 'C11'
  36. versand_separat = False
  37. cognos7: Cognos7Config
  38. cognos11: Cognos11Config
  39. _cfg = {}
  40. def __init__(self, ini='GAPS.ini'):
  41. self._cfg = {}
  42. self.tools_dir = Path(os.curdir).absolute()
  43. self.tasks_dir = str(self.tools_dir.parent).lower()
  44. if self.tools_dir.parent.name.lower() != 'tasks':
  45. # development
  46. self.tools_dir = self.tools_dir.joinpath('gctools')
  47. self.portal_dir = 'c:\\globalcube'
  48. if not Path(self.portal_dir).exists():
  49. self.portal_dir = joinpath(self.tools_dir, 'Portal')
  50. else:
  51. base_dir = self.tools_dir.parent.parent
  52. if base_dir.name.lower() != 'globalcube':
  53. self.version = 'C7'
  54. self.portal_dir = str(base_dir)
  55. self.system_dir = joinpath(self.portal_dir, 'System')
  56. self.tasks_dir = joinpath(self.portal_dir, 'Tasks')
  57. self.xml_dir = joinpath(self.tasks_dir, 'config')
  58. self.log_dir = joinpath(self.tasks_dir, 'logs')
  59. if ':' not in ini:
  60. ini = joinpath(self.tasks_dir, ini)
  61. with open(ini, 'r') as stream:
  62. for line in stream.readlines():
  63. if '=' in line:
  64. key, value = line.split('=')
  65. self._cfg[key] = value.replace('"', '').replace('\n', '')
  66. self.kunde = self._cfg.get('KUNDE', 'Test')
  67. self.kunde_safe = self.kunde.replace(' ', '-').lower()
  68. self.system = self._cfg.get('SYSTEM', '')
  69. if self.system != '':
  70. self.system_dir = joinpath(self.system_dir, self.system)
  71. self.mail_config()
  72. self.cognos7_config()
  73. self.cognos11_config()
  74. def mail_config(self):
  75. self.smtp = MailConfig(**{
  76. 'server': 'mail.global-cube.com',
  77. 'port': '465',
  78. 'secure': 'ssl',
  79. 'username': 'versand',
  80. 'password': 'y6!avXX3tQvr',
  81. 'email': 'versand+neuer-kunde@global-cube.com'
  82. })
  83. if self._cfg.get('SMTP_HOST', '') != '':
  84. secure = {'': '', 'N': '', 'J': 'ssl', 'SSL': 'ssl', 'TLS': 'tls'}
  85. self.smtp = MailConfig(
  86. server=self._cfg.get('SMTP_HOST'),
  87. port=self._cfg.get('SMTP_PORT'),
  88. secure=secure[self._cfg.get('SMTP_SSL', '')],
  89. username=self._cfg.get('SMTP_USER'),
  90. password=self._cfg.get('SMTP_PW'),
  91. email=self._cfg.get('SMTP_FROM'),
  92. )
  93. self.versand_separat = self._cfg.get('VERSAND_SEPARAT') == 'J'
  94. def cognos7_config(self):
  95. self.cognos7 = Cognos7Config(
  96. program_dir=self._cfg.get('COGNOS', 'c:\\program files (x86)\\cognos\\cer5\\bin'),
  97. iqd_dir=joinpath(self.system_dir, 'IQD'),
  98. models_dir=joinpath(self.system_dir, 'Models'),
  99. cube_dir=joinpath(self.system_dir, 'Cube_out'),
  100. report_dir=joinpath(self.system_dir, 'Report'),
  101. publish_dir=joinpath(self.portal_dir, 'Publish', 'daten'),
  102. prot_dir=joinpath(self.system_dir, 'Prot')
  103. )
  104. if not Path(self.cognos7.publish_dir).exists():
  105. self.cognos7.publish_dir = joinpath(self.portal_dir, 'daten'),
  106. def cognos11_config(self):
  107. self.cognos11 = Cognos11Config(
  108. logs_dir=joinpath(self.log_dir, 'c11'),
  109. reportoutput_dir=joinpath(self.portal_dir, 'ReportOutput'),
  110. specs_dir=joinpath(self.system_dir, 'Report'),
  111. webservice='http://localhost:9300/bi/',
  112. config_dir=joinpath(self.xml_dir, 'c11'),
  113. folders_file=joinpath(self.xml_dir, 'c11', 'folders.json'),
  114. reports_file=joinpath(self.xml_dir, 'c11', 'reports.json'),
  115. jobs_file=joinpath(self.xml_dir, 'c11', 'jobs.json')
  116. )