| 29 | |
| 30 | |
| 31 | class FileKey(object): |
| 32 | def __init__(self, bucket, name): |
| 33 | self.bucket = bucket |
| 34 | self.name = name |
| 35 | self.path = os.path.join("/", name.strip("/")) |
| 36 | if os.path.isfile(self.path): |
| 37 | stat = os.stat(self.path) |
| 38 | self.last_modified = epoch_to_iso8601(stat.st_mtime) |
| 39 | self.size = stat.st_size |
| 40 | |
| 41 | def get_contents_as_string(self): |
| 42 | with open(self.path, 'rb') as fp: |
| 43 | contents = fp.read() |
| 44 | return contents |
| 45 | |
| 46 | def set_contents_from_file(self, fp): |
| 47 | ensure_dir_exists(self.path) |
| 48 | with open(self.path, 'wb') as f: |
| 49 | shutil.copyfileobj(fp, f) |
| 50 | setattr(self, 'size', os.path.getsize(self.path)) |
| 51 | |
| 52 | def get_contents_to_file(self, fp): |
| 53 | with open(self.path, 'rb') as f: |
| 54 | shutil.copyfileobj(f, fp) |
| 55 | |
| 56 | |
| 57 | class Bucket(object): |