import os path = "../../lib" ignore = [".g.dart", "LICENSE", "external_api_keys.dart"] # To update the header, only change the variable below header = """/* * This file is part of Stack Wallet. * * Copyright (c) 2023 Cypher Stack * All Rights Reserved. * The code is distributed under GPLv3 license, see LICENSE file for details. * Generated by Cypher Stack on 2023-05-26 * */ """ def add_text_to_files(folder_path, text, ignored_extensions=[]): should_ignore = False for root, dirs, files in os.walk(folder_path): for filename in files: file_path = os.path.join(root, filename) should_ignore = False for ignored_extension in ignored_extensions: if file_path.endswith(ignored_extension): should_ignore = True break if not should_ignore: with open(file_path, 'r') as file: lines = file.readlines() if len(lines) >= 4: second_line = lines[0] third_line = lines[1] fourth_line = lines[2] if second_line.startswith("/*") and third_line.startswith(" *") and fourth_line.startswith(" *"): with open(file_path, 'w') as file: file.seek(0, 0) file.write(text + ''.join(lines[9:])) else: with open(file_path, 'w') as file: file.seek(0, 0) file.write(text + '\n' + ''.join(lines)) else: with open(file_path, 'w') as file: file.seek(0, 0) # Move the file cursor to the start file.write(text + '\n' + ''.join(lines)) add_text_to_files(path, header, ignore)