#!/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)))