svnlog2csv 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 876ddd1e59b9cc4fa08553725a7f1b74ff7b5460
4
+ data.tar.gz: c94a5c54d9fed6ffc4db73d8a55f7b9a9c9fa691
5
+ SHA512:
6
+ metadata.gz: de470f9fe95c53bcf69e9270d468df3331f8c0b0a7e81f77bf3dbf7ff2cd1c000da94d10cdcf1e14dc3d8df8a7c361d2321e85a73c60343634c1f431d96441d8
7
+ data.tar.gz: b29f8c4c16a3c7077ad5e294e8897ee4256dfd06b9df230fb4efc2643f36b37707c5318f0f48421b1f4558bcf17009c2c9720f859984c2688d0bf845c6dc2f0e
data/.gitignore ADDED
@@ -0,0 +1,19 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ *.log
19
+ *.csv
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in svnlog2csv.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Antonio Policastro
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,29 @@
1
+ # Svnlog2csv
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'svnlog2csv'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install svnlog2csv
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/bin/svnlog2csv ADDED
@@ -0,0 +1,59 @@
1
+ #!/usr/bin/env ruby
2
+ require "csv"
3
+ require "svnlog2csv"
4
+ require "thor"
5
+ # require "pry"
6
+
7
+ class App < Thor
8
+
9
+ default_task :start
10
+
11
+ desc "generate", "Genera un file CSV a partire da un log svn in formato XML"
12
+ method_option :xml, desc: "Log svn (XML)", required: true
13
+ method_option :csv, desc: "Output file (CSV)", required: true
14
+ def generate
15
+ # binding.pry
16
+ file = File.open(options[:xml])
17
+ reader = Svnlog2csv::Reader.new(file)
18
+ authors = reader.authors
19
+ file.close
20
+
21
+ file = File.open(options[:xml])
22
+ reader = Svnlog2csv::Reader.new(file)
23
+ CSV.open(options[:csv], "wb") do |csv|
24
+
25
+ # legenda del csv
26
+ csv << Svnlog2csv::Row.legend(authors)
27
+
28
+ current_row = nil
29
+
30
+ # Itero nei commit scritti nel log
31
+ reader.each("logentry") do |node|
32
+ log_entry = Svnlog2csv::LogEntry.new(node.outer_xml)
33
+
34
+ # Se current_row è nil, significa che sto gestendo il primo commit.
35
+ if current_row.nil?
36
+ current_row = Svnlog2csv::Row.new(log_entry.day, authors)
37
+ # Se la data di questo commit è diversa da quella del commit precedente,
38
+ # scrivo la riga sul csv e ne creo una nuova
39
+ elsif current_row.day != log_entry.day
40
+ csv << current_row.to_csv
41
+ current_row = Svnlog2csv::Row.new(log_entry.day, authors)
42
+ end
43
+ # Aggiungo i dati di questo commit alla riga
44
+ current_row.add(log_entry)
45
+ end
46
+
47
+ # Aggiungo l'ultima riga al csv
48
+ csv << current_row.to_csv
49
+
50
+ end
51
+
52
+ file.close
53
+ puts "Creato file #{options[:csv]}"
54
+
55
+ end
56
+
57
+ end
58
+
59
+ App.start
@@ -0,0 +1,24 @@
1
+ module Svnlog2csv
2
+
3
+ # Una LogEntry corrisponde ad un commit.
4
+ # Un commit è caratterizzato da una data, un autore e una serie di azioni.
5
+ # Ogni azione è un hash con la struttura {tipo_azione: n},
6
+ # dove tipo_azione può essere A (add), M (modify), D (delete), e n è il
7
+ # numero di file aggiunti/modificati/cancellati.
8
+ class LogEntry
9
+
10
+ attr_reader :day, :author, :actions
11
+
12
+ def initialize xml
13
+ doc = Nokogiri::XML(xml)
14
+ @day = doc.xpath("//date")[0].inner_text[0..9]
15
+ @author = doc.xpath("//author")[0].inner_text
16
+ @actions = Hash.new(0)
17
+ doc.xpath("//path").each do |path|
18
+ @actions[path.attribute("action").value.to_sym] += 1
19
+ end
20
+ end
21
+
22
+ end
23
+
24
+ end
@@ -0,0 +1,34 @@
1
+ module Svnlog2csv
2
+
3
+ # Classe di utilità che sfrutta nokogiri per leggere dati xml
4
+ class Reader
5
+
6
+ NODE_TYPE = Nokogiri::XML::Reader::TYPE_ELEMENT
7
+
8
+ def initialize string_or_io
9
+ @reader = Nokogiri::XML::Reader(string_or_io)
10
+ end
11
+
12
+ def each node_name = nil
13
+ @reader.each do |node|
14
+ if node_name.nil? || (node.name == node_name && node.node_type == NODE_TYPE)
15
+ yield node
16
+ end
17
+ end
18
+ end
19
+
20
+ # Estrae dall'xml tutti gli autori dei commit.
21
+ def authors
22
+ list = []
23
+ each("author") do |node|
24
+ author = node.inner_xml
25
+ unless list.include?(author)
26
+ list << author
27
+ end
28
+ end
29
+ list
30
+ end
31
+
32
+ end
33
+
34
+ end
@@ -0,0 +1,57 @@
1
+ module Svnlog2csv
2
+
3
+ # Row corrisponde a una riga che andrà scritta sul file csv.
4
+ # Ogni row è caratterizzata da una data (day) e una serie di azioni (actions).
5
+ # actions è un hash di hash, la cui struttura è
6
+ # @actions[autore][tipo_azione]
7
+ # tipo_azione è uno fra A (add), M (modify), D (delete), tot (totale).
8
+ # tot è semplicemente la somma di A, M e D.
9
+ class Row
10
+
11
+ attr_reader :day, :actions
12
+
13
+ def initialize day, authors
14
+ @day = day
15
+ @authors = authors.map { |author| author.to_sym }
16
+ @actions = Hash.new
17
+ @authors.each { |author| @actions[author] = Hash.new(0) }
18
+ end
19
+
20
+ # Aggiunge i dati di un commit alla riga.
21
+ # Se autore "pippo" ha fatto un commit con 2 add e 1 modify, viene eseguito
22
+ # l'equivalente di queste operazioni:
23
+ # @actions[:pippo][:A] += 2
24
+ # @actions[:pippo][:M] += 1
25
+ # @actions[:pippo][:tot] += 3
26
+ def add log_entry
27
+ log_entry.actions.each_pair do |action, value|
28
+ author = log_entry.author.to_sym
29
+ @actions[author][action] += value
30
+ @actions[author][:tot] += value
31
+ end
32
+ end
33
+
34
+ # Produce un array pronto per essere scritto sul csv.
35
+ # Viene scritta la data nella prima colonna, e per ogni autore quattro colonne
36
+ # (add, modify, delete, totale)
37
+ def to_csv
38
+ arr = @authors.map do |author|
39
+ author = author.to_sym
40
+ [@actions[author][:A], @actions[author][:M], @actions[author][:D], @actions[author][:tot]]
41
+ end
42
+ [@day] + arr.flatten
43
+ end
44
+
45
+ # Metodo statico che produce un array pronto per essere scritto sul csv.
46
+ # Contiene la legenda del csv.
47
+ def self.legend authors
48
+ arr = authors.map do |author|
49
+ author = author.to_sym
50
+ ["#{author} A", "#{author} M", "#{author} D", "#{author} TOT"]
51
+ end
52
+ ["Data"] + arr.flatten
53
+ end
54
+
55
+ end
56
+
57
+ end
@@ -0,0 +1,3 @@
1
+ module Svnlog2csv
2
+ VERSION = "0.0.1"
3
+ end
data/lib/svnlog2csv.rb ADDED
@@ -0,0 +1,8 @@
1
+ require "nokogiri"
2
+ require "svnlog2csv/version"
3
+ require "svnlog2csv/reader"
4
+ require "svnlog2csv/row"
5
+ require "svnlog2csv/log_entry"
6
+
7
+ module Svnlog2csv
8
+ end
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'svnlog2csv/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "svnlog2csv"
8
+ spec.version = Svnlog2csv::VERSION
9
+ spec.authors = ["Antonio Policastro"]
10
+ spec.email = ["tonypolik@gmail.com"]
11
+ spec.description = %q{svn log (xml format) -> csv}
12
+ spec.summary = %q{svn log (xml format) -> csv}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.3"
22
+ spec.add_development_dependency "rake"
23
+ spec.add_development_dependency "pry"
24
+ spec.add_dependency "nokogiri"
25
+ spec.add_dependency "thor"
26
+ end
metadata ADDED
@@ -0,0 +1,128 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: svnlog2csv
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Antonio Policastro
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-07-09 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: pry
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: nokogiri
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: thor
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description: svn log (xml format) -> csv
84
+ email:
85
+ - tonypolik@gmail.com
86
+ executables:
87
+ - svnlog2csv
88
+ extensions: []
89
+ extra_rdoc_files: []
90
+ files:
91
+ - .gitignore
92
+ - Gemfile
93
+ - LICENSE.txt
94
+ - README.md
95
+ - Rakefile
96
+ - bin/svnlog2csv
97
+ - lib/svnlog2csv.rb
98
+ - lib/svnlog2csv/log_entry.rb
99
+ - lib/svnlog2csv/reader.rb
100
+ - lib/svnlog2csv/row.rb
101
+ - lib/svnlog2csv/version.rb
102
+ - svnlog2csv.gemspec
103
+ homepage: ''
104
+ licenses:
105
+ - MIT
106
+ metadata: {}
107
+ post_install_message:
108
+ rdoc_options: []
109
+ require_paths:
110
+ - lib
111
+ required_ruby_version: !ruby/object:Gem::Requirement
112
+ requirements:
113
+ - - '>='
114
+ - !ruby/object:Gem::Version
115
+ version: '0'
116
+ required_rubygems_version: !ruby/object:Gem::Requirement
117
+ requirements:
118
+ - - '>='
119
+ - !ruby/object:Gem::Version
120
+ version: '0'
121
+ requirements: []
122
+ rubyforge_project:
123
+ rubygems_version: 2.0.3
124
+ signing_key:
125
+ specification_version: 4
126
+ summary: svn log (xml format) -> csv
127
+ test_files: []
128
+ has_rdoc: