-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Updating copyright per guidance from Alliance For Sustatianable Energy
- Loading branch information
Showing
4 changed files
with
144 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,142 @@ | ||
# Inserts copyright at beginning of each | ||
# | ||
# Inputs: | ||
# ARGV[0] - path to top level cmake source directory (one level above 'src' directory) | ||
|
||
require 'pathname' | ||
require 'rubygems' | ||
require 'fileutils' | ||
|
||
include FileUtils | ||
|
||
# check that called from command line directly | ||
if not ($0 == __FILE__) | ||
puts "#{__FILE__} called from external script" | ||
exit | ||
end | ||
|
||
basepath = ARGV[0].gsub("\\", "/") | ||
|
||
copyright = "/***********************************************************************************************************************\n" | ||
ruby_copyright = "########################################################################################################################\n" | ||
File.open(basepath + "/LICENSE.md") do |file| | ||
while (line = file.gets) | ||
if line.strip.empty? | ||
copyright += "*" + line | ||
ruby_copyright += "#" + line | ||
|
||
else | ||
copyright += "* " + line | ||
ruby_copyright += "# " + line | ||
end | ||
end | ||
end | ||
copyright += "***********************************************************************************************************************/\n\n" | ||
ruby_copyright += "########################################################################################################################\n\n" | ||
|
||
# first do c++ | ||
|
||
# exceptions are files that are not part of OpenStudio | ||
exceptions = [basepath + "/src/qtwinmigrate/", | ||
"mainpage.hpp"] | ||
|
||
# glob for hpp and cpp | ||
files = Dir.glob(basepath + "/src/**/*.[ch]pp") | ||
files.concat Dir.glob(basepath + "/ruby/**/*.[ch]pp") | ||
files.concat Dir.glob(basepath + "/src/**/*.cxx.in") | ||
files.concat Dir.glob(basepath + "/src/**/*.tmp") | ||
|
||
# reject exceptions | ||
files.reject! do |p| | ||
result = false | ||
exceptions.each do |e| | ||
if p.include?(e) | ||
result = true | ||
puts p | ||
break | ||
end | ||
end | ||
result | ||
end | ||
|
||
# loop over all files | ||
files.each do |p| | ||
|
||
# start with copyright | ||
text = copyright | ||
|
||
# read file | ||
File.open(p, "r") do |file| | ||
# read until end of current copyright | ||
while (line = file.gets) | ||
if not /^\s?[\/\*]/.match(line) | ||
if not line.chomp.empty? | ||
text += line | ||
end | ||
break | ||
end | ||
end | ||
|
||
# now keep rest of file | ||
while (line = file.gets) | ||
text += line | ||
end | ||
end | ||
|
||
# write file | ||
File.open(p, "w") do |file| | ||
file << text | ||
end | ||
|
||
end | ||
|
||
# now do ruby | ||
|
||
# exceptions are files that are not part of OpenStudio | ||
exceptions = [] | ||
|
||
# glob for rb | ||
files = Dir.glob(basepath + "/ruby/**/*.rb") | ||
|
||
# reject exceptions | ||
files.reject! do |p| | ||
result = false | ||
exceptions.each do |e| | ||
if p.include?(e) | ||
result = true | ||
break | ||
end | ||
end | ||
result | ||
end | ||
|
||
# loop over all files | ||
files.each do |p| | ||
|
||
# start with copyright | ||
text = ruby_copyright | ||
|
||
# read file | ||
File.open(p, "r") do |file| | ||
# read until end of current copyright | ||
while (line = file.gets) | ||
if not /^#/.match(line) | ||
if not line.chomp.empty? | ||
text += line | ||
end | ||
break | ||
end | ||
end | ||
|
||
# now keep rest of file | ||
while (line = file.gets) | ||
text += line | ||
end | ||
end | ||
|
||
# write file | ||
File.open(p, "w") do |file| | ||
file << text | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters