1234567891011121314151617181920212223242526272829303132333435 |
- # read server controller
- import re
- if __name__ == '__main__':
- with open('server_controller.py', 'r') as file:
- text = file.read().replace('\n', '')
- text = text.split('def ')
- del text[0]
- documentation = '''# the general syntax is
- # {attribute1: value, attribute2: value, ...}
- #
- # for example a valid request to /register would look like
- # {"email": "user123@example.org", "username": "user123", "password": "FILTERED", "preferred_language": "german"}
- # while a valid request to /events would be the empty object {}
- \n'''
- for method in sorted(text):
- method = 'def ' + method
- method_name = re.search(r"def (.*?)\s*\(", method)[1]
- if method_name[0] == '_':
- continue
- directly_used_arguments = re.findall(r"json_request\['(.*?)'\]", method)
- missing_attributes = re.search(r"missing_attributes\(json_request, \[((.|\n)*?)\]\)", method)
- if missing_attributes is None:
- print('HINT: method', method_name, 'does not require any parameters')
- required_arguments = []
- else:
- required_arguments = re.findall(r"'(.*?)'", missing_attributes[0])
- required_arguments = sorted(list(set(required_arguments)))
- possible_arguments = sorted(list(set(directly_used_arguments + required_arguments)))
- documentation += method_name + '_required_attributes = ' + str(required_arguments) + '\n'
- documentation += method_name + '_possible_attributes = ' + str(possible_arguments) + '\n\n'
- with open("doc/documentation.py", "w", newline='\n') as file:
- file.write(documentation[:-1])
- print(documentation)
|