server: intialize aux_header buffer to null if the data is missing.
[tridge/openchange.git] / branches / plugfest / python / openchange / urlutils.py
1 #!/usr/bin/python
2
3 # OpenChange provisioning
4 # Copyright (C) Jelmer Vernooij <jelmer@openchange.org> 2008-2009
5 # Copyright (C) Julien Kerihuel <j.kerihuel@openchange.org> 2009
6 # Copyright (C) Brad Hards <bradh@openchange.org> 2010
7 #
8 # This program is free software; you can redistribute it and/or modify
9 # it under the terms of the GNU General Public License as published by
10 # the Free Software Foundation; either version 3 of the License, or
11 # (at your option) any later version.
12 #
13 # This program is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 # GNU General Public License for more details.
17 #
18 # You should have received a copy of the GNU General Public License
19 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
20 #
21
22 import os
23
24
25 class UnsupportedMapistoreBackend(Exception):
26     
27     def __init__(self, backend):
28         super(UnsupportedMapistoreBackend, self).__init__("unsupported mapistore backend type: %s" % backend)
29
30
31 def openchangedb_url(lp):
32     return os.path.join(lp.get("private dir"), "openchange.ldb")
33
34
35 def openchangedb_mapistore_dir(lp):
36     return os.path.join(lp.get("private dir"), "mapistore")
37
38
39 def openchangedb_mapistore_url(lp, backend):
40     if backend in ("fsocpf", None):
41         return "fsocpf://%s" % openchangedb_mapistore_dir(lp)
42     elif backend == "sqlite":
43         return "sqlite://%s" % openchangedb_mapistore_dir(lp)
44     raise UnsupportedMapistoreBackend(backend)
45
46
47 def openchangedb_mapistore_url_split(url):
48     if url.startswith("fsocpf://"):
49         return url.partition("fsocpf://")[1:]
50     if url.startswith("sqlite://"):
51         return url.partition("sqlite://")[1:]
52
53
54 def openchangedb_suffix_for_mapistore_url(url):
55     if (url.startswith("fsocpf://")):
56         return ""
57     if (url.startswith("sqlite://")):
58         return ".db"
59     return ""