summaryrefslogtreecommitdiffstats
path: root/solenv/clang-format/remove_not_existent_files_from_clang_excludelist
blob: 89380381cf6ececc81a4851688f0386794bc4b88 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#!/usr/bin/python
# This file is part of the LibreOffice project.
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
# Reformat files which are not excluded. This is interesting if the
# clang-format version or config changes.
# -n allows just listing the formatted files.
	
import os
	
base_path_to_core = os.path.abspath("../../")
excludelist = "solenv/clang-format/excludelist"
	
def delete_line_in_excludelist(line_to_be_removed):
    with open(os.path.join(base_path_to_core, excludelist), "r") as f:
        lines = f.readlines()
    with open(os.path.join(base_path_to_core, excludelist), "w") as f:
        for line in lines:
            if line.strip("\n") != line_to_be_removed:
                f.write(line)
	
f = open(os.path.join(base_path_to_core, excludelist), "r")
lines = f.read().split("\n")
f.close()
del lines[len(lines)-1] # remove empty, last line
	
amount_lines_deleted = 0
	
for line in lines:
    if not os.path.isfile(os.path.join(base_path_to_core, line)):
        print("Deleting file {} in excludelist".format(line))
        delete_line_in_excludelist(line)
        amount_lines_deleted += 1
	
print("Removed {} lines in {}".format(amount_lines_deleted, os.path.join(base_path_to_core, excludelist)))