def export_upload_file(monitor_id): monitor = models.FileMonitor.objects.get(pk=monitor_id) full = monitor.full_path() monitor.status = "Checking" monitor.save() if not os.path.exists(full): logger.error("OS Error in file uploader") monitor.status = "Error: file does not exist" monitor.save() return digest_hex, diges_64, size = md5_stats_file(full) monitor.size = size monitor.md5sum = digest_hex monitor.url = "{0}:{1}".format(monitor.name, monitor.md5sum) monitor.status = "Connecting" monitor.save() try: con = boto.connect_s3(settings.AWS_ACCESS_KEY, settings.AWS_SECRET_KEY) bucket = con.get_bucket(settings.AWS_BUCKET_NAME) key = bucket.get_key(monitor.url) if key is not None: monitor.status = "Complete" monitor.save() return key = bucket.new_key(monitor.url) except Exception as err: logger.exception("Connecting error") monitor.status = "Error: {0}".format(err) monitor.save() return monitor.status = "Uploading" monitor.save() # Rewrite this into a class or a callable object # last_time = time.time()