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, 2020, Oracle and/or its affiliates. All rights reserved.
22#
23
24import logging
25
26from .cvs import CVSRepository
27from .git import GitRepository
28from .mercurial import MercurialRepository
29from .repo import RepoRepository
30from .svn import SubversionRepository
31from .teamware import TeamwareRepository
32
33logger = logging.getLogger(__name__)
34
35
36def get_repository(path, repo_type, project,
37                   commands=None, env=None, hooks=None, timeout=None):
38    """
39    :param path: full path
40    :param repo_type: repository type
41    :param project: project name
42    :param commands: commands dictionary with paths to SCM utilities
43    :param env: environment variables dictionary
44    :param hooks: hook dictionary
45    :param timeout: timeout in seconds
46    :return: a Repository derived object according to the type specified
47    or None if given repository type cannot be found.
48    """
49
50    repo_lower = repo_type.lower()
51
52    logger.debug("Constructing repo object for path {}".format(path))
53
54    if not commands:
55        commands = {}
56
57    if repo_lower in ["mercurial", "hg"]:
58        return MercurialRepository(logger, path, project,
59                                   commands.get("hg"),
60                                   env, hooks, timeout)
61    elif repo_lower in ["teamware", "sccs"]:
62        return TeamwareRepository(logger, path, project,
63                                  commands.get("teamware"),
64                                  env, hooks, timeout)
65    elif repo_lower == "cvs":
66        return CVSRepository(logger, path, project,
67                             commands.get("cvs"),
68                             env, hooks, timeout)
69    elif repo_lower in ["svn", "subversion"]:
70        return SubversionRepository(logger, path, project,
71                                    commands.get("svn"),
72                                    env, hooks, timeout)
73    elif repo_lower == "git":
74        return GitRepository(logger, path, project,
75                             commands.get("git"),
76                             env, hooks, timeout)
77    elif repo_lower == "repo":
78        return RepoRepository(logger, path, project,
79                              commands.get("repo"),
80                              env, hooks, timeout)
81    else:
82        logger.warning("Unsupported repository type {}: {}".
83                       format(repo_type, path))
84        return None
85