config.py 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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. def joinpath(path, *other):
  22. return str(Path(path).joinpath(*other))
  23. class Config:
  24. kunde = 'Test'
  25. version = 'C11'
  26. versand_separat = False
  27. cognos7: Cognos7Config
  28. _cfg = {}
  29. def __init__(self, ini='GAPS.ini'):
  30. self._cfg = {}
  31. self.tools_dir = Path(os.curdir).absolute()
  32. self.tasks_dir = str(self.tools_dir.parent)
  33. if self.tools_dir.parent.name.lower() != 'tasks':
  34. # development
  35. self.portal_dir = 'C:\\GlobalCube'
  36. if not Path(self.portal_dir).exists():
  37. self.portal_dir = joinpath(self.tools_dir, 'Portal')
  38. else:
  39. base_dir = self.tools_dir.parent.parent
  40. if base_dir.name.lower() != 'globalcube':
  41. self.version = 'C7'
  42. self.portal_dir = str(base_dir)
  43. self.system_dir = joinpath(self.portal_dir, 'System')
  44. self.tasks_dir = joinpath(self.portal_dir, 'Tasks')
  45. self.xml_dir = joinpath(self.tasks_dir, 'config')
  46. self.log_dir = joinpath(self.tasks_dir, 'logs')
  47. with open(joinpath(self.tasks_dir, ini), 'r') as stream:
  48. for line in stream.readlines():
  49. if '=' in line:
  50. key, value = line.split('=')
  51. self._cfg[key] = value.replace('"', '').replace('\n', '')
  52. self.kunde = self._cfg.get('KUNDE', 'Test')
  53. self.kunde_safe = self.kunde.replace(' ', '-').lower()
  54. self.system = self._cfg.get('SYSTEM', '')
  55. if self.system != '':
  56. self.system_dir = joinpath(self.system_dir, self.system)
  57. self.mail_config()
  58. self.cognos7_config()
  59. self.cognos11_config()
  60. def mail_config(self):
  61. self.smtp = MailConfig(**{
  62. 'server': 'mail.global-cube.com',
  63. 'port': '465',
  64. 'secure': 'ssl',
  65. 'username': 'versand',
  66. 'password': 'y6!avXX3tQvr',
  67. 'email': 'versand+neuer-kunde@global-cube.com'
  68. })
  69. if self._cfg.get('SMTP_HOST', '') != '':
  70. secure = {'': '', 'N': '', 'J': 'ssl', 'SSL': 'ssl', 'TLS': 'tls'}
  71. self.smtp = MailConfig(
  72. server=self._cfg.get('SMTP_HOST'),
  73. port=self._cfg.get('SMTP_PORT'),
  74. secure=secure[self._cfg.get('SMTP_SSL', '')],
  75. username=self._cfg.get('SMTP_USER'),
  76. password=self._cfg.get('SMTP_PW'),
  77. email=self._cfg.get('SMTP_FROM'),
  78. )
  79. self.versand_separat = self._cfg.get('VERSAND_SEPARAT') == 'J'
  80. def cognos7_config(self):
  81. self.cognos7 = Cognos7Config(
  82. program_dir=self._cfg.get('COGNOS', 'C:\\Program Files (x86)\\Cognos\\cer5\\bin'),
  83. iqd_dir=joinpath(self.system_dir, 'IQD'),
  84. models_dir=joinpath(self.system_dir, 'Models'),
  85. cube_dir=joinpath(self.system_dir, 'Cube_out'),
  86. report_dir=joinpath(self.system_dir, 'Report'),
  87. publish_dir=joinpath(self.portal_dir, 'Publish', 'daten'),
  88. prot_dir=joinpath(self.system_dir, 'Prot')
  89. )
  90. if not Path(self.cognos7.publish_dir).exists():
  91. self.cognos7.publish_dir = joinpath(self.portal_dir, 'daten'),
  92. def cognos11_config(self):
  93. pass