c97d084802caaabde6fa815bd7e605aea97bcfa5
[be.git] / libbe / storage / __init__.py
1 # Copyright (C) 2009-2012 Chris Ball <cjb@laptop.org>
2 #                         W. Trevor King <wking@drexel.edu>
3 #
4 # This file is part of Bugs Everywhere.
5 #
6 # Bugs Everywhere is free software: you can redistribute it and/or modify it
7 # under the terms of the GNU General Public License as published by the Free
8 # Software Foundation, either version 2 of the License, or (at your option) any
9 # later version.
10 #
11 # Bugs Everywhere is distributed in the hope that it will be useful, but
12 # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 # FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
14 # more details.
15 #
16 # You should have received a copy of the GNU General Public License along with
17 # Bugs Everywhere.  If not, see <http://www.gnu.org/licenses/>.
18
19 """Define the :class:`~libbe.storage.base.Storage` and
20 :class:`~libbe.storage.base.VersionedStorage` classes for storing BE
21 data.
22
23 Also define assorted implementations for the Storage classes:
24
25 * :mod:`libbe.storage.vcs`
26 * :mod:`libbe.storage.http`
27
28 Also define an assortment of storage-related tools and utilities:
29
30 * :mod:`libbe.storage.util`
31 """
32
33 import base
34
35 ConnectionError = base.ConnectionError
36 InvalidStorageVersion = base.InvalidStorageVersion
37 InvalidID = base.InvalidID
38 InvalidRevision = base.InvalidRevision
39 InvalidDirectory = base.InvalidDirectory
40 NotWriteable = base.NotWriteable
41 NotReadable = base.NotReadable
42 EmptyCommit = base.EmptyCommit
43
44 # a list of all past versions
45 STORAGE_VERSIONS = ['Bugs Everywhere Tree 1 0',
46                     'Bugs Everywhere Directory v1.1',
47                     'Bugs Everywhere Directory v1.2',
48                     'Bugs Everywhere Directory v1.3',
49                     'Bugs Everywhere Directory v1.4',
50                     ]
51
52 # the current version
53 STORAGE_VERSION = STORAGE_VERSIONS[-1]
54
55 def get_http_storage(location):
56     import http
57     return http.HTTP(location)
58
59 def get_vcs_storage(location):
60     import vcs
61     s = vcs.detect_vcs(location)
62     s.repo = location
63     return s
64
65 def get_storage(location):
66     """
67     Return a Storage instance from a repo location string.
68     """
69     if location.startswith('http://') or location.startswith('https://'):
70         return get_http_storage(location)
71     return get_vcs_storage(location)
72
73 __all__ = [ConnectionError, InvalidStorageVersion, InvalidID,
74            InvalidRevision, InvalidDirectory, NotWriteable, NotReadable,
75            EmptyCommit, STORAGE_VERSIONS, STORAGE_VERSION,
76            get_storage]