c7.py 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. import os
  2. from datetime import datetime
  3. from pathlib import Path
  4. import typer
  5. import cognos7
  6. import config
  7. app = typer.Typer()
  8. cfg = config.Config()
  9. @app.command()
  10. def iqd_convert():
  11. iqdconv = cognos7.IqdConverter()
  12. iqdconv.output_dir = f"{cfg.system_dir}\\SQL\\schema\\{cfg.system}\\views_imr"
  13. iqdconv.run_folder(f"{cfg.system_dir}\\IQD")
  14. @app.command()
  15. def mdl_convert(mdl_file):
  16. cognos7.convert_file(mdl_file)
  17. source = Path(mdl_file[:-4] + ".json")
  18. dest = f"{cfg.cognos11.specs_dir}\\..\\DataModel\\{source.name}"
  19. os.makedirs(os.path.dirname(dest), exist_ok=True)
  20. Path(dest).unlink(missing_ok=True)
  21. os.rename(source, dest)
  22. @app.command()
  23. def move_csv():
  24. max_age_ts = datetime.now().timestamp() - 24 * 60 * 60
  25. print("Verschiebe CSV-Dateien von IQD zu Export...")
  26. no_files = True
  27. for source in Path(f"{cfg.system_dir}\\IQD").rglob("*.csv"):
  28. full_file = str(source)
  29. if "_\\" in full_file or "_ori" in full_file or "_.csv" in full_file:
  30. continue
  31. no_files = False
  32. print("* " + str(source))
  33. dest = Path(f"{cfg.system_dir}\\Export\\{source.name}")
  34. source_size = source.stat().st_size
  35. source_ts = source.stat().st_mtime
  36. if source_size <= 20:
  37. print(f"!! Datei {source.name} ist leer !!")
  38. continue
  39. if source_ts < max_age_ts:
  40. print(f"!! Datei {source.name} ist aelter als 24 Stunden !!")
  41. continue
  42. if dest.exists():
  43. dest_size = dest.stat().st_size
  44. if source_size < dest_size // 10:
  45. print(f"!! Datei {source.name} ist zu klein !!")
  46. print(f"{source}: {source_size // 1024} KB")
  47. print(f"{dest}: {dest_size // 1024} KB")
  48. print("")
  49. continue
  50. dest_ts = dest.stat().st_mtime
  51. if source_ts < dest_ts:
  52. print(f"!! Datei {source.name} ist aelter als die Zieldatei !!")
  53. print(str(source) + ": " + datetime.fromtimestamp(source_ts).strftime("%d.%m.%Y, %H:%M:%S"))
  54. print(str(dest) + ": " + datetime.fromtimestamp(dest_ts).strftime("%d.%m.%Y, %H:%M:%S"))
  55. print("")
  56. continue
  57. dest.unlink()
  58. os.rename(source, dest)
  59. if no_files:
  60. print("* Keine CSV-Dateien im IQD-Ordner gefunden.\n")
  61. print("Pruefe Export-Ordner...")
  62. ignore_file = Path(f"{cfg.system_dir}\\Export\\ignoriert.txt")
  63. ignore_list = []
  64. if ignore_file.exists():
  65. ignore_list = ignore_file.read_text(encoding="latin-1").split("\n")
  66. clean_exit = True
  67. for dest in Path(f"{cfg.system_dir}\\Export").glob("*.csv"):
  68. if dest.name in ignore_list:
  69. continue
  70. dest_ts = dest.stat().st_mtime
  71. if dest_ts < max_age_ts:
  72. print(f"!! Datei {dest.name} ist aelter als 24 Stunden !!")
  73. print(str(dest) + ": " + datetime.fromtimestamp(dest_ts).strftime("%d.%m.%Y, %H:%M:%S"))
  74. clean_exit = False
  75. continue
  76. if clean_exit:
  77. print("* Alle Dateien aktuell.\n")
  78. if __name__ == "__main__":
  79. # app()
  80. move_csv()