config.py 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. # This file is part of Radicale Server - Calendar Server
  2. # Copyright © 2008-2016 Guillaume Ayoub
  3. # Copyright © 2008 Nicolas Kandel
  4. # Copyright © 2008 Pascal Halter
  5. #
  6. # This library is free software: you can redistribute it and/or modify
  7. # it under the terms of the GNU General Public License as published by
  8. # the Free Software Foundation, either version 3 of the License, or
  9. # (at your option) any later version.
  10. #
  11. # This library is distributed in the hope that it will be useful,
  12. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. # GNU General Public License for more details.
  15. #
  16. # You should have received a copy of the GNU General Public License
  17. # along with Radicale. If not, see <http://www.gnu.org/licenses/>.
  18. """
  19. Radicale configuration module.
  20. Give a configparser-like interface to read and write configuration.
  21. """
  22. import os
  23. from configparser import RawConfigParser as ConfigParser
  24. # Default configuration
  25. INITIAL_CONFIG = {
  26. "server": {
  27. "hosts": "0.0.0.0:5232",
  28. "daemon": "False",
  29. "pid": "",
  30. "ssl": "False",
  31. "certificate": "/etc/apache2/ssl/server.crt",
  32. "key": "/etc/apache2/ssl/server.key",
  33. "protocol": "PROTOCOL_SSLv23",
  34. "ciphers": "",
  35. "dns_lookup": "True",
  36. "base_prefix": "/",
  37. "can_skip_base_prefix": "False",
  38. "realm": "Radicale - Password Required"},
  39. "well-known": {
  40. "caldav": "/caldav/",
  41. "carddav": "/carddav/"},
  42. "encoding": {
  43. "request": "utf-8",
  44. "stock": "utf-8"},
  45. "auth": {
  46. "type": "None",
  47. "htpasswd_filename": "/etc/radicale/users",
  48. "htpasswd_encryption": "crypt"},
  49. "rights": {
  50. "type": "None",
  51. "file": "~/.config/radicale/rights"},
  52. "storage": {
  53. "type": "multifilesystem",
  54. "filesystem_folder": os.path.expanduser(
  55. "~/.config/radicale/collections")},
  56. "logging": {
  57. "config": "/etc/radicale/logging",
  58. "debug": "False",
  59. "full_environment": "False",
  60. "mask_passwords": "True"}}
  61. def load(paths=()):
  62. config = ConfigParser()
  63. for section, values in INITIAL_CONFIG.items():
  64. config.add_section(section)
  65. for key, value in values.items():
  66. config.set(section, key, value)
  67. for path in paths:
  68. if path:
  69. config.read(path)
  70. return config