~uwelk/drossellog/drossellog

« back to all changes in this revision

Viewing changes to xhochy/drossellog/logfileparser.rb

  • Committer: Uwe L. Korn
  • Date: 2007-05-26 19:25:46 UTC
  • Revision ID: uwe@hansdieter.xhochy.org-20070526192546-52osx8bfqr50bpzj
Seperated drossellog.rb into subprograms

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
require 'digest/sha1'
2
2
require 'fileutils'
3
 
require 'xml/libxml'
 
3
require 'yaml'
4
4
require File.dirname(__FILE__) + '/logline.rb'
5
5
 
6
6
module XhochY
88
88
        end
89
89
      end #^ parse
90
90
    
91
 
      # Save the data int sperate XML-Files
 
91
      # Save the data into sperate YAML-Files
92
92
      # 
93
 
      # The filenames consist of the following: <tmp_path>/<year>/<month>/<day>.xml
 
93
      # The filenames consist of the following: <tmp_path>/<year>/<month>/<day>.yml
94
94
      def save_data(domain, domain_alias)
95
95
        sorted = {}
96
96
        @lines.each do |line|
107
107
          end
108
108
          
109
109
          sorted[line.year][line.month][line.day] << line
110
 
        end #^ @line.each
 
110
        end #^ @lines.each
111
111
        
112
112
        sorted.each do |year, value|
113
113
          value.each do |month, value2|
114
114
            value2.each do |day, value3|
115
 
              path = File.join(@tmp_path, File.basename(@filename), year, month)
116
 
              filename = File.join(path, day) + '.xml'
 
115
              path = File.join(@tmp_path, File.basename(@filename), year.to_s, month)
 
116
              filename = File.join(path, day.to_s) + '.yml'
117
117
              FileUtils.mkdir_p(path)
118
 
              
119
 
              xml = XML::Document.new()
120
 
              xml.root = XML::Node.new('logs')
121
 
              xml.root << day_node = XML::Node.new('day')
122
 
              day_node << day
123
 
              xml.root << month_node = XML::Node.new('month')
124
 
              month_node << month
125
 
              xml.root << year_node = XML::Node.new('year')
126
 
              year_node << year
127
 
              xml.root << domain_node = XML::Node.new('domain')
128
 
              domain_node << domain
129
 
              xml.root << alias_node = XML::Node.new('alias')
130
 
              alias_node << domain_alias.join(',')
131
 
              
 
118
 
 
119
              outdoc = {
 
120
                'day' => day.to_i,
 
121
                'month' => month,
 
122
                'year' => year.to_i,
 
123
                'domain' => domain,
 
124
                'alias' => domain_alias,
 
125
                'lines' => []
 
126
              }
 
127
 
 
128
              strip_tags = ['day', 'month', 'year']
132
129
              value3.each do |line|
133
 
                xml.root << line.to_xml_node(['day', 'month', 'year']) 
 
130
                hash = line.to_hash strip_tags
 
131
                outdoc['lines'] << hash
134
132
              end
135
133
              
136
 
              xml.save(filename, true)
137
 
            end
138
 
          end
 
134
              File.open(filename, 'w') do |f|
 
135
                f.write outdoc.to_yaml
 
136
              end
 
137
 
 
138
            end #^ value2.each
 
139
          end #^ value.each
139
140
        end #^ sorted.each
140
141
    
141
142
        path = File.join(@tmp_path, File.basename(@filename), 'sha1sum')
148
149
 
149
150
  end
150
151
  
151
 
end
 
 
b'\\ No newline at end of file'
 
152
end