Path: blob/master/tools/maintenance/copyright_update.rb
1154 views
require 'yaml'1require 'logger'23# Set up logging4@log = Logger.new(STDOUT)5@log.level = Logger::INFO6log_file = File.open('copyright_update.log', 'w')7@log_file_logger = Logger.new(log_file)8@log_file_logger.level = Logger::INFO910def update_copyright(file_path, old_copyright, new_copyright)11@log.info("Processing file: #{file_path}")12@log_file_logger.info("Processing file: #{file_path}")1314# Treat all files the same way for copyright update, including YAML and CSS15content = File.read(file_path)16if content.empty?17@log.info("File is empty, no copyright update needed: #{file_path}")18@log_file_logger.info("File is empty, no copyright update needed: #{file_path}")19else20if content.include?(old_copyright)21updated_content = content.gsub(old_copyright, new_copyright)22File.write(file_path, updated_content)23@log.info("Updated copyright in #{file_path}")24@log_file_logger.info("Updated copyright in #{file_path}")25else26@log.warn("Copyright string not found in #{file_path}")27@log_file_logger.warn("Copyright string not found in #{file_path}")28end29end30rescue => e31@log.error("Error processing file #{file_path}: #{e.message}")32@log_file_logger.error("Error processing file #{file_path}: #{e.message}")33end3435old_copyright = 'Copyright (c) 2006-2024'36new_copyright = 'Copyright (c) 2006-2025'3738Dir.glob("../../**/*.{rb,js,yaml,html,md,txt,css,c,nasm,java,php,as}").each do |file|39next if File.basename(file) == 'copyright_update.rb' # Skip this file40update_copyright(file, old_copyright, new_copyright)41end4243# Handle files without extensions, excluding copyright_update.rb44Dir.glob("../../**/*").reject { |f|45File.directory?(f) || File.extname(f) != '' || File.basename(f) == 'copyright_update.rb'46}.each do |file|47update_copyright(file, old_copyright, new_copyright)48end4950@log.info("Copyright update process completed.")51@log_file_logger.info("Copyright update process completed.")52log_file.close5354