data_export_3.py 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. def export_upload_file(monitor_id):
  2. monitor = models.FileMonitor.objects.get(pk=monitor_id)
  3. full = monitor.full_path()
  4. monitor.status = "Checking"
  5. monitor.save()
  6. if not os.path.exists(full):
  7. logger.error("OS Error in file uploader")
  8. monitor.status = "Error: file does not exist"
  9. monitor.save()
  10. return
  11. digest_hex, diges_64, size = md5_stats_file(full)
  12. monitor.size = size
  13. monitor.md5sum = digest_hex
  14. monitor.url = "{0}:{1}".format(monitor.name, monitor.md5sum)
  15. monitor.status = "Connecting"
  16. monitor.save()
  17. try:
  18. con = boto.connect_s3(settings.AWS_ACCESS_KEY, settings.AWS_SECRET_KEY)
  19. bucket = con.get_bucket(settings.AWS_BUCKET_NAME)
  20. key = bucket.get_key(monitor.url)
  21. if key is not None:
  22. monitor.status = "Complete"
  23. monitor.save()
  24. return
  25. key = bucket.new_key(monitor.url)
  26. except Exception as err:
  27. logger.exception("Connecting error")
  28. monitor.status = "Error: {0}".format(err)
  29. monitor.save()
  30. return
  31. monitor.status = "Uploading"
  32. monitor.save()
  33. # Rewrite this into a class or a callable object
  34. # last_time = time.time()