[asterisk-commits] mjordan: testsuite/asterisk/trunk r3022 - in /asterisk/trunk: asttest/lib/lua...
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Sat Jan 28 21:46:44 CST 2012
Author: mjordan
Date: Sat Jan 28 21:46:40 2012
New Revision: 3022
URL: http://svnview.digium.com/svn/testsuite?view=rev&rev=3022
Log:
Update asttest's version parsing
Asterisk no longer provides a header file with the version defined in it.
The previous mechanism of parsing this file no longer work. Previously,
in r3021, the python library's mechanism of parsing this was updated
to obtain the version from the installed Asterisk binary; this patch
adds that functionality to asttest's lua library as well. It also addresses
some minor points from the python review. See
https://reviewboard.asterisk.org/r/1695/
Review: https://reviewboard.asterisk.org/r/1701/
Modified:
asterisk/trunk/asttest/lib/lua/astlib.lua
asterisk/trunk/lib/python/asterisk/version.py
Modified: asterisk/trunk/asttest/lib/lua/astlib.lua
URL: http://svnview.digium.com/svn/testsuite/asterisk/trunk/asttest/lib/lua/astlib.lua?view=diff&rev=3022&r1=3021&r2=3022
==============================================================================
--- asterisk/trunk/asttest/lib/lua/astlib.lua (original)
+++ asterisk/trunk/asttest/lib/lua/astlib.lua Sat Jan 28 21:46:40 2012
@@ -29,22 +29,15 @@
function version(ver)
local version = ver or _version()
if version == "unknown" then
- -- read version from path .. /usr/include/asterisk/version.h
- local f, err = io.open(path .. "/usr/include/asterisk/version.h")
- if not f then
- error("error determining asterisk verison; unable to open version.h: " .. err)
- end
-
- for line in f:lines() do
- version = line:match('ASTERISK_VERSION%s"([^"]+)"')
- if version then
- break
- end
- end
- f:close()
-
+ -- read version from Asterisk
+ local ast = proc.exec_io("asterisk", "-V")
+ if not ast then
+ error("error determining asterisk version; unable to execute asterisk -V")
+ end
+ version = ast.stdout:read("*all")
+ version = string.gsub(version,"Asterisk ", "")
if not version then
- error("error determining asterisk version; version not found in version.h")
+ error("error determining asterisk version")
end
end
return asterisk_version:new(version)
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=3022&r1=3021&r2=3022
==============================================================================
--- asterisk/trunk/lib/python/asterisk/version.py (original)
+++ asterisk/trunk/lib/python/asterisk/version.py Sat Jan 28 21:46:40 2012
@@ -34,38 +34,12 @@
version -- The Asterisk version string to parse.
"""
self.svn = False
-
- if version is None and AsteriskVersion.ast_version == '':
- self.ast_binary = utils.which("asterisk") or "/usr/sbin/asterisk"
- cmd = [
- self.ast_binary,
- "-V",
- ]
-
- try:
- process = subprocess.Popen(cmd, stdout=subprocess.PIPE,
- stderr=subprocess.STDOUT)
- except OSError:
- print "Failed to execute command: %s" % str(cmd)
- return
-
- try:
- AsteriskVersion.ast_version = process.stdout.read()
- except OSError:
- print "Failed to execute command: %s" % str(cmd)
- return
-
- AsteriskVersion.ast_version = AsteriskVersion.ast_version.replace("Asterisk ", "")
- self.version_str = AsteriskVersion.ast_version
-
- elif version is not None:
+ self.__get_asterisk_version_from_binary()
+
+ if version is not None:
self.version_str = version
-
else:
self.version_str = AsteriskVersion.ast_version
-
- if not self.version_str:
- return
if self.version_str[:3] == "SVN":
self.__parse_svn_version()
@@ -74,6 +48,29 @@
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:
More information about the asterisk-commits
mailing list