1 # Cumulus: Efficient Filesystem Backup to the Cloud
2 # Copyright (C) 2008-2010 The Cumulus Developers
3 # See the AUTHORS file for a list of contributors.
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 2 of the License, or
8 # (at your option) any later version.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License along
16 # with this program; if not, write to the Free Software Foundation, Inc.,
17 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 import exceptions, re, urlparse
22 'checksums': re.compile(r"^snapshot-(.*)\.(\w+)sums$"),
23 '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+)?$"),
24 'snapshots': re.compile(r"^snapshot-(.*)\.(cumulus|lbs)$")
27 class NotFoundError(exceptions.KeyError):
28 """Exception thrown when a file is not found in a repository."""
33 """Base class for all cumulus storage backends."""
35 def __new__ (cls, url, **kw):
36 """ Return the correct sub-class depending on url,
37 pass parsed url parameters to object
40 return super(Store, cls).__new__(cls, url, **kw)
41 (scheme, netloc, path, params, query, fragment) \
42 = urlparse.urlparse(url)
45 cumulus = __import__('cumulus.store.%s' % scheme, globals())
46 subcls = getattr (cumulus.store, scheme).Store
47 obj = super(Store, cls).__new__(subcls, url, **kw)
53 obj.fragment = fragment
56 raise NotImplementedError, "Scheme %s not implemented" % scheme
59 raise NotImplementedError
62 raise NotImplementedError
64 def put(self, path, fp):
65 raise NotImplementedError
67 def delete(self, path):
68 raise NotImplementedError
71 raise NotImplementedError
74 """Cache file information stored in this backend.
76 This might make subsequent list or stat calls more efficient, but this
77 function is intended purely as a performance optimization."""
82 """Tear down the connection explicitly if needed
84 Currently needed for sftp to be able to end the program."""