Author: kwall
Date: Sun Feb 22 08:20:35 2015
New Revision: 1661459

URL: http://svn.apache.org/r1661459
Log:
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

Modified:
    qpid/trunk/qpid/python/qpid/client.py
    qpid/trunk/qpid/python/qpid/tests/util.py
    qpid/trunk/qpid/python/qpid/util.py

Modified: qpid/trunk/qpid/python/qpid/client.py
URL: 
http://svn.apache.org/viewvc/qpid/trunk/qpid/python/qpid/client.py?rev=1661459&r1=1661458&r2=1661459&view=diff
==============================================================================
--- qpid/trunk/qpid/python/qpid/client.py (original)
+++ qpid/trunk/qpid/python/qpid/client.py Sun Feb 22 08:20:35 2015
@@ -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)

Modified: qpid/trunk/qpid/python/qpid/tests/util.py
URL: 
http://svn.apache.org/viewvc/qpid/trunk/qpid/python/qpid/tests/util.py?rev=1661459&r1=1661458&r2=1661459&view=diff
==============================================================================
--- qpid/trunk/qpid/python/qpid/tests/util.py (original)
+++ qpid/trunk/qpid/python/qpid/tests/util.py Sun Feb 22 08:20:35 2015
@@ -21,26 +21,32 @@ from qpid.util import get_client_propert
 
 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"])
-

Modified: qpid/trunk/qpid/python/qpid/util.py
URL: 
http://svn.apache.org/viewvc/qpid/trunk/qpid/python/qpid/util.py?rev=1661459&r1=1661458&r2=1661459&view=diff
==============================================================================
--- qpid/trunk/qpid/python/qpid/util.py (original)
+++ qpid/trunk/qpid/python/qpid/util.py Sun Feb 22 08:20:35 2015
@@ -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(),



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@qpid.apache.org
For additional commands, e-mail: commits-h...@qpid.apache.org

Reply via email to