08b4517ca1d25dc1ea63327b714bf178d75ee3c6
[cumulus.git] / python / cumulus / store / __init__.py
1 import re, urlparse
2
3 type_patterns = {
4     'checksums': re.compile(r"^snapshot-(.*)\.(\w+)sums$"),
5     'segments': re.compile(r"^([0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12})(\.\S+)?$"),
6     'snapshots': re.compile(r"^snapshot-(.*)\.lbs$")
7 }
8
9 class Store:
10     """Base class for all cumulus storage backends."""
11
12     def list(self, type):
13         raise NotImplementedException
14
15     def get(self, type, name):
16         raise NotImplementedException
17
18     def put(self, type, name, fp):
19         raise NotImplementedException
20
21     def delete(self, type, name):
22         raise NotImplementedException
23
24 def open(url):
25     (scheme, netloc, path, params, query, fragment) \
26         = urlparse.urlparse(url)
27
28     if scheme == "file":
29         import cumulus.store.file
30         return cumulus.store.file.FileStore(path)
31     elif scheme == "s3":
32         import cumulus.store.s3
33         while path.startswith("/"): path = path[1:]
34         (bucket, path) = path.split("/", 1)
35         return cumulus.store.s3.S3Store(bucket, path)
36     else:
37         raise NotImplementedException