config.py 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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. "max_connections": "20",
  31. "max_content_length": "10000000",
  32. "timeout": "10",
  33. "ssl": "False",
  34. "certificate": "/etc/apache2/ssl/server.crt",
  35. "key": "/etc/apache2/ssl/server.key",
  36. "protocol": "PROTOCOL_SSLv23",
  37. "ciphers": "",
  38. "dns_lookup": "True",
  39. "base_prefix": "/",
  40. "can_skip_base_prefix": "False",
  41. "realm": "Radicale - Password Required"},
  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. "fsync": "True",
  57. "hook": "",
  58. "close_lock_file": "False"},
  59. "logging": {
  60. "config": "/etc/radicale/logging",
  61. "debug": "False",
  62. "full_environment": "False",
  63. "mask_passwords": "True"}}
  64. def load(paths=(), extra_config=None):
  65. config = ConfigParser()
  66. for section, values in INITIAL_CONFIG.items():
  67. config.add_section(section)
  68. for key, value in values.items():
  69. config.set(section, key, value)
  70. if extra_config:
  71. for section, values in extra_config.items():
  72. for key, value in values.items():
  73. config.set(section, key, value)
  74. for path in paths:
  75. if path:
  76. config.read(path)
  77. return config