X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=PLC%2FMethods%2F__init__.py;h=9b6645bf5e23939d52d24582d9f42b416ec5d539;hb=24f0a4528061afbca3299e92005bb19e631b323a;hp=d72755e162f3a75ce691e310d68485322bd1b73d;hpb=399edf0617befa056249184aae43d89561ef6147;p=plcapi.git diff --git a/PLC/Methods/__init__.py b/PLC/Methods/__init__.py index d72755e..9b6645b 100644 --- a/PLC/Methods/__init__.py +++ b/PLC/Methods/__init__.py @@ -1,20 +1,32 @@ #!/usr/bin/python -tt +from __future__ import print_function + import os +import glob + native_methods = [] toppath = os.path.dirname(__file__) -for path, dirs, methods in os.walk(toppath): - remove_dirs = [] - for dir in dirs: - if dir.startswith("."): - remove_dirs.append(dir) - for dir in remove_dirs: - dirs.remove(dir) - prefix = path + "/" - prefix = prefix[len(toppath) + 1:].replace("/", ".") - for method in methods: - if method == "__init__.py": - continue - if not method.endswith(".py"): - continue - native_methods.append(prefix + method[:-3]) + +# do not blindly scan this directory, as when using devel tools +# like `make sync` we can easily end up with more files than needed +# which breaks in production + +contents = [ + ('.', '[A-Z][a-zA-Z]*.py'), + ('system', '[a-zA-Z]*.py'), +] + +for dir, pattern in contents: + matches = glob.glob("{}/{}/{}".format(toppath, dir, pattern)) + # count 2 slashes + prefix = len(toppath) + 1 + len(dir) + 1 + for match in matches: + filename = match[prefix:][:-3] + python_name = filename if dir == '.' \ + else "{}.{}".format(dir, filename) + native_methods.append(python_name) + +if __name__ == '__main__': + native_methods.sort() + print(native_methods)