imip-agent

Annotated imiptools/stores/__init__.py

1431:564a684025ff
2018-01-12 Paul Boddie Prevent objects constructed for ADD method updates from employing RECURRENCE-ID. client-editing-simplification
paul@1069 1
#!/usr/bin/env python
paul@1069 2
paul@1069 3
"""
paul@1069 4
General support for calendar data storage.
paul@1069 5
paul@1206 6
Copyright (C) 2016, 2017 Paul Boddie <paul@boddie.org.uk>
paul@1069 7
paul@1069 8
This program is free software; you can redistribute it and/or modify it under
paul@1069 9
the terms of the GNU General Public License as published by the Free Software
paul@1069 10
Foundation; either version 3 of the License, or (at your option) any later
paul@1069 11
version.
paul@1069 12
paul@1069 13
This program is distributed in the hope that it will be useful, but WITHOUT
paul@1069 14
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
paul@1069 15
FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
paul@1069 16
details.
paul@1069 17
paul@1069 18
You should have received a copy of the GNU General Public License along with
paul@1069 19
this program.  If not, see <http://www.gnu.org/licenses/>.
paul@1069 20
"""
paul@1069 21
paul@1338 22
from imiptools.config import settings
paul@1340 23
from imiptools.stores.common import StoreInitialisationError
paul@1206 24
from imiptools.stores.manifest import stores
paul@1071 25
paul@1088 26
# Access functions.
paul@1069 27
paul@1338 28
def get_store(store_type=None, store_dir=None):
paul@1338 29
paul@1338 30
    """
paul@1338 31
    Return a store object for the given 'store_type' and 'store_dir', using
paul@1338 32
    configuration defaults where the parameters are given as None.
paul@1338 33
    """
paul@1338 34
paul@1343 35
    if store_dir or not store_type or store_type == settings["STORE_TYPE"]:
paul@1343 36
        return stores[store_type or settings["STORE_TYPE"]].Store(
paul@1343 37
            store_dir or settings["STORE_DIR"])
paul@1343 38
    else:
paul@1343 39
        raise StoreInitialisationError, "Store type cannot be changed arbitrarily."
paul@1338 40
paul@1338 41
def get_publisher(publishing_dir=None):
paul@1069 42
paul@1338 43
    """
paul@1338 44
    Return a publisher object for the given 'publishing_dir', using
paul@1338 45
    configuration defaults where the parameter is given as None.
paul@1338 46
    """
paul@1338 47
paul@1338 48
    return stores["file"].Publisher(
paul@1340 49
        publishing_dir or settings["PUBLISH_DIR"])
paul@1069 50
paul@1338 51
def get_journal(store_type=None, journal_dir=None):
paul@1338 52
paul@1338 53
    """
paul@1338 54
    Return a journal object for the given 'store_type' and 'journal_dir', using
paul@1338 55
    configuration defaults where the parameters are given as None.
paul@1338 56
    """
paul@1338 57
paul@1343 58
    if journal_dir or not store_type or store_type == settings["STORE_TYPE"]:
paul@1343 59
        return stores[store_type or settings["STORE_TYPE"]].Journal(
paul@1343 60
            journal_dir or settings["JOURNAL_DIR"])
paul@1343 61
    else:
paul@1343 62
        raise StoreInitialisationError, "Journal type cannot be changed arbitrarily."
paul@1069 63
paul@1069 64
# vim: tabstop=4 expandtab shiftwidth=4