reviser 0.0.2 → 0.0.3.rc2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 63f5c9bb8b13e12e15bfaa88826b18e740fd9c9c
4
- data.tar.gz: 7b6da00d754cd3a1cf240b74dbfbff1210877b2c
3
+ metadata.gz: de86303651098bc8dc96d8c79d31d2fd3dfea923
4
+ data.tar.gz: 9e7d767dfb42f4f30264958a8f7bc25b9656ced8
5
5
  SHA512:
6
- metadata.gz: 702d6ac5c42ba91b81c366d85d42f560a1243ba780c4575148da466137a690f01fe038d8ea411ee6f258ca8d42e615fad807625eb524c5d510cc4145c83a9c51
7
- data.tar.gz: 75be96c7c3560d4385b6f2fd08e9543a0dc1b83aab5fcb1ad59e89e24c9a5d466d2ff4025ad77bafeda6c062f7acf131446bf3c87a85b1b48c281e63dea702e7
6
+ metadata.gz: 4cd682db9986a72d0c67214a9bed34781cec93badc1e8eb6ac535b68cbca68095e461401fb73e94e39925d0dd0d503990e3877e68774350ae829da95747c3888
7
+ data.tar.gz: 3780311419cb5cdcc2705ad1207d3ad4bbe22678b8a776493ba0c96a079be8f32ee8545c8fe227ecce1bf9e5aaed155ea6dd98a5eae4f9eb6139d6d47526b3bb
data/.yardopts ADDED
@@ -0,0 +1 @@
1
+ --markup markdown
data/Gemfile CHANGED
@@ -1,18 +1,17 @@
1
- source 'http://rubygems.org'
2
-
3
- gemspec
1
+ source 'https://rubygems.org'
4
2
 
5
3
  # String.scrub for ruby 1.9.x
6
4
  gem 'scrub_rb' unless RUBY_VERSION.split('.')[0] == '2'
7
5
 
8
6
  gem 'rubyzip', '~> 1.1.6'
9
- #gem 'seven_zip_ruby', '~> 1.2.4'
10
- #gem 'yard', '~> 0.8.7.6'
11
- #gem 'redcarpet', '~> 3.2.2'
12
- gem 'spreadsheet', '~> 1.0.1'
13
- gem 'ruby-ole', '>= 1.0'
14
- gem 'rake', '~> 10.4.2'
7
+ # gem 'spreadsheet', '~> 1.0.1'
8
+ # gem 'ruby-ole', '>= 1.0'
15
9
  gem 'thor', '~> 0.19.1'
16
- gem 'git', '~> 1.2.9.1'
17
- gem 'w3c_validators', '~> 1.2'
18
- gem 'colorize', '~> 0.7.5'
10
+ # gem 'git', '~> 1.2.9.1'
11
+ gem 'colorize', '~> 0.7.5'
12
+
13
+ # To generate docs
14
+ group :development do
15
+ gem 'redcarpet'
16
+ gem 'yard'
17
+ end
data/README.md CHANGED
@@ -32,6 +32,22 @@ To perform the analysis, simply run:
32
32
 
33
33
  reviser work
34
34
 
35
+ ###How it works
36
+ ---------------
37
+
38
+ Our tool is divided into 4 main components :
39
+
40
+ |Component|Role|
41
+ |-------------|-------|
42
+ |Archiver|Extracting all computing projects|
43
+ |Organiser|Parsing students names and renaming directories appropriately|
44
+ |Checker|Running the analysis based upon selected criteria and extensions|
45
+ |Generator|Generating the analysis results in various formats|
46
+
47
+ The basic idea is that each component can receive data from any of the components run before it.
48
+ It shall requests that input upon loading. The *work* command actually runs the above components
49
+ with the appropriate input data (e.g. *Generator* relies on *Checker* results).
50
+
35
51
  ###Configuration
36
52
  ---------------
37
53
 
@@ -65,7 +81,18 @@ Lives in *type/my_project.yml*.
65
81
  |*program_prefix*|The program prefix|`pkg.` for Java||
66
82
  |*program_name*|The name of the program|`a.out` `Main`||
67
83
  |*execution_count*|The amount of times to execute the program|Default *1*||
68
- |*execution_value*|The optional parameter to pass to the program when executing|A list of values whose length shall be one if *execution_count* is not greater than 1|||
84
+ |*execution_value*|The optional parameter to pass to the program when executing|A list of values whose length shall be one if *execution_count* is not greater than *1*|||
85
+
86
+ ###Labels configuration
87
+
88
+ Each criterion is associated with a label. A label is some words, describing the criterion's result. For example, a criterion which checks the existence of a Makefile could have a label like 'Existence of Makefile'.
89
+
90
+ By default, labels are generated with the name of the called method. You have the possibility to customize this label thanks to the command line tool:
91
+
92
+ reviser add makefile? 'Existence of makefile'
93
+ # method associated label
94
+
95
+ Labels are stored in reviser's installation directory, in a file called *labels.yml*. We don't include them in the workspace at this point, but we could later depending on feedback.
69
96
 
70
97
  ###Extensions
71
98
  Extensions are in fact Criteria we didn't want to include into reviser's core.
@@ -79,12 +106,16 @@ As of now, there are 2 extensions:
79
106
  |Valgrind|Runs a memcheck through system call to valgrind|`memleaks`|
80
107
  |WebValidators|Validates HTML and CSS through W3C API calls|`validate_web` `validate_html` `validate_css`|
81
108
 
82
- ###Extending
109
+ ###Working on your own
110
+
111
+ If you have very special needs, you may need to create your own components or extensions.
112
+ You'll then need to load your components at the right time, and register your extensions for them to be available.
83
113
 
84
114
  ####Custom components
115
+
116
+ *example/my_component.rb*
85
117
  ```
86
118
  #!ruby
87
-
88
119
  require 'json'
89
120
  require 'reviser'
90
121
 
@@ -117,18 +148,88 @@ class MyComponent < Reviser::Component
117
148
  end
118
149
  end
119
150
  end
151
+ ```
120
152
 
153
+ ####Custom extensions
154
+
155
+ *example/my_extension.rb*
156
+ ```
157
+ #!ruby
121
158
  #
122
- # Then we run it
159
+ # A custom criteria for reviser
123
160
  #
161
+ require 'reviser'
162
+
163
+ module MyExtension
164
+ #
165
+ # This helper has the 'sources' methods
166
+ # that allow you to retrieve all sources
167
+ # files (files matching language extension)
168
+ #
169
+ include Reviser::Helpers::Project
170
+
171
+ def my_criteria
172
+ results = []
173
+ sources.each do |f|
174
+ results << f
175
+ end
176
+
177
+ #
178
+ # The manufacture method excepts
179
+ # a block which must describe the result contents
180
+ # for EACH format.
181
+ # You can also return raw data, then it'll be as it is
182
+ # for all formats.
183
+ #
184
+ manufacture do |format|
185
+ format.html { to_html results }
186
+ format.csv { ['This', 'is', 'power', 'of', 'Ruby', 'blocks'] }
187
+ format.xls { results }
188
+ end
189
+ end
190
+
191
+ private
192
+ #
193
+ # We just create a HTML list
194
+ #
195
+ def to_html data
196
+ html = '<ul>'
197
+ data.each do |el|
198
+ html << "<li>#{el}</li>"
199
+ end
200
+ html << '</ul>'
201
+
202
+ html
203
+ end
204
+ end
205
+ ```
206
+
207
+ ### Putting it together
208
+ *example/config.yml*
209
+ ```
210
+ #!yaml
211
+ extensions:
212
+ - my_criteria
213
+ ```
214
+
215
+ *example/my_app.rb*
216
+ ```
217
+ #!ruby
218
+ require 'reviser'
219
+
220
+ require_relative 'my_component'
221
+ require_relative 'my_extension'
222
+
124
223
  module MyApp
125
224
  include Reviser
126
225
 
127
- def self.run config_file = '../config.yml'
226
+ def self.run config_file = 'config.yml'
128
227
  #
129
228
  # Setup reviser
130
229
  #
131
230
  Reviser::setup config_file
231
+
232
+ Reviser::register :extension => 'MyExtension'
132
233
 
133
234
  #
134
235
  # You can load any built-in component (archiver, organiser, checker, generator)
@@ -137,18 +238,18 @@ module MyApp
137
238
  # If you don't respect that, nothing will work.
138
239
  # But you can run your component at any step, this won't break the process.
139
240
  #
140
- # Reviser::load :component => 'archiver'
141
- # Reviser::load :component => 'organiser', :input_from => 'archiver'
241
+ Reviser::load :component => 'archiver'
242
+ Reviser::load :component => 'organiser', :input_from => 'archiver'
142
243
 
143
244
  #
144
245
  # Tell reviser not to look for our component
145
246
  # in its core ones but to let us include it
146
247
  # ourselves instead
147
248
  #
148
- Reviser::load :component => 'my_component', :local => true #, :input_from => 'archiver'
249
+ Reviser::load :component => 'my_component', :input_from => 'archiver', :local => true
149
250
 
150
- # Reviser::load :component => 'checker', :input_from => 'organiser'
151
- # Reviser::load :component => 'generator', :input_from => 'checker'
251
+ Reviser::load :component => 'checker', :input_from => 'organiser'
252
+ Reviser::load :component => 'generator', :input_from => 'checker'
152
253
 
153
254
  #
154
255
  # Run reviser
@@ -156,12 +257,23 @@ module MyApp
156
257
  Reviser::run
157
258
  end
158
259
  end
260
+ ```
159
261
 
262
+ *example/main.rb*
263
+ ```
264
+ #!ruby
265
+ require_relative 'my_app'
266
+
267
+ #
268
+ # You can then run your app (don't forget you still need to be in a reviser workspace,
269
+ # so type/ and res/ folders must exist, as well as config.yml)
270
+ #
160
271
  MyApp::run
161
272
  ```
162
273
 
274
+
163
275
  Team
164
- ----
276
+ --------
165
277
  [Anthony Cerf]()
166
278
 
167
279
  [Yann Prono](https://github.com/mcdostone)
data/config.yml CHANGED
@@ -65,6 +65,9 @@ criteria:
65
65
  extensions:
66
66
  - memleaks
67
67
 
68
+ # Whether to create a git repository for each project
69
+ # relies on 'git' gem
70
+ create_git_repo: true
68
71
 
69
72
  # Options of all components
70
73
  # For the moment, there is just verbose option (for logger)
@@ -7,15 +7,26 @@
7
7
  # It's very simple at that point, but feel free to
8
8
  # make the extension better :-)
9
9
  #
10
- require 'w3c_validators'
11
10
 
12
11
  module Reviser
13
12
  module Extensions
14
13
  module WebValidators
15
14
  include Helpers::Project
16
- include W3CValidators
17
15
 
16
+ #
17
+ # Validates HTML and CSS
18
+ # if any
19
+ #
18
20
  def validate_web
21
+ #
22
+ # TODO : explain the exception to the user
23
+ #
24
+ unless defined? W3CValidators
25
+ require_gem 'w3c_validators'
26
+
27
+ self.class.send(:include, W3CValidators)
28
+ end
29
+
19
30
  results = validate(:html)
20
31
  results.merge! validate(:css)
21
32
 
@@ -29,14 +40,6 @@ module Reviser
29
40
  end
30
41
  end
31
42
 
32
- def validate_html
33
- validate :html
34
- end
35
-
36
- def validate_css
37
- validate :css
38
- end
39
-
40
43
  private
41
44
  #
42
45
  # @returns a hash matching all files for this lang to a resultset
@@ -46,13 +49,14 @@ module Reviser
46
49
  validator = nil
47
50
  case lang
48
51
  when :html
49
- validator = MarkupValidator.new
52
+ validator = W3CValidators::MarkupValidator.new
50
53
  when :css
51
- validator = CSSValidator.new
54
+ validator = W3CValidators::CSSValidator.new
52
55
  end
53
56
 
54
57
  raise ArgumentError unless validator != nil
55
58
 
59
+ print "\t\t#{lang.upcase}\t["
56
60
  files = sources.select { |s| File.extname(s) == ".#{lang}" }
57
61
  files.each do |f|
58
62
  begin
@@ -62,11 +66,14 @@ module Reviser
62
66
  :errors => response.errors.length
63
67
  }
64
68
 
65
- puts "\t\t#{f} => #{results[f][:valid]}"
66
- rescue ValidatorUnavailable => e
67
- results[f] = { :status => 'Unknown', :errors => 'Unknown' }
69
+ print "="
70
+ rescue W3CValidators::ValidatorUnavailable => e
71
+ results[f] = e.message
72
+ rescue Exception => e
73
+ results[f] = e.message
68
74
  end
69
75
  end
76
+ puts "]"
70
77
 
71
78
  results
72
79
  end
@@ -76,17 +83,19 @@ module Reviser
76
83
 
77
84
  headings = results.values.first.keys
78
85
 
79
- html = '<table><caption>WebValidators results</caption><tr><th>File</th>'
80
- headings.each { |heading| html << "<th>#{heading}</th>" }
86
+ html = '<table><tr><th>File</th>'
87
+ headings.each { |heading| html << "<th>#{heading.to_s.capitalize!}</th>" }
81
88
  html << '</tr>'
82
89
 
83
90
  results.each do |file, data|
84
- html << '<tr>'
85
- html << "<th>#{file}</th>"
86
- data.values.each { |value| html << "<td>#{value}</td>" }
91
+ html << "<tr><th>#{file}</th>"
92
+ if data.is_a?(Hash)
93
+ data.values.each { |value| html << "<td>#{value}</td>" }
94
+ else
95
+ html << "<td>#{data}</td>"
96
+ end
87
97
  html << '</tr>'
88
98
  end
89
-
90
99
  html << '</table>'
91
100
 
92
101
  html
data/labels.yml CHANGED
@@ -5,4 +5,5 @@ lines_count: Nombre de lignes de code
5
5
  comments_count: Nombre de lignes de commentaires
6
6
  compile: Resultats compilation
7
7
  execute: Resultats execution
8
- memleaks: Fuites memoires
8
+ memleaks: Fuites memoires
9
+ validate_web: Validite HTML/CSS W3C
data/lang/HTML.yml CHANGED
@@ -21,13 +21,6 @@ compiled: false
21
21
  #
22
22
  regex_comments: !ruby/regexp '/<!--(.*?)-->/'
23
23
 
24
- #
25
- # In all HTML projects, we'll need
26
- # the html_validator extension
27
- #
28
- extensions:
29
- validate_html: Validite HTML 5
30
-
31
24
  # Program prefix, needed especially for C
32
25
  # The execution command will look like this :
33
26
  # [execute_command=(java, ruby, python, ...)] [program_prefix]<program> [args]
data/lib/exec.rb CHANGED
@@ -1,7 +1,9 @@
1
1
  require 'thor'
2
2
  require 'fileutils'
3
3
  require 'colorize'
4
+
4
5
  require_relative 'reviser'
6
+ require_relative 'reviser/helpers/criteria'
5
7
 
6
8
  #
7
9
  # Module used for managing all actions in command line
@@ -13,7 +15,7 @@ require_relative 'reviser'
13
15
  module Reviser
14
16
  class Exec < Thor
15
17
 
16
- VERSION = '0.0.2'
18
+ VERSION = '0.0.3.rc1'
17
19
 
18
20
  map '--version' => :version
19
21
  map '-v' => :version
@@ -28,31 +30,17 @@ module Reviser
28
30
  # If config.yml already exists in the working
29
31
  # directory, then we setup reviser here
30
32
  config_file = File.expand_path('config.yml')
31
- setup config_file if File.exist? config_file
33
+ setup config_file if File.exist? config_file
32
34
  end
33
35
 
34
36
  # Create a environnment for checking projects
35
37
  # This method only copies the config file into the current directory.
36
38
  desc 'init DIRECTORY', 'Initialize Reviser workspace. DIRECTORY ||= \'.\''
37
39
  def init(dir = '.')
38
- pwd = FileUtils.pwd
39
-
40
- [Cfg::RES_DIR, Cfg::TYPE_DIR].each do |d|
41
- path = File.join(Cfg::ROOT, d)
42
- if File.directory? path
43
- unless File.directory? File.join(dir, d)
44
- FileUtils.cp_r(path, dir)
45
- message('Create', dir == '.' && d || File.join(dir, d))
46
- end
47
- end
48
- end
49
-
50
- msg = File.exist?(File.join(pwd,dir,File.basename($template_path))) && 'Recreate' || 'Create'
51
- FileUtils.mkdir_p dir unless Dir.exist?(File.join(pwd, dir))
52
- FileUtils.cp($template_path, dir)
53
- message(msg, File.basename($template_path))
54
-
55
- setup File.expand_path(File.join(dir, File.basename($template_path))) unless @@setup
40
+ # Import all files and directories
41
+ init_workspace dir
42
+
43
+ setup File.expand_path(File.join(dir, File.basename($template_path))) unless @@setup
56
44
 
57
45
  puts "Customize config.yml to your needs @see docs".yellow
58
46
  puts 'Then simply execute \'reviser work\' to launch analysis.'.yellow
@@ -100,9 +88,11 @@ module Reviser
100
88
 
101
89
  Reviser::run
102
90
  rescue Interrupt => i
103
- message("...".yellow, "Bye bye")
91
+ puts 'Bye bye'
92
+ rescue Gem::LoadError => e
93
+ message('Missing gem'.light_red, e.message)
104
94
  rescue Exception => e
105
- message('Error'.red, "#{e.message}")
95
+ message('Error'.red, e.message)
106
96
  end
107
97
  else
108
98
  message('Error'.red, "'config.yml' file doesn't exist! @see 'reviser init'")
@@ -117,9 +107,11 @@ module Reviser
117
107
 
118
108
  Reviser::run
119
109
  rescue Interrupt => i
120
- message("...".yellow, "Bye bye")
110
+ puts 'Bye bye'
111
+ rescue Gem::LoadError => e
112
+ message('Missing gem'.yellow, e.message)
121
113
  rescue Exception => e
122
- message('Error'.red, "#{e.message}")
114
+ message('Error'.red, e.message)
123
115
  end
124
116
  end
125
117
 
@@ -134,7 +126,7 @@ module Reviser
134
126
  #
135
127
  desc 'add METH \'LABEL\'', 'Associates LABEL with METH analysis def'
136
128
  def add meth, label
137
- res = Helpers::Labels.add meth, label
129
+ res = Helpers::Criteria::Labels.add meth, label
138
130
  message "#{res} label".green,meth + " => " + label
139
131
  end
140
132
 
@@ -156,8 +148,29 @@ module Reviser
156
148
 
157
149
  @@setup = true
158
150
  end
151
+
152
+ # Initialize workspace copying all files et directories.
153
+ # @param dir Directory to init.
154
+ def init_workspace dir
155
+ # First copy directories
156
+ [Cfg::RES_DIR, Cfg::TYPE_DIR].each do |d|
157
+ path = File.join(Cfg::ROOT, d)
158
+ if File.directory? path
159
+ unless File.directory? File.join(dir, d)
160
+ FileUtils.cp_r path, dir
161
+ message('Create', dir == '.' && d || File.join(dir, d))
162
+ end
163
+ end
164
+ end
165
+
166
+ # Then the config file
167
+ FileUtils.cp $template_path, dir
168
+ basename = File.basename($template_path)
169
+ message('Create', dir == '.' && basename || File.join(dir, basename))
170
+ end
171
+
159
172
  end
160
173
 
161
174
  end
162
175
  end
163
- Reviser::Exec.start(ARGV)
176
+ Reviser::Exec.start(ARGV)
@@ -1,15 +1,15 @@
1
1
  #
2
- # Author:: Renan Strauss
2
+ # The abstract class Component
3
+ # Even though Ruby doesn't have abstract classes,
4
+ # we force inheriting classes to implement the run
5
+ # method that will be called during reviser's execution
6
+ #
7
+ # @author Renan Strauss
3
8
  #
4
- require 'yaml'
5
9
  require_relative 'loggers/logger'
6
10
 
7
11
  module Reviser
8
12
  class Component
9
-
10
- # Each component has a logger (currently a txt file)
11
- # $logger
12
-
13
13
  #
14
14
  # Don't forget to call super in your component's initializer !
15
15
  # This method is all about : it stores the data from another
@@ -46,10 +46,11 @@ module Reviser
46
46
  data
47
47
  end
48
48
 
49
+ #
49
50
  # Be kind to our childs and let them access
50
51
  # ressources files easily
51
52
  #
52
- # @returns The specified resource path
53
+ # @return The specified resource path
53
54
  # TODO : put resources in dedicated folders
54
55
  # for each component or extension, so that
55
56
  # the user can omit <lang>/<ext_name>/ when
@@ -62,6 +63,7 @@ module Reviser
62
63
  protected
63
64
  #
64
65
  # @return all options for all components if they exist in config file.
66
+ #
65
67
  def options
66
68
  Cfg[:options]
67
69
  end
@@ -1,10 +1,10 @@
1
1
  #
2
- # Author:: Renan Strauss
2
+ # @author Renan Strauss
3
3
  #
4
4
  # The Checker is a component that wraps
5
5
  # all required tools to do the analysis.
6
6
  # It adapts itself dynamically
7
- # to the language Cfg.
7
+ # to the configuration
8
8
  #
9
9
  #
10
10
  require 'open3'
@@ -25,8 +25,15 @@ module Reviser
25
25
 
26
26
  @logger.h1 Logger::INFO, "Loading modules"
27
27
 
28
- load CRITERIA
29
- load EXTENSIONS
28
+ load_modules CRITERIA
29
+ load_modules EXTENSIONS
30
+
31
+ #
32
+ # We also load user-registered extensions if any
33
+ #
34
+ Reviser.registered_extensions.each do |ext|
35
+ load_module_methods ext
36
+ end
30
37
 
31
38
  @logger.h1 Logger::INFO, "Loading labels"
32
39
 
@@ -35,9 +42,10 @@ module Reviser
35
42
  @results = {}
36
43
  end
37
44
 
38
- # Yann : je ne recupere pas les datas de l'organiser,
39
- # Je considere que tous les projets sont dans le dossier courant.
40
- # TODO a voir si cela marche dans certains cas particuliers
45
+ #
46
+ # For each project processed by Organiser,
47
+ # we run analysis and store results
48
+ #
41
49
  def run
42
50
  @data.each_with_index do |proj, i|
43
51
  path = File.join(Cfg[:dest], proj)
@@ -118,7 +118,8 @@ module Reviser
118
118
  # @param seven_zip_file [String] the 7zip file.
119
119
  # @param destination [String] Destination of extracted data.
120
120
  def seven_zip seven_zip_file, destination
121
- require 'seven_zip_ruby'
121
+ require_gem 'seven_zip' unless defined? SevenZipRuby
122
+
122
123
  File.open(seven_zip_file, 'rb') do |file|
123
124
  SevenZipRuby::Reader.open(file) do |szr|
124
125
  szr.extract_all destination
@@ -50,7 +50,8 @@ module Reviser
50
50
 
51
51
  # Generates a Excel file
52
52
  def xls data, ext = '.xls'
53
- require 'spreadsheet'
53
+ require_gem 'spreadsheet' unless defined? Spreadsheet
54
+
54
55
  Spreadsheet.client_encoding = 'UTF-8'
55
56
  book = Spreadsheet::Workbook.new
56
57
  sheet = book.create_worksheet :name => 'Results'
@@ -1,7 +1,7 @@
1
1
  require 'fileutils'
2
- require_relative '../helpers/git'
3
- require_relative '../helpers/project'
2
+ require 'rubygems'
4
3
 
4
+ require_relative '../helpers/project'
5
5
 
6
6
  module Reviser
7
7
  module Components
@@ -18,9 +18,6 @@ module Reviser
18
18
  # @author Renan Strauss
19
19
  #
20
20
  class Organiser < Component
21
-
22
- # Include all tools
23
- include Helpers::Git
24
21
  include Helpers::Project::Naming
25
22
 
26
23
  # All entries to ignore during sort and organization
@@ -47,6 +44,14 @@ module Reviser
47
44
 
48
45
  # How many patterns are in the pseudo-regex?
49
46
  @count_patterns = {}
47
+
48
+ # Is git present ?
49
+ if Cfg[:create_git_repo]
50
+ require_gem 'git'
51
+ require_relative '../helpers/git'
52
+
53
+ self.class.send(:include, Helpers::Git)
54
+ end
50
55
  end
51
56
 
52
57
  # Renames directories more clearly.
@@ -131,8 +136,10 @@ module Reviser
131
136
  @logger.h1 Logger::INFO, "Structure project"
132
137
  structure entry
133
138
 
134
- @logger.h1 Logger::INFO, "Initializing git repo"
135
- git entry
139
+ if Cfg[:create_git_repo]
140
+ @logger.h1 Logger::INFO, "Initializing git repo"
141
+ git entry
142
+ end
136
143
 
137
144
  @logger.h1 Logger::INFO, "Renaming directory"
138
145
  new_path = rename entry
@@ -1,6 +1,9 @@
1
1
  #
2
- # @author Renan Strauss
3
2
  # Externalises the configuration
3
+ # Cfg acts like a hash whose entries are config keys
4
+ # associated with their values
5
+ #
6
+ # @author Renan Strauss
4
7
  #
5
8
  require 'yaml'
6
9
 
@@ -19,6 +22,9 @@ module Reviser
19
22
  # Project's type dir
20
23
  TYPE_DIR = 'type'
21
24
 
25
+ # The available out formats
26
+ OUT_FORMATS = [:csv, :html, :xls]
27
+
22
28
  # Is the config is loaded ?
23
29
  @@loaded = false
24
30
 
@@ -36,7 +42,7 @@ module Reviser
36
42
  end
37
43
 
38
44
  #
39
- # @returns The specified resource path
45
+ # @return The specified resource path
40
46
  # TODO : put resources in dedicated folders
41
47
  # for each component or extension, so that
42
48
  # the user can omit <lang>/<ext_name>/ when
@@ -90,6 +96,8 @@ module Reviser
90
96
  Cfg[:program_prefix] ||= ''
91
97
  Cfg[:execution_command] ||= ''
92
98
  Cfg[:execution_count] ||= 1
99
+
100
+ Cfg[:create_git_repo] ||= false
93
101
  end
94
102
 
95
103
  private
@@ -1,5 +1,5 @@
1
1
  #
2
- # @Author Renan Strauss
2
+ # @author Renan Strauss
3
3
  #
4
4
  # Basic stuff needed for Checker
5
5
  #
@@ -1,6 +1,6 @@
1
1
  #
2
- # @Author Yann Prono
3
- # @Author Renan Strauss
2
+ # @author Yann Prono
3
+ # @author Renan Strauss
4
4
  #
5
5
  # Needed stuff for compiled languages
6
6
  # such as C, Java, and so on.
@@ -1,5 +1,5 @@
1
1
  #
2
- # @Author Renan Strauss
2
+ # @author Renan Strauss
3
3
  #
4
4
  # Needed stuff for Checker
5
5
  # when it comes to executing
@@ -55,7 +55,7 @@ module Reviser
55
55
  @logger.h1(Logger::INFO, "Include methods of #{@criteria[meth]}") unless respond_to? meth
56
56
  self.class.send(:include, @criteria[meth]) unless respond_to? meth
57
57
 
58
- send meth
58
+ send meth
59
59
  else
60
60
  nil
61
61
  end
@@ -81,7 +81,7 @@ module Reviser
81
81
  # Load all of modules available for the analysis
82
82
  # @param directory Directory where search of modules is done.
83
83
  # @param regex regex to find name of modules.
84
- def load directory, regex = '*'
84
+ def load_modules directory, regex = '*'
85
85
  @logger.h2 Logger::INFO, "Modules of #{directory}"
86
86
  modules = Dir[File.join(directory, regex)]
87
87
 
@@ -89,13 +89,21 @@ module Reviser
89
89
  modules.each do |m|
90
90
  require_relative m
91
91
  ext = File.extname m
92
- module_name = Object.const_get "#{namespace}::#{camelize(File.basename(m,ext))}", false
93
- @logger.h3 Logger::INFO, "Load #{module_name}"
94
- methods = module_name.instance_methods false
95
- methods.each { |method| populate(method, module_name) }
92
+ module_name = "#{namespace}::#{camelize(File.basename(m,ext))}"
93
+
94
+ load_module_methods module_name
96
95
  end
97
96
  end
98
97
 
98
+ def load_module_methods module_name
99
+ mod = Object.const_get module_name, false
100
+
101
+ @logger.h3 Logger::INFO, "Load #{module_name}"
102
+
103
+ methods = mod.instance_methods false
104
+ methods.each { |method| populate(method, mod) }
105
+ end
106
+
99
107
  # Gets the name of module
100
108
  # @param file_module Name of the file module.
101
109
  def camelize file_module
@@ -110,15 +118,8 @@ module Reviser
110
118
 
111
119
  if Cfg.has_key?(key) && Cfg[key].respond_to?('each')
112
120
  Cfg[key].each do |meth|
113
- if meth.respond_to?('each') && meth.respond_to?('[]')
114
- label = meth[meth.keys[0]]
115
- @logger.h2(Logger::ERROR, "Undefined label for #{meth.keys[0]}, check your config file") if label == nil
116
- label = create_label(meth.keys[0]) if label == nil
117
- @output[meth.keys[0].to_sym] = label
118
- else
119
- label = (labels.respond_to?('[]') && labels.key?(meth.to_sym)) ? labels[meth.to_sym] : create_label(meth)
120
- @output[meth.to_sym] = label
121
- end
121
+ label = ((labels.respond_to?('each') && labels.key?(meth.to_sym))) && labels[meth.to_sym] || create_label(meth)
122
+ @output[meth.to_sym] = label
122
123
  end
123
124
  end
124
125
  end
@@ -130,58 +131,57 @@ module Reviser
130
131
  @logger.h2 Logger::ERROR, "Create label for #{meth}. You should custom your label (see 'reviser add')"
131
132
  meth.to_s.split('_').each {|s| s.capitalize! }.join(' ')
132
133
  end
133
- end
134
-
135
-
136
- # Manage all actions for adding, updating or getting labels of Reviser.
137
- # A label is a a group of words, describing the associated criterion (method).
138
- #
139
- # @example
140
- # criterion => label
141
- # all_files => all files of project
142
- #
143
- # known Labels are in the labels.yml file.
144
- #
145
- # @author Yann Prono
146
- class Labels
147
-
148
- # Current directory of this file
149
- PWD = File.dirname __FILE__
150
-
151
- # Path of label.yml file
152
- LABELS = File.join File.dirname(File.dirname(File.dirname(PWD))), 'labels.yml'
153
134
 
135
+ # Manage all actions for adding, updating or getting labels of Reviser.
136
+ # A label is a a group of words, describing the associated criterion (method).
137
+ #
138
+ # @example
139
+ # criterion => label
140
+ # all_files => all files of project
141
+ #
142
+ # known Labels are in the labels.yml file.
154
143
  #
155
- # Enable to associate a label to a criterion (method).
156
- # The label will be saved in the 'labels.yml' file
157
- # @param meth Method to link.
158
- # @param label Label to link with the method.
159
- def self.add meth, label
160
- res = "Create"
161
- labels = YAML.load File.open(LABELS)
162
- if labels.respond_to? '[]'
163
- res = "Update" if labels.key? meth
164
- labels[meth] = label
165
- File.open(LABELS, 'w') { |f| f.write labels.to_yaml }
144
+ # @author Yann Prono
145
+ module Labels
146
+
147
+ # Current directory of this file
148
+ PWD = File.dirname __FILE__
149
+
150
+ # Path of label.yml file
151
+ LABELS = File.join File.dirname(File.dirname(File.dirname(PWD))), 'labels.yml'
152
+
153
+ #
154
+ # Enable to associate a label to a criterion (method).
155
+ # The label will be saved in the 'labels.yml' file
156
+ # @param meth Method to link.
157
+ # @param label Label to link with the method.
158
+ def self.add meth, label
159
+ res = "Create"
160
+ labels = YAML.load File.open(LABELS)
161
+ if labels.respond_to? '[]'
162
+ res = "Update" if labels.key? meth
163
+ labels[meth] = label
164
+ File.open(LABELS, 'w') { |f| f.write labels.to_yaml }
165
+ end
166
+ res
166
167
  end
167
- res
168
- end
169
168
 
170
- # @return Hash all known labels by reviser.
171
- # :criterion => label
172
- def self.load
173
- Labels.populate(YAML.load(File.open(LABELS)))
174
- end
169
+ # @return Hash all known labels by reviser.
170
+ # :criterion => label
171
+ def self.load
172
+ Labels.populate(YAML.load(File.open(LABELS)))
173
+ end
175
174
 
176
- def self.populate hash
177
- labels = {}
178
- if hash.respond_to?('each')
179
- hash.each do |meth, label|
180
- labels[meth.to_sym] = label
175
+ def self.populate hash
176
+ labels = {}
177
+ if hash.respond_to?('each')
178
+ hash.each do |meth, label|
179
+ labels[meth.to_sym] = label
180
+ end
181
181
  end
182
+ labels
182
183
  end
183
- labels
184
184
  end
185
- end
185
+ end
186
186
  end
187
187
  end
@@ -4,8 +4,6 @@
4
4
  # @author Romain Ruez
5
5
  # @author Anthony Cerf
6
6
  #
7
- require 'git'
8
-
9
7
  module Reviser
10
8
  module Helpers
11
9
  module Git
@@ -43,16 +43,23 @@ module Reviser
43
43
  Dir.glob("**/*").select { |f| (File.file?(f)) }
44
44
  end
45
45
 
46
+ #
47
+ # @return all the files matching the project's language extension(s)
48
+ #
46
49
  def sources
47
50
  files.select { |f| Cfg[:extension].include? File.extname(f) }
48
51
  end
49
52
 
53
+ #
54
+ # Yields a new Result for the criteria
55
+ # to define an out value for each format
56
+ #
50
57
  def manufacture &block
51
58
  format = Result.new
52
59
  block.call format
53
60
 
54
61
  format
55
- end
62
+ end
56
63
 
57
64
  # This modules is used to scan the name of project
58
65
  # in order to get all students who worked.
@@ -1,4 +1,6 @@
1
1
  #
2
+ # Wraps methods for system calls
3
+ # (external programs execution)
2
4
  # @author Renan Strauss
3
5
  #
4
6
  require 'open3'
@@ -18,7 +20,7 @@ module Reviser
18
20
  # Executes the given command
19
21
  # and kills it if its execution
20
22
  # time > timeout
21
- # @returns stdout, stderr & process_status
23
+ # @return stdout, stderr & process_status
22
24
  #
23
25
  def exec_with_timeout(cmd, timeout = Cfg[:timeout])
24
26
  stdin, stdout, stderr, wait_thr = Open3.popen3(cmd)
@@ -3,6 +3,8 @@
3
3
  # It allows us to easily output well-formatted results for certain output formats
4
4
  # (eg HTML)
5
5
  #
6
+ # @author Renan Strauss
7
+ #
6
8
  module Reviser
7
9
  class Result
8
10
  #
@@ -20,8 +22,13 @@ module Reviser
20
22
 
21
23
  #
22
24
  # Does the magic ;-)
25
+ # When the user calls a method whose name is a valid format,
26
+ # we associate it with the given block value if a block is given,
27
+ # else we return the stored value
23
28
  #
24
29
  def method_missing m, *args, &block
30
+ raise NoMethodError, "Unknown format #{m}" unless Cfg::OUT_FORMATS.include?(m)
31
+
25
32
  format = "@#{m}".to_sym
26
33
 
27
34
  block_given? && instance_variable_set(format, block[]) || instance_variable_get(format)
data/lib/reviser.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  #
2
- # Author:: Renan Strauss
2
+ # @author Renan Strauss
3
3
  #
4
4
  # This class is basically here to give the user
5
5
  # a generic and comprehensive way to use and
@@ -10,18 +10,40 @@
10
10
  #
11
11
  require 'mkmf'
12
12
  require 'colorize'
13
+ require 'rubygems'
13
14
 
14
15
  require_relative 'reviser/component'
15
16
  require_relative 'reviser/config'
16
17
 
17
- require_relative 'reviser/helpers/git'
18
18
  require_relative 'reviser/helpers/project'
19
- require_relative 'reviser/helpers/system'
19
+ require_relative 'reviser/helpers/system'
20
20
 
21
+ #
22
+ # Very handy (that's why it's in global scope)
23
+ # Raises an exception unless the given gem is installed
24
+ # Requires the gem if it is installed
25
+ #
26
+ def require_gem gem_name
27
+ unless Gem::Specification::find_all_by_name(gem_name).any?
28
+ raise Gem::LoadError, "#{gem_name}".yellow + " => ".white + "gem install #{gem_name}".magenta
29
+ end
30
+
31
+ require gem_name
32
+ end
33
+
34
+ #
35
+ # The API entry point
36
+ #
21
37
  module Reviser
22
38
  class Reviser
23
39
  @@setup = false
40
+
24
41
  @@loaded_components = {}
42
+ @@registered_extensions = []
43
+
44
+ def self.registered_extensions
45
+ @@registered_extensions
46
+ end
25
47
 
26
48
  #
27
49
  # Adds an entry with the specified data.
@@ -39,7 +61,20 @@ module Reviser
39
61
  :data => nil
40
62
  }
41
63
  end
64
+
65
+ #
66
+ # Registers the specified extension
67
+ # (its methods will be available for analysis)
68
+ #
69
+ def self.register(data)
70
+ raise ArgumentError unless data.has_key?(:extension)
71
+
72
+ @@registered_extensions << data[:extension]
73
+ end
42
74
 
75
+ #
76
+ # Loads the configuration from given config_file
77
+ #
43
78
  def self.setup(config_file)
44
79
  Cfg.load config_file
45
80
  @@setup = true
@@ -12,15 +12,6 @@ preferred_build_command: make
12
12
  required_files:
13
13
  - !ruby/regexp '/(M|m)akefile/'
14
14
 
15
- #
16
- # The extensions you want
17
- # In this case, ext/valgrind.rb
18
- # must exist
19
- #
20
- extensions:
21
- #valgrind:
22
- - memleaks: Fuites memoire
23
-
24
15
  # For interpreted languages
25
16
  # execute_command:
26
17
 
data/type/example/Web.yml CHANGED
@@ -5,19 +5,4 @@ language: HTML
5
5
  #
6
6
  extension:
7
7
  - .html
8
- - .css
9
-
10
- #
11
- # The criteria's extensions.
12
- # Here we're using web_validators
13
- #
14
- extensions:
15
- - validate_web
16
-
17
- #
18
- # Let's configure it!
19
- # We tell the extension to save analysis details files
20
- # it got from W3C validator, so that we can check those
21
- # files ourselves for analysis :-)
22
- #
23
- web_validators_save_results: true
8
+ - .css
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: reviser
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3.rc2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Renan Strauss
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2015-03-27 00:00:00.000000000 Z
14
+ date: 2015-03-30 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: colorize
@@ -33,26 +33,6 @@ dependencies:
33
33
  - - ">="
34
34
  - !ruby/object:Gem::Version
35
35
  version: 0.7.5
36
- - !ruby/object:Gem::Dependency
37
- name: thor
38
- requirement: !ruby/object:Gem::Requirement
39
- requirements:
40
- - - "~>"
41
- - !ruby/object:Gem::Version
42
- version: '0.19'
43
- - - ">="
44
- - !ruby/object:Gem::Version
45
- version: 0.19.1
46
- type: :runtime
47
- prerelease: false
48
- version_requirements: !ruby/object:Gem::Requirement
49
- requirements:
50
- - - "~>"
51
- - !ruby/object:Gem::Version
52
- version: '0.19'
53
- - - ">="
54
- - !ruby/object:Gem::Version
55
- version: 0.19.1
56
36
  - !ruby/object:Gem::Dependency
57
37
  name: rubyzip
58
38
  requirement: !ruby/object:Gem::Requirement
@@ -74,59 +54,25 @@ dependencies:
74
54
  - !ruby/object:Gem::Version
75
55
  version: 1.1.7
76
56
  - !ruby/object:Gem::Dependency
77
- name: spreadsheet
78
- requirement: !ruby/object:Gem::Requirement
79
- requirements:
80
- - - "~>"
81
- - !ruby/object:Gem::Version
82
- version: '1.0'
83
- - - ">="
84
- - !ruby/object:Gem::Version
85
- version: 1.0.3
86
- type: :runtime
87
- prerelease: false
88
- version_requirements: !ruby/object:Gem::Requirement
89
- requirements:
90
- - - "~>"
91
- - !ruby/object:Gem::Version
92
- version: '1.0'
93
- - - ">="
94
- - !ruby/object:Gem::Version
95
- version: 1.0.3
96
- - !ruby/object:Gem::Dependency
97
- name: git
57
+ name: thor
98
58
  requirement: !ruby/object:Gem::Requirement
99
59
  requirements:
100
60
  - - "~>"
101
61
  - !ruby/object:Gem::Version
102
- version: '1.2'
62
+ version: '0.19'
103
63
  - - ">="
104
64
  - !ruby/object:Gem::Version
105
- version: 1.2.9.1
65
+ version: 0.19.1
106
66
  type: :runtime
107
67
  prerelease: false
108
68
  version_requirements: !ruby/object:Gem::Requirement
109
69
  requirements:
110
70
  - - "~>"
111
71
  - !ruby/object:Gem::Version
112
- version: '1.2'
72
+ version: '0.19'
113
73
  - - ">="
114
74
  - !ruby/object:Gem::Version
115
- version: 1.2.9.1
116
- - !ruby/object:Gem::Dependency
117
- name: w3c_validators
118
- requirement: !ruby/object:Gem::Requirement
119
- requirements:
120
- - - '='
121
- - !ruby/object:Gem::Version
122
- version: '1.2'
123
- type: :runtime
124
- prerelease: false
125
- version_requirements: !ruby/object:Gem::Requirement
126
- requirements:
127
- - - '='
128
- - !ruby/object:Gem::Version
129
- version: '1.2'
75
+ version: 0.19.1
130
76
  description: A semi-automatic tool for student's projects evaluation
131
77
  email: renan.strauss@gmail.com
132
78
  executables:
@@ -134,6 +80,7 @@ executables:
134
80
  extensions: []
135
81
  extra_rdoc_files: []
136
82
  files:
83
+ - ".yardopts"
137
84
  - Gemfile
138
85
  - README.md
139
86
  - bin/reviser
@@ -184,7 +131,7 @@ files:
184
131
  - type/example/Labyrinthe.yml
185
132
  - type/example/Pendu.yml
186
133
  - type/example/Web.yml
187
- homepage: https://bitbucket.org/renan-/reviser
134
+ homepage: http://rubygems.org/gems/reviser
188
135
  licenses:
189
136
  - GPL-3
190
137
  metadata: {}
@@ -199,9 +146,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
199
146
  version: 1.9.3
200
147
  required_rubygems_version: !ruby/object:Gem::Requirement
201
148
  requirements:
202
- - - ">="
149
+ - - ">"
203
150
  - !ruby/object:Gem::Version
204
- version: '0'
151
+ version: 1.3.1
205
152
  requirements: []
206
153
  rubyforge_project:
207
154
  rubygems_version: 2.4.5
@@ -209,3 +156,4 @@ signing_key:
209
156
  specification_version: 4
210
157
  summary: Reviser
211
158
  test_files: []
159
+ has_rdoc: