storage:util:mapfile: convert YAML settings to JSON.
[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                     'Bugs Everywhere Directory v1.5',
51                     ]
52
53 # the current version
54 STORAGE_VERSION = STORAGE_VERSIONS[-1]
55
56 def get_http_storage(location):
57     import http
58     return http.HTTP(location)
59
60 def get_vcs_storage(location):
61     import vcs
62     s = vcs.detect_vcs(location)
63     s.repo = location
64     return s
65
66 def get_storage(location):
67     """
68     Return a Storage instance from a repo location string.
69     """
70     if location.startswith('http://') or location.startswith('https://'):
71         return get_http_storage(location)
72     return get_vcs_storage(location)
73
74 __all__ = [ConnectionError, InvalidStorageVersion, InvalidID,
75            InvalidRevision, InvalidDirectory, NotWriteable, NotReadable,
76            EmptyCommit, STORAGE_VERSIONS, STORAGE_VERSION,
77            get_storage]