keep-logs.py 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. #
  2. # Archives, to the specified folder, the logged output generated by a benchmark
  3. # run.
  4. #
  5. # @author A. Shawn Bandy
  6. import os
  7. import zipfile
  8. import datetime
  9. import requests
  10. # Follows closely from:
  11. # http://stackoverflow.com/a/34153816
  12. #
  13. # Paths to the log folders are generated by TFB and where those files
  14. # should be archived.
  15. #
  16. path_in = os.path.abspath(os.path.normpath(os.path.expanduser(os.path.join( \
  17. os.environ['TFB_REPOPARENT'], os.environ['TFB_REPONAME'], \
  18. 'results'))))
  19. date_time = datetime.datetime.now()
  20. dt_folder = date_time.strftime('%Y%m%d%H%M%S')
  21. path_out = os.path.abspath(os.path.join(os.environ['TFB_LOGSFOLDER'], \
  22. dt_folder))
  23. if not os.path.exists(path_out):
  24. os.makedirs(path_out)
  25. zip_path = path_out + '/results.zip'
  26. zip_file = zipfile.ZipFile(zip_path, 'w', zipfile.ZIP_DEFLATED)
  27. for root, dirs, files in os.walk(path_in):
  28. for file in files:
  29. zip_file.write(os.path.join(root, file))
  30. zip_file.close()
  31. results_upload_uri = os.environ['TFB_UPLOADURI']
  32. if results_upload_uri != None:
  33. with open(zip_path, 'rb') as file_to_upload:
  34. requests.post(
  35. results_upload_uri,
  36. headers={'Content-Type': 'application/zip'},
  37. data=file_to_upload)