| 
									
										
										
										
											2025-02-11 21:11:43 -05:00
										 |  |  | import os | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | from nexrad.s3 import S3Bucket | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class Archive(): | 
					
						
							|  |  |  |     path:   str | 
					
						
							|  |  |  |     bucket: S3Bucket | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     def __init__(self, path: str, bucket: S3Bucket): | 
					
						
							|  |  |  |         self.path   = path | 
					
						
							|  |  |  |         self.bucket = bucket | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     def is_archived(self, key: str): | 
					
						
							| 
									
										
										
										
											2025-02-12 15:37:14 -05:00
										 |  |  |         return os.path.exists(os.path.join(self.path, key)) | 
					
						
							| 
									
										
										
										
											2025-02-11 21:11:43 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  |     def archive(self, key: str): | 
					
						
							| 
									
										
										
										
											2025-02-12 15:37:14 -05:00
										 |  |  |         path   = os.path.join(self.path, key) | 
					
						
							| 
									
										
										
										
											2025-02-11 21:11:43 -05:00
										 |  |  |         parent = os.path.dirname(path) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         os.makedirs(parent, exist_ok=True) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         with open(path, 'wb') as fh: | 
					
						
							|  |  |  |             self.bucket.s3.download_fileobj(self.bucket.name, key, fh) |