| # Copyright 2011 OpenStack, LLC. |
| # Copyright 2012 Hewlett-Packard Development Company, L.P. |
| # |
| # Licensed under the Apache License, Version 2.0 (the "License"); you may |
| # not use this file except in compliance with the License. You may obtain |
| # a copy of the License at |
| # |
| # http://www.apache.org/licenses/LICENSE-2.0 |
| # |
| # Unless required by applicable law or agreed to in writing, software |
| # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| # License for the specific language governing permissions and limitations |
| # under the License. |
| |
| import logging |
| from six.moves import urllib |
| |
| import voluptuous as v |
| |
| from zuul.connection import BaseConnection |
| |
| |
| class GitConnection(BaseConnection): |
| driver_name = 'git' |
| log = logging.getLogger("connection.git") |
| |
| def __init__(self, driver, connection_name, connection_config): |
| super(GitConnection, self).__init__(driver, connection_name, |
| connection_config) |
| if 'baseurl' not in self.connection_config: |
| raise Exception('baseurl is required for git connections in ' |
| '%s' % self.connection_name) |
| self.baseurl = self.connection_config.get('baseurl') |
| self.canonical_hostname = self.connection_config.get( |
| 'canonical_hostname') |
| if not self.canonical_hostname: |
| r = urllib.parse.urlparse(self.baseurl) |
| if r.hostname: |
| self.canonical_hostname = r.hostname |
| else: |
| self.canonical_hostname = 'localhost' |
| self.projects = {} |
| |
| def getProject(self, name): |
| return self.projects.get(name) |
| |
| def addProject(self, project): |
| self.projects[project.name] = project |
| |
| def getProjectBranches(self, project): |
| # TODO(jeblair): implement; this will need to handle local or |
| # remote git urls. |
| raise NotImplemented() |
| |
| def getGitUrl(self, project): |
| url = '%s/%s' % (self.baseurl, project.name) |
| return url |
| |
| |
| def getSchema(): |
| git_connection = v.Any(str, v.Schema(dict)) |
| return git_connection |