Add user-agent and version

Send the gertty version in the user-agent header.  Also add a
--version command argument.

Change-Id: I83a3330550497d3d45d5b34608058ece66590d4b
This commit is contained in:
James E. Blair 2014-08-30 11:19:45 -07:00
parent f47275022b
commit fe8c123407
3 changed files with 33 additions and 2 deletions

View File

@ -357,6 +357,10 @@ class App(object):
self.log.debug("Open URL %s" % url)
webbrowser.open_new_tab(url)
def version():
from gertty.version import version_info as gertty_version_info
return "Gertty version: %s" % gertty_version_info.version_string()
def main():
parser = argparse.ArgumentParser(
description='Console client for Gerrit Code Review.')
@ -367,6 +371,9 @@ def main():
parser.add_argument('--fetch-missing-refs', dest='fetch_missing_refs',
action='store_true',
help='fetch any refs missing from local repos')
parser.add_argument('--version', dest='version', action='version',
version=version(),
help='show zuul version')
parser.add_argument('-p', dest='palette', default='default',
help='Color palette to use')
parser.add_argument('-k', dest='keymap', default='default',

View File

@ -30,6 +30,9 @@ try:
except:
pass
import requests
import requests.utils
import gertty.version
HIGH_PRIORITY=0
NORMAL_PRIORITY=1
@ -563,6 +566,8 @@ class UploadReviewTask(Task):
class Sync(object):
def __init__(self, app):
self.user_agent = 'Gertty/%s %s' % (gertty.version.version_info.version_string(),
requests.utils.default_user_agent())
self.offline = False
self.app = app
self.log = logging.getLogger('gertty.sync')
@ -632,7 +637,8 @@ class Sync(object):
verify=self.app.config.verify_ssl,
auth=self.auth,
headers = {'Accept': 'application/json',
'Accept-Encoding': 'gzip'})
'Accept-Encoding': 'gzip',
'User-Agent': self.user_agent})
self.log.debug('Received: %s' % (r.text,))
ret = json.loads(r.text[4:])
return ret
@ -644,7 +650,8 @@ class Sync(object):
r = self.session.post(url, data=json.dumps(data).encode('utf8'),
verify=self.app.config.verify_ssl,
auth=self.auth,
headers = {'Content-Type': 'application/json;charset=UTF-8'})
headers = {'Content-Type': 'application/json;charset=UTF-8',
'User-Agent': self.user_agent})
self.log.debug('Received: %s' % (r.text,))
def syncSubscribedProjects(self):

17
gertty/version.py Normal file
View File

@ -0,0 +1,17 @@
# Copyright 2014 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 pbr.version
version_info = pbr.version.VersionInfo('gertty')