config.py 4.9 KB

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