##// END OF EJS Templates
pull-requests: move text with commit summary to left. It looks better.
pull-requests: move text with commit summary to left. It looks better.

File last commit:

r1271:47a44c03 default
r1469:f85bca1f default
Show More
utils.py
93 lines | 3.2 KiB | text/x-python | PythonLexer
Martin Bornhold
svn: Moved code and make a small bugfix.
r563 # -*- coding: utf-8 -*-
license: updated copyright year to 2017
r1271 # Copyright (C) 2016-2017 RhodeCode GmbH
Martin Bornhold
svn: Moved code and make a small bugfix.
r563 #
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License, version 3
# (only), as published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
# This program is dual-licensed. If you wish to learn more about the
# RhodeCode Enterprise Edition, including its added features, Support services,
# and proprietary license terms, please see https://rhodecode.com/licenses/
Martin Bornhold
svn-support: Use utf-8 to encode mod_dav_svn configuration before writing to disk....
r830 import codecs
Martin Bornhold
svn: Split up config generation method and do not raise exceptions on writing config to file.
r571 import logging
Martin Bornhold
svn: Moved code and make a small bugfix.
r563 import os
from pyramid.renderers import render
Martin Bornhold
svn-support: Add subscriber to execute the svn.proxy.reload_cmd on config changes. #4271
r1011 from rhodecode.events import trigger
from rhodecode.lib.utils import get_rhodecode_realm, get_rhodecode_base_path
svn-support: generate http downgrade only if we force_https in config.
r1218 from rhodecode.lib.utils2 import str2bool
Martin Bornhold
svn: Moved code and make a small bugfix.
r563 from rhodecode.model.db import RepoGroup
Martin Bornhold
svn-support: Add subscriber to execute the svn.proxy.reload_cmd on config changes. #4271
r1011
Martin Bornhold
svn: Rename keys.py to config_keys.py
r567 from . import config_keys
Martin Bornhold
svn-support: Add subscriber to execute the svn.proxy.reload_cmd on config changes. #4271
r1011 from .events import ModDavSvnConfigChange
Martin Bornhold
svn: Moved code and make a small bugfix.
r563
Martin Bornhold
svn: Split up config generation method and do not raise exceptions on writing config to file.
r571 log = logging.getLogger(__name__)
Martin Bornhold
svn-support: Add subscriber to execute the svn.proxy.reload_cmd on config changes. #4271
r1011 def generate_mod_dav_svn_config(registry):
Martin Bornhold
svn: Moved code and make a small bugfix.
r563 """
Generate the configuration file for use with subversion's mod_dav_svn
module. The configuration has to contain a <Location> block for each
available repository group because the mod_dav_svn module does not support
repositories organized in sub folders.
"""
Martin Bornhold
svn-support: Add subscriber to execute the svn.proxy.reload_cmd on config changes. #4271
r1011 settings = registry.settings
svn-support: generate http downgrade only if we force_https in config.
r1218 use_ssl = str2bool(registry.settings['force_https'])
Martin Bornhold
svn: Split up config generation method and do not raise exceptions on writing config to file.
r571 config = _render_mod_dav_svn_config(
svn-support: generate http downgrade only if we force_https in config.
r1218 use_ssl=use_ssl,
Martin Bornhold
svn-support: Add subscriber to execute the svn.proxy.reload_cmd on config changes. #4271
r1011 parent_path_root=get_rhodecode_base_path(),
Martin Bornhold
svn-support: Use repo root path from DB to generate mod-dav-svn config. Fixes #4203
r826 list_parent_path=settings[config_keys.list_parent_path],
Martin Bornhold
svn-support: Fix typo in argument name.
r829 location_root=settings[config_keys.location_root],
Martin Bornhold
svn-support: Fix tests for subversion support....
r1021 repo_groups=RepoGroup.get_all_repo_groups(),
realm=get_rhodecode_realm())
Martin Bornhold
svn: Split up config generation method and do not raise exceptions on writing config to file.
r571 _write_mod_dav_svn_config(config, settings[config_keys.config_file_path])
Martin Bornhold
svn-support: Add subscriber to execute the svn.proxy.reload_cmd on config changes. #4271
r1011 # Trigger an event on mod dav svn configuration change.
trigger(ModDavSvnConfigChange(), registry)
Martin Bornhold
svn: Moved code and make a small bugfix.
r563
Martin Bornhold
svn: Split up config generation method and do not raise exceptions on writing config to file.
r571 def _render_mod_dav_svn_config(
svn-support: generate http downgrade only if we force_https in config.
r1218 parent_path_root, list_parent_path, location_root, repo_groups, realm,
use_ssl):
Martin Bornhold
svn: Split up config generation method and do not raise exceptions on writing config to file.
r571 """
Render mod_dav_svn configuration to string.
"""
Martin Bornhold
svn: Move path computation from themplate to python.
r570 repo_group_paths = []
Martin Bornhold
svn: Split up config generation method and do not raise exceptions on writing config to file.
r571 for repo_group in repo_groups:
Martin Bornhold
svn: Move path computation from themplate to python.
r570 group_path = repo_group.full_path_splitted
location = os.path.join(location_root, *group_path)
parent_path = os.path.join(parent_path_root, *group_path)
repo_group_paths.append((location, parent_path))
Martin Bornhold
svn: Moved code and make a small bugfix.
r563 context = {
'location_root': location_root,
'parent_path_root': parent_path_root,
Martin Bornhold
svn: Move path computation from themplate to python.
r570 'repo_group_paths': repo_group_paths,
Martin Bornhold
svn: Moved code and make a small bugfix.
r563 'svn_list_parent_path': list_parent_path,
Martin Bornhold
svn-support: Fix tests for subversion support....
r1021 'rhodecode_realm': realm,
svn-support: generate http downgrade only if we force_https in config.
r1218 'use_https': use_ssl
Martin Bornhold
svn: Moved code and make a small bugfix.
r563 }
Martin Bornhold
svn: Move path computation from themplate to python.
r570
# Render the configuration template to string.
template = 'rhodecode:svn_support/templates/mod-dav-svn.conf.mako'
Martin Bornhold
svn: Split up config generation method and do not raise exceptions on writing config to file.
r571 return render(template, context)
Martin Bornhold
svn: Moved code and make a small bugfix.
r563
Martin Bornhold
svn: Split up config generation method and do not raise exceptions on writing config to file.
r571 def _write_mod_dav_svn_config(config, filepath):
"""
Martin Bornhold
svn-support: Move try/catch block up to subscriber and also DB interaction.
r831 Write mod_dav_svn config to file.
Martin Bornhold
svn: Split up config generation method and do not raise exceptions on writing config to file.
r571 """
Martin Bornhold
svn-support: Move try/catch block up to subscriber and also DB interaction.
r831 with codecs.open(filepath, 'w', encoding='utf-8') as f:
f.write(config)