py-s3uploader_7.py 1023 B

1234567891011121314151617181920212223242526
  1. def _upload_file(self,connection,bucket,localfile,bucketfile,ignoredates):
  2. s3key = bucket.get_key(bucketfile)
  3. if not s3key:
  4. s3key = Key(bucket)
  5. s3key.key = bucketfile
  6. s3date = s3key.get_metadata("date")
  7. if s3date: s3date = int(s3date)
  8. lcdate = int(os.path.getmtime(localfile))
  9. upload = False
  10. if not s3date: upload = True
  11. if s3date and lcdate > s3date: upload = True
  12. if ignoredates: upload = True
  13. if not upload: return ## don't upload, return
  14. if self.dryrun: print ("dry-run. %s : %s => %s" % (bucket.name,localfile,bucketfile))
  15. else: print ("%s : %s => %s" % (bucket.name,localfile,bucketfile))
  16. filetype = localfile.split(".")[-1]
  17. meta = self.get_metadata_for_filtetype(filetype)
  18. if meta:
  19. for metadata in meta:
  20. for key in metadata:
  21. print (" => metdata: %s:%s" % (key,metadata[key]))
  22. if not self.dryrun:
  23. s3key.set_metadata(key,metadata[key])
  24. if not self.dryrun:
  25. s3key.set_metadata("date",str(int(time.time())))
  26. s3key.set_contents_from_filename(localfile)