[svn-commits] wdoekes: testsuite/asterisk/trunk r3026 - /asterisk/trunk/lib/python/asterisk/

SVN commits to the Digium repositories svn-commits at lists.digium.com
Mon Jan 30 14:06:24 CST 2012


Author: wdoekes
Date: Mon Jan 30 14:06:21 2012
New Revision: 3026

URL: http://svnview.digium.com/svn/testsuite?view=rev&rev=3026
Log:
Clean up get_asterisk_version_from_binary just a little bit.

No functional change, apart from not calling the binary at all when
supplying a custom version. Couldn't help myself.

Modified:
    asterisk/trunk/lib/python/asterisk/version.py

Modified: asterisk/trunk/lib/python/asterisk/version.py
URL: http://svnview.digium.com/svn/testsuite/asterisk/trunk/lib/python/asterisk/version.py?view=diff&rev=3026&r1=3025&r2=3026
==============================================================================
--- asterisk/trunk/lib/python/asterisk/version.py (original)
+++ asterisk/trunk/lib/python/asterisk/version.py Mon Jan 30 14:06:21 2012
@@ -25,8 +25,6 @@
 
     This class handles Asterisk version strings.
     """
-    ast_version = ''
-
     def __init__(self, version=None):
         """Construct an Asterisk Version parser.
 
@@ -34,12 +32,11 @@
         version -- The Asterisk version string to parse.
         """
         self.svn = False
-        self.__get_asterisk_version_from_binary()
 
         if version is not None:
             self.version_str = version
         else:
-            self.version_str = AsteriskVersion.ast_version
+            self.version_str = self.get_asterisk_version_from_binary()
 
         if self.version_str[:3] == "SVN":
             self.__parse_svn_version()
@@ -48,29 +45,6 @@
 
     def __str__(self):
         return self.version_str
-
-    @classmethod
-    def __get_asterisk_version_from_binary(cls):
-        """
-        Obtain the version from Asterisk and store in a class variable
-        """
-        if (AsteriskVersion.ast_version):
-            return
-        version = ""
-        ast_binary = utils.which("asterisk") or "/usr/sbin/asterisk"
-        cmd = [
-            ast_binary,
-            "-V",
-        ]
-
-        try:
-            process = subprocess.Popen(cmd, stdout=subprocess.PIPE,
-                    stderr=subprocess.STDOUT)
-            version = process.stdout.read()
-        except OSError as oe:
-            logger.error("OSError [%d]: %s" % (oe.errno, oe.strerror))
-            raise
-        AsteriskVersion.ast_version = version.replace("Asterisk ", "")
 
     def __int__(self):
         if self.svn is True:
@@ -140,8 +114,8 @@
         ret = int(parts[0])
         if len(parts) >= 2:
             versions = [
-                ['rc', 100],
-                ['beta', 10],
+                ["rc", 100],
+                ["beta", 10],
             ]
             for v, cost in versions:
                 match = re.search(
@@ -156,6 +130,30 @@
 
         return ret
 
+    @classmethod
+    def get_asterisk_version_from_binary(cls):
+        """
+        Obtain the version from Asterisk and return (a cached version of) it
+        """
+        if not hasattr(cls, "_asterisk_version_from_binary"):
+            version = ""
+            ast_binary = utils.which("asterisk") or "/usr/sbin/asterisk"
+            cmd = [
+                ast_binary,
+                "-V",
+            ]
+
+            try:
+                process = subprocess.Popen(cmd, stdout=subprocess.PIPE,
+                        stderr=subprocess.STDOUT)
+                version = process.stdout.read()
+            except OSError as oe:
+                logger.error("OSError [%d]: %s" % (oe.errno, oe.strerror))
+                raise
+
+            cls._asterisk_version_from_binary = version.replace("Asterisk ", "")
+        return cls._asterisk_version_from_binary
+
 
 class AsteriskVersionTests(unittest.TestCase):
     def test_version(self):




More information about the svn-commits mailing list