Commit 2653c7e0 authored by Matthias Putz's avatar Matthias Putz

further improvement of review url selection

parent cca15f81
...@@ -594,28 +594,34 @@ class Remote(object): ...@@ -594,28 +594,34 @@ class Remote(object):
protocolSeperator = "://" protocolSeperator = "://"
protocolSepIndex = u.find(protocolSeperator) protocolSepIndex = u.find(protocolSeperator)
if protocolSepIndex == -1: if protocolSepIndex == -1:
http_url = 'http://%s' % u protocols = ["http", "https"]
for prefix in protocols:
http_url = '%s://%s' % (prefix, u)
info_url = http_url + 'ssh_info' info_url = http_url + 'ssh_info'
info = None
try:
info = portable.stream2str(urllib.request.urlopen(info_url).read()) info = portable.stream2str(urllib.request.urlopen(info_url).read())
if '<' in info: if '<' in info:
# Assume the server gave us some sort of HTML # Assume the server gave us some sort of HTML
# response back, like maybe a login page. # response back, like maybe a login page.
# #
try:
raise UploadError('%s: Cannot parse response' % info_url) raise UploadError('%s: Cannot parse response' % info_url)
if info != 'NOT_AVAILABLE':
host, port = info.split()
self._review_url = self._SshReviewUrl(userEmail, host, port)
except Exception as e: except Exception as e:
Trace("could not get ssh infos of %s from %s", u, info_url) Trace("could not get ssh infos of %s from %s (received %s), error %s", u, info_url, info, e)
info = 'NOT_AVAILABLE' info = 'NOT_AVAILABLE'
if info == 'NOT_AVAILABLE': if not self._review_url:
# Assume HTTP if SSH is not enabled. # Assume HTTP if SSH is not enabled.
self._review_url = http_url + 'p/' self._review_url = http_url + 'p/'
Trace( Trace(
"warning: proceed upload with http url %s since no protocol given and no infos could be retrieved from %s", "warning: proceed upload with http url %s since no protocol given and no infos could be retrieved from %s",
self._review_url, info_url) self._review_url, info_url)
else:
host, port = info.split() print("detected %s as review url" % self._review_url)
self._review_url = self._SshReviewUrl(userEmail, host, port)
else: else:
self._review_url = u self._review_url = u
except urllib.error.HTTPError as e: except urllib.error.HTTPError as e:
......
...@@ -244,7 +244,9 @@ Gerrit Code Review: http://code.google.com/p/gerrit/ ...@@ -244,7 +244,9 @@ Gerrit Code Review: http://code.google.com/p/gerrit/
else x else x
for x in script] for x in script]
script = portable.stream2str(Editor.EditString("\n".join(script))).split("\n") script = Editor.EditString(b"\n".join(script))
script = script.split("\n")
project_re = re.compile(r'^#?\s*project\s*([^\s]+)/:$') project_re = re.compile(r'^#?\s*project\s*([^\s]+)/:$')
branch_re = re.compile(r'^\s*branch\s*([^\s(]+)\s*\(.*') branch_re = re.compile(r'^\s*branch\s*([^\s(]+)\s*\(.*')
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment