Append2BaseXLS.py 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. from logging import getLogger
  2. import baangt.base.GlobalConstants as GC
  3. from icopy2xls import Mover
  4. from baangt.base.PathManagement import ManagedPaths
  5. logger = getLogger("pyC")
  6. class Append2BaseXLS:
  7. """
  8. If in the globals of the current testrun the parameter AR2BXLS (Append Results to Base XLS) is set,
  9. we execute baangt Move-Corresponding module accordingly.
  10. """
  11. def __init__(self, testRunInstance, resultsFileName: str=None):
  12. self.testRunInstance = testRunInstance
  13. self.resultsFileName = resultsFileName
  14. self.mp = ManagedPaths()
  15. self._append2BaseXLS()
  16. def _append2BaseXLS(self):
  17. lGlobals = self.testRunInstance.globalSettings
  18. if not lGlobals.get("AR2BXLS"):
  19. logger.debug("No request to save to further destinations. Exiting.")
  20. return
  21. # Format: fileAndPath,Sheet;fileAndPath,sheet
  22. fileTuples = []
  23. if ";" in lGlobals.get("AR2BXLS"):
  24. files = lGlobals.get("AR2BXLS").split(";")
  25. for file in files:
  26. fileTuples.append(self.checkAppend(file))
  27. else:
  28. fileTuples.append(self.checkAppend(lGlobals["AR2BXLS"]))
  29. for fileTuple in fileTuples:
  30. logger.debug(f"Starting to append results to: {str(fileTuple)}")
  31. lMover = Mover(source_file_path=self.resultsFileName,
  32. source_sheet="Output",
  33. destination_file_path=fileTuple[0],
  34. destination_sheet=fileTuple[1])
  35. lMover.move(add_missing_columns=False)
  36. def checkAppend(self, file):
  37. lFileAndPath = self.mp.findFileInAnyPath(filename=file.split(",")[0])
  38. if lFileAndPath:
  39. return [lFileAndPath, file.split(",")[1]]
  40. else:
  41. logger.critical(f"File not found anywhere: {file.split(',')[0]}")
  42. return None