Esempio n. 1
0
File: s3.py Progetto: ranaur/S4
 def get_real_local_timestamp(self, key):
     try:
         response = self.boto.head_object(
             Bucket=self.bucket, Key=os.path.join(self.prefix, key)
         )
         return utils.to_timestamp(response["LastModified"])
     except ClientError:
         return None
Esempio n. 2
0
File: s3.py Progetto: ranaur/S4
    def get_all_real_local_timestamps(self):
        result = {}
        paginator = self.boto.get_paginator("list_objects_v2")
        page_iterator = paginator.paginate(Bucket=self.bucket, Prefix=self.prefix)
        for page in page_iterator:
            for obj in page.get("Contents", []):
                key = os.path.relpath(obj["Key"], self.prefix)
                if not is_ignored_key(key, self.ignore_files):
                    result[key] = utils.to_timestamp(obj["LastModified"])

        return result
Esempio n. 3
0
File: s3.py Progetto: samashti/S4
 def get(self, key):
     try:
         resp = self.boto.get_object(Bucket=self.bucket,
                                     Key=os.path.join(self.prefix, key))
         return SyncObject(
             resp["Body"],
             resp["ContentLength"],
             utils.to_timestamp(resp["LastModified"]),
         )
     except ClientError:
         return None
Esempio n. 4
0
File: test_s3.py Progetto: epayet/S4
    def test_put_get(self, s3_client):
        # given
        data = b'woooooooooshhh'
        input_object = SyncObject(io.BytesIO(data), len(data), 4000)
        frozen_time = datetime.datetime(2016, 10, 23, 10, 30, tzinfo=datetime.timezone.utc)

        # when
        with freezegun.freeze_time(frozen_time):
            s3_client.put('something/woosh.gif', input_object)

        # then
        output_object = s3_client.get('something/woosh.gif')
        assert output_object.fp.read() == data
        assert output_object.timestamp == to_timestamp(frozen_time)
Esempio n. 5
0
File: test_s3.py Progetto: epayet/S4
    def test_get(self, s3_client):
        # given
        data = b'#000000'
        frozen_time = datetime.datetime(2016, 10, 23, 10, 30, tzinfo=datetime.timezone.utc)
        with freezegun.freeze_time(frozen_time):
            s3_client.boto.put_object(
                Bucket=s3_client.bucket,
                Key=os.path.join(s3_client.prefix, 'black.color'),
                Body=data,
            )

        # when
        output_object = s3_client.get('black.color')

        # then
        assert output_object.fp.read() == data
        assert output_object.total_size == len(data)
        assert output_object.timestamp == to_timestamp(frozen_time)
Esempio n. 6
0
def get_timestamp(year, month, day, hour, minute):
    return to_timestamp(
        datetime(year, month, day, hour, minute, tzinfo=pytz.UTC))