Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
beefproject
GitHub Repository: beefproject/beef
Path: blob/master/tools/maintenance/copyright_update.rb
1154 views
1
require 'yaml'
2
require 'logger'
3
4
# Set up logging
5
@log = Logger.new(STDOUT)
6
@log.level = Logger::INFO
7
log_file = File.open('copyright_update.log', 'w')
8
@log_file_logger = Logger.new(log_file)
9
@log_file_logger.level = Logger::INFO
10
11
def update_copyright(file_path, old_copyright, new_copyright)
12
@log.info("Processing file: #{file_path}")
13
@log_file_logger.info("Processing file: #{file_path}")
14
15
# Treat all files the same way for copyright update, including YAML and CSS
16
content = File.read(file_path)
17
if content.empty?
18
@log.info("File is empty, no copyright update needed: #{file_path}")
19
@log_file_logger.info("File is empty, no copyright update needed: #{file_path}")
20
else
21
if content.include?(old_copyright)
22
updated_content = content.gsub(old_copyright, new_copyright)
23
File.write(file_path, updated_content)
24
@log.info("Updated copyright in #{file_path}")
25
@log_file_logger.info("Updated copyright in #{file_path}")
26
else
27
@log.warn("Copyright string not found in #{file_path}")
28
@log_file_logger.warn("Copyright string not found in #{file_path}")
29
end
30
end
31
rescue => e
32
@log.error("Error processing file #{file_path}: #{e.message}")
33
@log_file_logger.error("Error processing file #{file_path}: #{e.message}")
34
end
35
36
old_copyright = 'Copyright (c) 2006-2024'
37
new_copyright = 'Copyright (c) 2006-2025'
38
39
Dir.glob("../../**/*.{rb,js,yaml,html,md,txt,css,c,nasm,java,php,as}").each do |file|
40
next if File.basename(file) == 'copyright_update.rb' # Skip this file
41
update_copyright(file, old_copyright, new_copyright)
42
end
43
44
# Handle files without extensions, excluding copyright_update.rb
45
Dir.glob("../../**/*").reject { |f|
46
File.directory?(f) || File.extname(f) != '' || File.basename(f) == 'copyright_update.rb'
47
}.each do |file|
48
update_copyright(file, old_copyright, new_copyright)
49
end
50
51
@log.info("Copyright update process completed.")
52
@log_file_logger.info("Copyright update process completed.")
53
log_file.close
54