xref: /OpenGrok/tools/src/main/python/opengrok_tools/scm/svn.py (revision ae5b3cb81c9e71cf489cd9e38e66f063f1180c30)
12d57dc69SVladimir Kotal#
22d57dc69SVladimir Kotal# CDDL HEADER START
32d57dc69SVladimir Kotal#
42d57dc69SVladimir Kotal# The contents of this file are subject to the terms of the
52d57dc69SVladimir Kotal# Common Development and Distribution License (the "License").
62d57dc69SVladimir Kotal# You may not use this file except in compliance with the License.
72d57dc69SVladimir Kotal#
82d57dc69SVladimir Kotal# See LICENSE.txt included in this distribution for the specific
92d57dc69SVladimir Kotal# language governing permissions and limitations under the License.
102d57dc69SVladimir Kotal#
112d57dc69SVladimir Kotal# When distributing Covered Code, include this CDDL HEADER in each
122d57dc69SVladimir Kotal# file and include the License file at LICENSE.txt.
132d57dc69SVladimir Kotal# If applicable, add the following below this CDDL HEADER, with the
142d57dc69SVladimir Kotal# fields enclosed by brackets "[]" replaced with your own identifying
152d57dc69SVladimir Kotal# information: Portions Copyright [yyyy] [name of copyright owner]
162d57dc69SVladimir Kotal#
172d57dc69SVladimir Kotal# CDDL HEADER END
182d57dc69SVladimir Kotal#
192d57dc69SVladimir Kotal
202d57dc69SVladimir Kotal#
21*ae5b3cb8SVladimir Kotal# Copyright (c) 2018, 2021, Oracle and/or its affiliates. All rights reserved.
222d57dc69SVladimir Kotal# Portions Copyright (c) 2020, Krystof Tulinger <k.tulinger@seznam.cz>
232d57dc69SVladimir Kotal#
242d57dc69SVladimir Kotal
252d57dc69SVladimir Kotalfrom shutil import which
262d57dc69SVladimir Kotal
272d57dc69SVladimir Kotalfrom .repository import Repository, RepositoryException
282d57dc69SVladimir Kotal
292d57dc69SVladimir Kotal
302d57dc69SVladimir Kotalclass SubversionRepository(Repository):
31*ae5b3cb8SVladimir Kotal    def __init__(self, name, logger, path, project, command, env, hooks, timeout):
32*ae5b3cb8SVladimir Kotal        super().__init__(name, logger, path, project, command, env, hooks, timeout)
332d57dc69SVladimir Kotal
342d57dc69SVladimir Kotal        self.command = self._repository_command(command, default=lambda: which('svn'))
352d57dc69SVladimir Kotal
362d57dc69SVladimir Kotal        if not self.command:
372d57dc69SVladimir Kotal            raise RepositoryException("Cannot get svn command")
382d57dc69SVladimir Kotal
392d57dc69SVladimir Kotal    def reposync(self):
402d57dc69SVladimir Kotal        svn_command = [self.command]
412d57dc69SVladimir Kotal
422d57dc69SVladimir Kotal        #
432d57dc69SVladimir Kotal        # The proxy configuration in SVN does not heed environment variables so
442d57dc69SVladimir Kotal        # they need to be converted to the options.
452d57dc69SVladimir Kotal        #
462d57dc69SVladimir Kotal        http_proxy = self.env.get('http_proxy')
472d57dc69SVladimir Kotal        if http_proxy:
482d57dc69SVladimir Kotal            data = http_proxy.split(':')
492d57dc69SVladimir Kotal            if len(data) != 2:
502d57dc69SVladimir Kotal                self.logger.error("Cannot split '{}' into two strings by ':'".
512d57dc69SVladimir Kotal                                  format(http_proxy))
522d57dc69SVladimir Kotal                return 1
532d57dc69SVladimir Kotal
542d57dc69SVladimir Kotal            svn_command.append("--config-option")
552d57dc69SVladimir Kotal            svn_command.append("servers:global:http-proxy-host=" + data[0])
562d57dc69SVladimir Kotal            svn_command.append("--config-option")
572d57dc69SVladimir Kotal            svn_command.append("servers:global:http-proxy-port=" + data[1])
582d57dc69SVladimir Kotal
592d57dc69SVladimir Kotal        no_proxy = self.env.get('no_proxy')
602d57dc69SVladimir Kotal        if no_proxy:
612d57dc69SVladimir Kotal            svn_command.append("--config-option")
622d57dc69SVladimir Kotal            svn_command.append("servers:global:http-proxy-exceptions=" +
632d57dc69SVladimir Kotal                               no_proxy)
642d57dc69SVladimir Kotal
652d57dc69SVladimir Kotal        svn_command.append("update")
662d57dc69SVladimir Kotal        return self._run_custom_sync_command(svn_command)
67