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 from __future__ import division, print_function, unicode_literals
23 from urllib.parse import urlparse
25 from urlparse import urlparse
28 'checksums': re.compile(r"^snapshot-(.*)\.(\w+)sums$"),
29 '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+)?$"),
30 'snapshots': re.compile(r"^snapshot-(.*)\.(cumulus|lbs)$")
33 class NotFoundError(KeyError):
34 """Exception thrown when a file is not found in a repository."""
39 """Base class for all cumulus storage backends."""
41 def __new__ (cls, url, **kw):
42 """ Return the correct sub-class depending on url,
43 pass parsed url parameters to object
46 return super(Store, cls).__new__(cls, url, **kw)
47 (scheme, netloc, path, params, query, fragment) \
51 cumulus = __import__('cumulus.store.%s' % scheme, globals())
52 subcls = getattr (cumulus.store, scheme).Store
53 obj = super(Store, cls).__new__(subcls, url, **kw)
59 obj.fragment = fragment
62 raise NotImplementedError("Scheme %s not implemented" % scheme)
65 raise NotImplementedError
68 raise NotImplementedError
70 def put(self, path, fp):
71 raise NotImplementedError
73 def delete(self, path):
74 raise NotImplementedError
77 raise NotImplementedError
80 """Cache file information stored in this backend.
82 This might make subsequent list or stat calls more efficient, but this
83 function is intended purely as a performance optimization."""
88 """Tear down the connection explicitly if needed
90 Currently needed for sftp to be able to end the program."""