1234567891011121314151617181920212223242526 |
- def _upload_file(self,connection,bucket,localfile,bucketfile,ignoredates):
- s3key = bucket.get_key(bucketfile)
- if not s3key:
- s3key = Key(bucket)
- s3key.key = bucketfile
- s3date = s3key.get_metadata("date")
- if s3date: s3date = int(s3date)
- lcdate = int(os.path.getmtime(localfile))
- upload = False
- if not s3date: upload = True
- if s3date and lcdate > s3date: upload = True
- if ignoredates: upload = True
- if not upload: return ## don't upload, return
- if self.dryrun: print ("dry-run. %s : %s => %s" % (bucket.name,localfile,bucketfile))
- else: print ("%s : %s => %s" % (bucket.name,localfile,bucketfile))
- filetype = localfile.split(".")[-1]
- meta = self.get_metadata_for_filtetype(filetype)
- if meta:
- for metadata in meta:
- for key in metadata:
- print (" => metdata: %s:%s" % (key,metadata[key]))
- if not self.dryrun:
- s3key.set_metadata(key,metadata[key])
- if not self.dryrun:
- s3key.set_metadata("date",str(int(time.time())))
- s3key.set_contents_from_filename(localfile)
|