X-Git-Url: http://git.vrable.net/?p=cumulus.git;a=blobdiff_plain;f=python%2Fcumulus%2Fstore%2Ffile.py;h=fd6805f571a2334f44522110da677053695c0972;hp=6aea58beea7c30cd0ece5b1e4dafb1764fb6cfec;hb=8637c84e5657ec8aa677091a1cde4c2fe666cbfb;hpb=567bd6a883eaa54d10ca61d0b6083da09bf48085 diff --git a/python/cumulus/store/file.py b/python/cumulus/store/file.py index 6aea58b..fd6805f 100644 --- a/python/cumulus/store/file.py +++ b/python/cumulus/store/file.py @@ -22,14 +22,11 @@ import os, sys, tempfile import cumulus.store -type_patterns = cumulus.store.type_patterns - -class FileStore(cumulus.store.Store): - def __init__(self, url, **kw): - # if constructor isn't called via factory interpret url as filename - if not hasattr (self, 'path'): - self.path = url - self.prefix = self.path.rstrip("/") +class Store(cumulus.store.Store): + """Storage backend that accesses the local file system.""" + def __init__(self, url): + super(Store, self).__init__(url) + self.prefix = cumulus.store.unquote(url.path) def list(self, subdir): try: @@ -44,11 +41,11 @@ class FileStore(cumulus.store.Store): raise cumulus.store.NotFoundError(path) def put(self, path, fp): - out = open(os.path.join(self.prefix, path), 'wb') - buf = fp.read(4096) - while len(buf) > 0: - out.write(buf) + with open(os.path.join(self.prefix, path), "wb") as out: buf = fp.read(4096) + while len(buf) > 0: + out.write(buf) + buf = fp.read(4096) def delete(self, path): os.unlink(os.path.join(self.prefix, path)) @@ -59,5 +56,3 @@ class FileStore(cumulus.store.Store): return {'size': stat.st_size} except OSError: raise cumulus.store.NotFoundError(path) - -Store = FileStore