Created
July 25, 2012 14:49
-
-
Save rafops/3176561 to your computer and use it in GitHub Desktop.
Save SVN logs to Sqlite3
This file contains hidden or 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
require "sqlite3" | |
db = SQLite3::Database.new "logs.db" | |
db.execute "DROP TABLE IF EXISTS logs" | |
db.execute <<SQL | |
CREATE TABLE logs ( | |
project VARCHAR(100), | |
revision INT, | |
contributor VARCHAR(100), | |
created_at DATE, | |
lines INT | |
) | |
SQL | |
Dir["*.log"].each do |filename| | |
project = filename.match(/^(.+)\.log/).to_a.last | |
puts "opening #{filename}" | |
file = File.new(filename, "r") | |
while line = file.gets | |
matched = line.match(/^r(\d+)\s\|\s([^\|]+)\s\|\s([^\|]+)\s\|\s(\d+)\sline.*$/).to_a | |
matched.shift | |
revision = matched.shift.to_i | |
contributor = matched.shift | |
created_at = Date.parse matched.shift rescue nil | |
lines = matched.shift.to_i | |
if revision > 0 | |
db.execute <<SQL | |
INSERT INTO logs (project,revision,contributor,created_at,lines) | |
VALUES ('#{project}',#{revision},'#{contributor}','#{created_at}',#{lines}) | |
SQL | |
puts "#{project}\t#{revision}\t#{contributor}\t#{created_at}\t#{lines}" | |
end | |
end | |
file.close | |
end | |
db.close |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment