summaryrefslogtreecommitdiff
path: root/rbtools
diff options
context:
space:
mode:
authorChristian Hammond <chipx86@chipx86.com>2009-12-20 03:19:19 -0800
committerChristian Hammond <chipx86@chipx86.com>2009-12-20 03:19:19 -0800
commita39e3f27d01594f9cd58f4727723a7d5c1c544b1 (patch)
treecfd26aadea38bb8cf08d50d1886416fad6a920e3 /rbtools
parentb94f94b12f1aff7f35a2f58adfbb7b686044b995 (diff)
Support server aliases for Perforce.
Some Perforce setups have DNS aliases for a Perforce server. We currently fetch the server aliases, but weren't doing anything with them. Now we support scanning a list of aliases against the known list of repositories on Review Board in order to find the right repository URL to use. This happens automatically without any additional configuration. Patch by Ravi Kondamuru Reviewed at http://reviews.reviewboard.org/r/1235/
Diffstat (limited to 'rbtools')
-rwxr-xr-xrbtools/postreview.py44
1 files changed, 39 insertions, 5 deletions
diff --git a/rbtools/postreview.py b/rbtools/postreview.py
index 2df2bb0..34c4591 100755
--- a/rbtools/postreview.py
+++ b/rbtools/postreview.py
@@ -367,8 +367,23 @@ class ReviewBoardServer(object):
the submitter of the review request (given that the logged in user has
the appropriate permissions).
"""
+
+ # If repository_path is a list, find a name in the list that's
+ # registered on the server.
+ if isinstance(self.info.path, list):
+ repositories = self.get_repositories()
+
+ debug("Repositories on Server: %s" % repositories)
+ debug("Server Aliases: %s" % self.info.path)
+
+ for repository in repositories:
+ if repository['path'] in self.info.path:
+ self.info.path = repository['path']
+ break
+
try:
- debug("Attempting to create review request for %s" % changenum)
+ debug("Attempting to create review request on %s for %s" %
+ (self.info.path, changenum))
data = { 'repository_path': self.info.path }
if changenum:
@@ -664,9 +679,20 @@ class SCMClient(object):
if not isinstance(trees, dict):
die("Warning: 'TREES' in config file is not a dict!")
- if repository_info.path in trees and \
- 'REVIEWBOARD_URL' in trees[repository_info.path]:
- return trees[repository_info.path]['REVIEWBOARD_URL']
+ # If repository_info is a list, check if any one entry is in trees.
+ path = None
+
+ if isinstance(repository_info.path, list):
+ for path in repository_info.path:
+ if path in trees:
+ break
+ else:
+ path = None
+ elif repository_info.path in trees:
+ path = repository_info.path
+
+ if path and 'REVIEWBOARD_URL' in trees[path]:
+ return trees[path]['REVIEWBOARD_URL']
return None
@@ -1293,7 +1319,15 @@ class PerforceClient(SCMClient):
try:
hostname, port = repository_path.split(":")
info = socket.gethostbyaddr(hostname)
- repository_path = "%s:%s" % (info[0], port)
+
+ # If aliases exist for hostname, create a list of alias:port
+ # strings for repository_path.
+ if info[1]:
+ servers = [info[0]] + info[1]
+ repository_path = ["%s:%s" % (server, port)
+ for server in servers]
+ else:
+ repository_path = "%s:%s" % (info[0], port)
except (socket.gaierror, socket.herror):
pass