1#!/usr/local/bin/python3.8
2
3# This file is part of the LibreOffice project.
4#
5# This Source Code Form is subject to the terms of the Mozilla Public
6# License, v. 2.0. If a copy of the MPL was not distributed with this
7# file, You can obtain one at http://mozilla.org/MPL/2.0/.
8
9import os
10import datetime
11
12def analyze_file(filename):
13    class_name = ""
14    method_list = []
15    with open(filename, encoding='utf-8') as fh:
16        for line in fh:
17            if line.lstrip().startswith('class '):
18                class_name = line.lstrip().split(" ")[1].split("(")[0]
19            elif line.lstrip().startswith('def test_'):
20                method_list.append(
21                        line.lstrip().split("test_")[1].split("(")[0])
22            else:
23                continue
24    return class_name, method_list
25
26def get_files_list(directory, extension):
27    array_items = []
28
29    dh = os.scandir(directory)
30    for entry in dh:
31        if entry.is_dir():
32            array_items += get_files_list(entry.path, extension)
33        elif entry.is_file():
34            if entry.name.endswith(extension):
35                array_items.append(entry.path)
36
37    return array_items
38
39def linkFormat(name):
40    if name.startswith('tdf'):
41        return "[https://bugs.documentfoundation.org/show_bug.cgi?id={} {}]"\
42                .format(name.split('tdf')[1], name)
43    else:
44        return name
45
46
47def main():
48    uitest_ext = '.py'
49    uitest_dirs = {
50            'Writer' : ['../uitest/writer_tests/', '../writerperfect/qa/uitest/', '../sw/qa/uitest/'],
51            'Calc' : ['../uitest/calc_tests', '../sc/qa/uitest/'],
52            'Impress' : ['../uitest/impress_tests/', '../sd/qa/uitest/'],
53            'Math': ['../uitest/math_tests/'],
54            'Draw': [''],
55            'Manual_tests': ['../uitest/manual_tests/']}
56
57    print('{{TopMenu}}')
58    print('{{Menu}}')
59    print('{{Menu.Development}}')
60    print('{{OrigLang|}}')
61    print()
62    print('Generated on ' + str(datetime.datetime.now()))
63    for k,v in uitest_dirs.items():
64        print('\n=== ' + k + ' ===')
65        for uitest_dir in v:
66            if uitest_dir:
67                uitest_files = get_files_list(uitest_dir, uitest_ext)
68                for uitest_file in uitest_files:
69                    class_name, method_names = analyze_file(uitest_file)
70                    if class_name:
71                        print("* {} ({})".format(
72                            linkFormat(class_name),uitest_file[3:]))
73                        for m in method_names:
74                            print('**' + linkFormat(m))
75    print()
76    print('[[Category:QA]][[Category:Development]]')
77
78if __name__ == '__main__':
79    main()
80