summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSzczepan Zalega <szczepan@nitrokey.com>2018-01-04 20:14:42 +0100
committerSzczepan Zalega <szczepan@nitrokey.com>2018-01-04 20:14:42 +0100
commit57621cf96960a4e64a25383b50f8876183f632f6 (patch)
tree8fe5a3c09d302a844dea1c61f6c12453d6d9c7e7
parent09f80ac4123a2bc02737f19faecb8f2935599cd5 (diff)
downloadlibnitrokey-57621cf96960a4e64a25383b50f8876183f632f6.tar.gz
libnitrokey-57621cf96960a4e64a25383b50f8876183f632f6.tar.bz2
Use correct filtering of C API symbols from C header
Recently the C API header was reformatted by adding more white-spaces, though the filtering function from example was not adjusted to it. Now the lines are stripped before further processing. Fixes #82 Signed-off-by: Szczepan Zalega <szczepan@nitrokey.com>
-rwxr-xr-xpython_bindings_example.py14
1 files changed, 9 insertions, 5 deletions
diff --git a/python_bindings_example.py b/python_bindings_example.py
index 37b70b8..1740a76 100755
--- a/python_bindings_example.py
+++ b/python_bindings_example.py
@@ -25,14 +25,18 @@ def get_library():
with open(fp, 'r') as f:
declarations = f.readlines()
+ cnt = 0
a = iter(declarations)
for declaration in a:
- if declaration.startswith('NK_C_API'):
+ if declaration.strip().startswith('NK_C_API'):
declaration = declaration.replace('NK_C_API', '').strip()
- while not ';' in declaration:
+ while ';' not in declaration:
declaration += (next(a)).strip()
- #print(declaration)
+ # print(declaration)
ffi.cdef(declaration, override=True)
+ cnt +=1
+ print('Imported {} declarations'.format(cnt))
+
C = None
import os, sys
@@ -68,10 +72,10 @@ a = raw_input()
if not a == 'continue':
exit()
-ADMIN = raw_input('Please enter your admin PIN (empty string uses 12345678)')
+ADMIN = raw_input('Please enter your admin PIN (empty string uses 12345678) ')
ADMIN = ADMIN or '12345678' # use default if empty string
-show_log = raw_input('Should log messages be shown (please write "yes" to enable)?') == 'yes'
+show_log = raw_input('Should log messages be shown (please write "yes" to enable)? ') == 'yes'
libnitrokey = get_library()
libnitrokey.NK_set_debug(show_log) # do not show debug messages