xref: /OpenGrok/tools/src/main/python/opengrok_tools/scm/teamware.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
25import os
26
27from .repository import Repository, RepositoryException
28
29
30class TeamwareRepository(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        #
35        # Teamware is different than the rest of the repositories.
36        # It really needs a path to the tools since the 'bringover'
37        # binary by itself is not sufficient to update the workspace.
38        # So instead of passing path to the binary, the command
39        # argument contains the path to the directory that contains
40        # the binaries.
41        #
42        self.command = self._repository_command(command)
43        if command:
44            if not os.path.isdir(command):
45                raise RepositoryException("Cannot construct Teamware "
46                                          "repository: {} is not a "
47                                          "directory".format(command))
48
49            try:
50                path = os.environ['PATH']
51            except KeyError:
52                raise OSError("Cannot get PATH env var")
53
54            path += ":" + command
55            self.env['PATH'] = path
56        else:
57            raise RepositoryException("Cannot get path to Teamware commands")
58
59    def reposync(self):
60        #
61        # If there is no Teamware specific subdirectory, do not bother
62        # syncing.
63        #
64        if not os.path.isdir(os.path.join(self.path, "Codemgr_wsdata")):
65            self.logger.debug("Not a teamware repository: {} -> not syncing".
66                              format(self.path))
67            return 0
68
69        return self._run_custom_sync_command(['bringover'])
70
71    def _check_command(self):
72        #
73        # The default implementation checks file existence. Teamware needs
74        # a directory.
75        #
76        if not os.path.isdir(self.command):
77            self.logger.error("path for '{}' is not a directory: {}".
78                              format(self.name, self.command))
79            return False
80
81        return True
82