Implement a single NotFoundError which is thrown whenever a file does not
exist in any remote store, instead instance-specific error handling.
-import re, urlparse
+import exceptions, re, urlparse
type_patterns = {
'checksums': re.compile(r"^snapshot-(.*)\.(\w+)sums$"),
'snapshots': re.compile(r"^snapshot-(.*)\.lbs$")
}
+class NotFoundError(exceptions.KeyError):
+ """Exception thrown when a file is not found in a repository."""
+
+ pass
+
class Store:
"""Base class for all cumulus storage backends."""
os.unlink(k)
def stat(self, type, name):
- stat = os.stat(self._get_path(type, name))
- return {'size': stat.st_size}
+ try:
+ stat = os.stat(self._get_path(type, name))
+ return {'size': stat.st_size}
+ except OSError:
+ raise cumulus.store.NotFoundError
def stat(self, type, name):
k = self.bucket.get_key("%s/%s/%s" % (self.prefix, type, name))
+ if k is None:
+ raise cumulus.store.NotFoundError
return {'size': int(k.size)}