bugfix, scanning native_methods needs to start in installed dir, not '.'
[plcapi.git] / PLC / Methods / __init__.py
1 #!/usr/bin/python -tt
2
3 from __future__ import print_function
4
5 import os
6 import glob
7
8 native_methods = []
9 toppath = os.path.dirname(__file__)
10
11 # do not blindly scan this directory, as when using devel tools
12 # like `make sync` we can easily end up with more files than needed
13 # which breaks in production
14
15 contents = [
16     ('.', '[A-Z][a-zA-Z]*.py'),
17     ('system', '[a-zA-Z]*.py'),
18 ]
19
20 for dir, pattern in contents:
21     matches = glob.glob("{}/{}/{}".format(toppath, dir, pattern))
22     # count 2 slashes
23     prefix = len(toppath) + 1 + len(dir) + 1
24     for match in matches:
25         filename = match[prefix:][:-3]
26         python_name = filename if dir == '.' \
27             else "{}.{}".format(dir, filename)
28         native_methods.append(python_name)
29
30 if __name__ == '__main__':
31     native_methods.sort()
32     print(native_methods)