-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Joel Marty
committed
Sep 16, 2013
0 parents
commit 8da3419
Showing
1 changed file
with
52 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
#!/usr/bin/env ruby | ||
# coding: utf-8 | ||
|
||
XML_MARKUP = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>" | ||
SVN_MARKUP = "<!--\n$Revision$\n$Date$\n-->" | ||
REV_PAT = /\$Revision\$/ | ||
SEARCH_PAT = /(<!DOCTYPE(.*?)\">|<\?xml.*\?>)/mi | ||
|
||
usage = "usage: \n svn_markup.rb \"/path/to/templates\"" | ||
|
||
# just checking script was called with path argument | ||
unless ARGV.length >= 1 | ||
puts "Wrong number of arguments" | ||
puts usage | ||
exit | ||
end | ||
|
||
path = ARGV[0] | ||
|
||
# is the given path real? | ||
if not File.directory? path | ||
puts "path is invalid" | ||
exit | ||
end | ||
|
||
dir = Dir.new path | ||
|
||
dir.each do |filename| | ||
#building absolute path, is there a better way to do this? | ||
absolute_path = %{#{dir.path}#{filename}} | ||
unless File.directory? File.new absolute_path | ||
begin | ||
content = File.read absolute_path | ||
unless REV_PAT.match content | ||
if SEARCH_PAT.match content | ||
replace = content.gsub(SEARCH_PAT) {|match| "#{match}\n#{SVN_MARKUP}"} | ||
message = "File #{filename} was tagged below header" | ||
else | ||
replace = "#{XML_MARKUP}\n#{SVN_MARKUP}\n#{content}" | ||
message = "File #{filename} was tagged with new header" | ||
end | ||
File.open(absolute_path, 'w') { |file| file.write(replace) } | ||
puts message | ||
else | ||
puts "#{filename} is already tagged" | ||
end | ||
rescue Exception => e | ||
puts e.message | ||
puts e.backtrace.inspect | ||
end | ||
end | ||
end |