diff --git a/gertty/app.py b/gertty/app.py index 2e844cc..cbf9abc 100644 --- a/gertty/app.py +++ b/gertty/app.py @@ -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', diff --git a/gertty/sync.py b/gertty/sync.py index 62b07a7..87dbd03 100644 --- a/gertty/sync.py +++ b/gertty/sync.py @@ -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): diff --git a/gertty/version.py b/gertty/version.py new file mode 100644 index 0000000..8d18ea3 --- /dev/null +++ b/gertty/version.py @@ -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')