Permalink
Browse files

Add support for sending the logs to S3.

  • Loading branch information...
Flameeyes committed Jun 15, 2012
1 parent 4cfd669 commit 450af9010e1d5d7de91599b8c0e92a6453ac9ce4
Showing with 61 additions and 24 deletions.
  1. +4 −0 Gemfile
  2. +8 −0 htmlgrep.css
  3. +49 −24 readscript.rb
View
@@ -0,0 +1,4 @@
+gem 'aws-sdk'
+gem 'inifile'
+gem 'archive-tar-minitar'
+gem 'builder'
View
@@ -0,0 +1,8 @@
+li {
+ white-space: pre;
+ font-family: monospace;
+}
+
+li.match {
+ background-color: #FF6B6B;
+}
View
@@ -15,37 +15,62 @@
# ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
# SOFTWARE.
-require 'builder'
+require 'inifile'
+require 'aws'
require 'archive/tar/minitar'
+require 'builder'
match = Regexp.new("( .*\\*.* ERROR: .*failed|detected file collision|Tinderbox QA Warning!|QA Notice: (Pre-stripped|file does not exist|command not found|USE flag|Files built without respecting LDFLAGS|The following files)|linux_config_exists|will always overflow|called with bigger|maintainer mode detected|econf called in src_compile)")
+config = IniFile.new("./tboxanalysis.ini")
+bucket_name = config['aws']['bucket']
+
+s3 = AWS::S3.new(:access_key_id => config['aws']['access_key'],
+ :secret_access_key => config['aws']['secret_key'])
+
+bucket = s3.buckets[bucket_name] || s3.buckets.create(bucket_name)
+
+unless bucket.objects['htmlgrep.css']
+ bucket.objects.create('htmlgrep.css',
+ :file => 'htmlgrep.css',
+ :acl => :public_read,
+ :content_type => "text/css",
+ :storage_class => :reduced_redundancy)
+end
+
Archive::Tar::Minitar::Reader.open($stdin) do |input|
input.each do |log|
next unless log.file?
- output = File.new(File.basename(log.name, ".log") + ".html", "w")
- output_xml = Builder::XmlMarkup.new(:indent => 2)
- output_xml.instruct!
-
- output.puts(output_xml.root {
- output_xml.html {
- output_xml.head {
- output_xml.link(:href => "htmlgrep.css",
- :rel => "stylesheet",
- :type => "text/css")
- }
-
- output_xml.body {
- output_xml.ol {
- log.read.split("\n").each do |line|
- cssclass = "match" if line =~ match
-
- output_xml.li line, :class => cssclass
- end
- }
- }
- }
- })
+ html_name = File.basename(log.name, ".log") + ".html"
+
+ xml_builder = Builder::XmlMarkup.new(:indent => 2)
+ xml_builder.instruct!
+
+ html_output = xml_builder.html {
+ xml_builder.head {
+ xml_builder.link(:href => "htmlgrep.css",
+ :rel => "stylesheet",
+ :type => "text/css")
+ }
+
+ xml_builder.body {
+ xml_builder.ol {
+ log.read.split("\n").each do |line|
+ cssclass = "match" if line =~ match
+
+ xml_builder.li line, :class => cssclass
+ end
+ }
+ }
+ }
+
+ bucket.objects.create(html_name,
+ :data => html_output,
+ :acl => :public_read,
+ # if we don't use text/html Chromium is
+ # unable to render it with the CSS.
+ :content_type => 'text/html',
+ :storage_class => :reduced_redundancy)
end
end

0 comments on commit 450af90

Please sign in to comment.