From bb5263996f655225de56d0af467de2b166865634 Mon Sep 17 00:00:00 2001 From: Keith Wall Date: Sun, 22 Feb 2015 08:20:35 +0000 Subject: QPID-6405: [Python Client] Retreive package version number from pkg_resources and report to the peer at connection time using version/qpid.client_version connection property git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk@1661459 13f79535-47bb-0310-9956-ffa450edef68 --- qpid/python/qpid/client.py | 2 +- qpid/python/qpid/tests/util.py | 22 ++++++++++++++-------- qpid/python/qpid/util.py | 13 ++++++++++--- 3 files changed, 25 insertions(+), 12 deletions(-) (limited to 'qpid/python') diff --git a/qpid/python/qpid/client.py b/qpid/python/qpid/client.py index b0ce5d9009..fbec7ccc7d 100644 --- a/qpid/python/qpid/client.py +++ b/qpid/python/qpid/client.py @@ -89,7 +89,7 @@ class Client: self.password = password self.locale = locale self.tune_params = tune_params - self.client_properties=get_client_properties_with_defaults(provided_client_properties=client_properties) + self.client_properties=get_client_properties_with_defaults(provided_client_properties=client_properties, version_property_key="version") self.sasl_options = sasl_options self.socket = connect(self.host, self.port, connection_options) self.conn = Connection(self.socket, self.spec) diff --git a/qpid/python/qpid/tests/util.py b/qpid/python/qpid/tests/util.py index 9777443720..4e901218c2 100644 --- a/qpid/python/qpid/tests/util.py +++ b/qpid/python/qpid/tests/util.py @@ -21,26 +21,32 @@ from qpid.util import get_client_properties_with_defaults class UtilTest (TestCase): - def test_get_spec_recommended_client_properties(self): - client_properties = get_client_properties_with_defaults(provided_client_properties={"mykey":"myvalue"}) + def test_default_client_properties_08091(self): + client_properties = get_client_properties_with_defaults(version_property_key="version") self.assertTrue("product" in client_properties) self.assertTrue("version" in client_properties) self.assertTrue("platform" in client_properties) - def test_get_client_properties_with_provided_value(self): + def test_default_client_properties_010(self): + client_properties = get_client_properties_with_defaults(version_property_key="qpid.client_version") + self.assertTrue("product" in client_properties) + self.assertTrue("qpid.client_version" in client_properties) + self.assertTrue("platform" in client_properties) + + def test_client_properties_with_provided_value(self): client_properties = get_client_properties_with_defaults(provided_client_properties={"mykey":"myvalue"}) self.assertTrue("product" in client_properties) self.assertTrue("mykey" in client_properties) self.assertEqual("myvalue", client_properties["mykey"]) - def test_get_client_properties_with_no_provided_values(self): + def test_client_properties_with_provided_value_that_overrides_default(self): + client_properties = get_client_properties_with_defaults(provided_client_properties={"product":"myproduct"}) + self.assertEqual("myproduct", client_properties["product"]) + + def test_client_properties_with_no_provided_values(self): client_properties = get_client_properties_with_defaults(provided_client_properties=None) self.assertTrue("product" in client_properties) client_properties = get_client_properties_with_defaults() self.assertTrue("product" in client_properties) - def test_get_client_properties_with_provided_value_that_overrides_default(self): - client_properties = get_client_properties_with_defaults(provided_client_properties={"version":"myversion"}) - self.assertEqual("myversion", client_properties["version"]) - diff --git a/qpid/python/qpid/util.py b/qpid/python/qpid/util.py index 37d999b771..fb343b536a 100644 --- a/qpid/python/qpid/util.py +++ b/qpid/python/qpid/util.py @@ -17,7 +17,7 @@ # under the License. # -import os, socket, time, textwrap, re, sys +import os, socket, time, textwrap, re, sys, pkg_resources try: from ssl import wrap_socket as ssl @@ -42,15 +42,22 @@ except ImportError: def close(self): self.sock.close() -def get_client_properties_with_defaults(provided_client_properties={}): +def get_client_properties_with_defaults(provided_client_properties={}, version_property_key="qpid.client_version"): ppid = 0 + version = "unidentified" try: ppid = os.getppid() except: pass + try: + pkg = pkg_resources.require("qpid-python") + version = pkg[0].version if pkg and pkg[0] and pkg[0].version else version + except: + pass + client_properties = {"product": "qpid python client", - "version": "development", + version_property_key : version, "platform": os.name, "qpid.client_process": os.path.basename(sys.argv and sys.argv[0] or ''), "qpid.client_pid": os.getpid(), -- cgit v1.2.1