xref: /OpenGrok/tools/src/main/python/opengrok_tools/scm/svn.py (revision ae5b3cb81c9e71cf489cd9e38e66f063f1180c30)
1#
2# CDDL HEADER START
3#
4# The contents of this file are subject to the terms of the
5# Common Development and Distribution License (the "License").
6# You may not use this file except in compliance with the License.
7#
8# See LICENSE.txt included in this distribution for the specific
9# language governing permissions and limitations under the License.
10#
11# When distributing Covered Code, include this CDDL HEADER in each
12# file and include the License file at LICENSE.txt.
13# If applicable, add the following below this CDDL HEADER, with the
14# fields enclosed by brackets "[]" replaced with your own identifying
15# information: Portions Copyright [yyyy] [name of copyright owner]
16#
17# CDDL HEADER END
18#
19
20#
21# Copyright (c) 2018, 2021, Oracle and/or its affiliates. All rights reserved.
22# Portions Copyright (c) 2020, Krystof Tulinger <k.tulinger@seznam.cz>
23#
24
25from shutil import which
26
27from .repository import Repository, RepositoryException
28
29
30class SubversionRepository(Repository):
31    def __init__(self, name, logger, path, project, command, env, hooks, timeout):
32        super().__init__(name, logger, path, project, command, env, hooks, timeout)
33
34        self.command = self._repository_command(command, default=lambda: which('svn'))
35
36        if not self.command:
37            raise RepositoryException("Cannot get svn command")
38
39    def reposync(self):
40        svn_command = [self.command]
41
42        #
43        # The proxy configuration in SVN does not heed environment variables so
44        # they need to be converted to the options.
45        #
46        http_proxy = self.env.get('http_proxy')
47        if http_proxy:
48            data = http_proxy.split(':')
49            if len(data) != 2:
50                self.logger.error("Cannot split '{}' into two strings by ':'".
51                                  format(http_proxy))
52                return 1
53
54            svn_command.append("--config-option")
55            svn_command.append("servers:global:http-proxy-host=" + data[0])
56            svn_command.append("--config-option")
57            svn_command.append("servers:global:http-proxy-port=" + data[1])
58
59        no_proxy = self.env.get('no_proxy')
60        if no_proxy:
61            svn_command.append("--config-option")
62            svn_command.append("servers:global:http-proxy-exceptions=" +
63                               no_proxy)
64
65        svn_command.append("update")
66        return self._run_custom_sync_command(svn_command)
67