kuuko pushed a commit to branch master.
commit 2cb20da28780e7c7cec700cbb30588e8f4555a3c
Author: Kai Huuhko <[email protected]>
Date: Sat Apr 6 14:38:20 2013 +0300
Add py2/3 compatibility code to API coverage script
---
api_coverage.py | 45 +++++++++++++++++++++++++++++++--------------
1 file changed, 31 insertions(+), 14 deletions(-)
diff --git a/api_coverage.py b/api_coverage.py
index 9c5d305..2e45949 100755
--- a/api_coverage.py
+++ b/api_coverage.py
@@ -26,32 +26,49 @@ def pkg_config(require, min_vers=None):
def get_capis(inc_path, prefix):
capis = []
+ capi_pattern = re.compile("^ *EAPI [A-Za-z_ *\n]+ +\**(?!" + c_excludes +
")(" + prefix + "_\w+) *\(", flags = re.S|re.M)
for path, dirs, files in os.walk(inc_path):
for f in files:
- with open(os.path.join(path, f), encoding="UTF-8", mode="r") as
header:
- capi = header.read()
- matches = re.finditer("^ *EAPI [A-Za-z_ *\n]+ +\**(?!" +
c_excludes + ")(" + prefix + "_\w+) *\(", capi, re.S|re.M)
- for match in matches:
- func = match.group(1)
- capis.append(func)
+ if sys.version_info[0] < 3:
+ header = open(os.path.join(path, f), mode="r")
+ else:
+ header = open(os.path.join(path, f), encoding="UTF-8",
mode="r")
+
+ capi = header.read()
+
+ matches = re.finditer(capi_pattern, capi)
+ for match in matches:
+ func = match.group(1)
+ capis.append(func)
+
+ header.close()
return capis
def get_pyapis(pxd_path, header_name, prefix):
pyapis = []
+ pyapi_pattern1 = re.compile('(cdef extern from "' + header_name +
'\.h":\n)(.+)', flags = re.S)
+ pyapi_pattern2 = re.compile("^ [a-zA-Z _*]+?(?!" + py_excludes + ")(" +
prefix + "_\w+)\(", flags = re.M)
for path, dirs, files in os.walk(pxd_path):
for f in files:
if f.endswith(".pxd"):
- with open(os.path.join(path, f), "r") as pxd:
- pyapi = pxd.read()
- cdef = re.search('(cdef extern from "' + header_name +
'\.h":\n)(.+)', pyapi, re.S)
- if cdef:
- matches = re.finditer("^ [a-zA-Z _*]+?(?!" +
py_excludes + ")(" + prefix + "_\w+)\(", cdef.group(2), re.M)
- for match in matches:
- func = match.group(1)
- pyapis.append(func)
+ if sys.version_info[0] < 3:
+ pxd = open(os.path.join(path, f), mode="r")
+ else:
+ pxd = open(os.path.join(path, f), encoding="UTF-8",
mode="r")
+
+ pyapi = pxd.read()
+
+ cdef = re.search(pyapi_pattern1, pyapi)
+ if cdef:
+ matches = re.finditer(pyapi_pattern2, cdef.group(2))
+ for match in matches:
+ func = match.group(1)
+ pyapis.append(func)
+
+ pxd.close()
return pyapis
--
------------------------------------------------------------------------------
Minimize network downtime and maximize team effectiveness.
Reduce network management and security costs.Learn how to hire
the most talented Cisco Certified professionals. Visit the
Employer Resources Portal
http://www.cisco.com/web/learning/employer_resources/index.html