keep-logs.py 1.2 KB

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