hw_cheker 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ NDYzZTAxYTcwZmVmMjQ1NDk2N2MzOTcxMmNjZjRkNTZiYTZhYmQzMg==
5
+ data.tar.gz: !binary |-
6
+ OTlkNGE1YWY1ZTkxODE2MTllOWFhMmYyYTVhNmI0YWFmNDQ5YWM1MQ==
7
+ !binary "U0hBNTEy":
8
+ metadata.gz: !binary |-
9
+ OWVlYWJkMzI2NjRkMjk5Yzk0Yjg5OTMyYWZmM2FmZWVkYmM1NjU4OTYwMjVi
10
+ YTRlZTE4NTJiMGJlZDc1ZTliZjJlODRjZWRkNzI4NjFhNWFhOWYxZTQwZGJk
11
+ NDk4YjJkYTkwODQxOTRlN2IwYjk5Y2Y3OTg3MjgyNTc0MjA1ZGY=
12
+ data.tar.gz: !binary |-
13
+ NzczYTM0MWNjZTMxYzVjNWQwYTFmZjRkYzNjNzdlODUyOTI1ZmUxNDZmNGM0
14
+ NDE0YzNlM2IwNTY0ODIwZjcyNDRkOGYzYmMxZDJkNjUwNjExODNkZDQwZDE4
15
+ ODk0OGFkZGZlZjJiNjBhOThlOGVlMDZkYThjNzJmNjc0ZGE1MTg=
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Andriy Baran
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
+ # HwCheker
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'hw_cheker'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install hw_cheker
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/bin/hw_cheker ADDED
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'hw_cheker'
4
+ #HomeWorkChecker::Base.new(../app/resived).start
data/lib/hw_cheker.rb ADDED
@@ -0,0 +1,34 @@
1
+ require "hw_cheker/version"
2
+ require 'active_support/core_ext/hash'
3
+ require 'hw_cheker/base'
4
+ require 'hw_cheker/file_scan'
5
+ require 'hw_cheker/zip'
6
+ require 'hw_cheker/test_run'
7
+ require 'hw_cheker/ruby_test_run'
8
+ require 'hw_cheker/python_test_run'
9
+
10
+ module HwCheker
11
+ # Your code goes here...
12
+ module HomeWorkChecker
13
+ FILE_TYPES = {
14
+ '.7z' => '',
15
+ '.zip' => ''
16
+ }
17
+ LANGUAGE_TYPES = {
18
+ '.rb' => "TestRun::RubyTestRun",
19
+ '.py' => "TestRun::PythonTestRun"
20
+ }
21
+ end
22
+ class StatusControl
23
+ include HomeWorkChecker
24
+ def check path
25
+ @t = HomeWorkChecker::Base.new(path)
26
+ @t.start
27
+ end
28
+
29
+ def scan_only path
30
+ @t = HomeWorkChecker::FileScan.new(path)
31
+ @t.files
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,22 @@
1
+ module HwCheker
2
+ module HomeWorkChecker
3
+ class Base
4
+ include HomeWorkChecker
5
+ def initialize(work_path, tmp_path = '/tmp')
6
+ raise "Working directory is not known" if work_path.nil?
7
+ raise "Directory #{work_path} does not exist" unless Dir::exist?(work_path)
8
+ raise "Directory #{tmp_path} does not exist" unless Dir::exist?(tmp_path)
9
+ @work_path, @tmp_path = work_path, tmp_path
10
+ end
11
+
12
+ def start
13
+ FileScan.new(@work_path).each do |name, type|
14
+ `rm -r #{@tmp_path}/#{name}` if Dir::exist?("#{@tmp_path}/#{name}")
15
+ Unarchive::Zip.new("#{@work_path}/#{name+type}", @tmp_path)
16
+ class_name = LANGUAGE_TYPES[TestRun::detect_language "#{@tmp_path}/#{name}"]
17
+ test_runner = class_name.constantize.new(@work_path, @tmp_path, name).perform
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,35 @@
1
+ module HwCheker
2
+ module HomeWorkChecker
3
+ class FileScan
4
+ attr_reader :files
5
+ def initialize(work_path)
6
+ @work_path, @files = work_path, []
7
+ Dir::foreach(@work_path) do |p|
8
+ if File::file?("#{@work_path}/#{p}") && FILE_TYPES.include?(File::extname p) && !exist_xml?(p)
9
+ @files << p
10
+ end
11
+ end
12
+ end
13
+
14
+ def each
15
+ if block_given?
16
+ i = 0
17
+ while i < @files.size
18
+ type = File::extname(@files[i])
19
+ name = @files[i].chomp(type)
20
+ yield(name, type)
21
+ i += 1
22
+ end
23
+ end
24
+ @files
25
+ end
26
+
27
+ private
28
+ def exist_xml?(archive_name)
29
+ temp = archive_name.chomp(File::extname archive_name)
30
+ File::exist? "#{@work_path}/#{temp}.xml"
31
+ end
32
+ end
33
+ end
34
+ end
35
+
@@ -0,0 +1,12 @@
1
+ module HwCheker
2
+ module HomeWorkChecker
3
+ module TestRun
4
+ class PythonTestRun
5
+ def initialize(path)
6
+ `cd #{path}/test`
7
+ puts `nosetests`
8
+ end
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,42 @@
1
+ module HwCheker
2
+ module HomeWorkChecker
3
+ module TestRun
4
+ class RubyTestRun
5
+ include TestRun
6
+
7
+ def initialize(work_path, tmp_path, dirname)
8
+ @work_path, @tmp_path = work_path, tmp_path
9
+ @dirname, @passed, @failed = dirname, 0, 0
10
+ end
11
+
12
+ def perform
13
+ Dir::foreach("#{@tmp_path}/#{@dirname}/test") do |p|
14
+ next unless File::file?("#{@tmp_path}/#{@dirname}/test/#{p}") && File::extname(p) == '.rb'
15
+ `rspec #{@tmp_path}/#{@dirname}/test/#{p} > #{@tmp_path}/report.txt`
16
+ count_passed_failed(File.open("#{@tmp_path}/report.txt").first.chomp)
17
+ end
18
+ generate_xml("#{@work_path}/#{@dirname}", {
19
+ :test_passing => calc_percent_passed,
20
+ :code_quality => '???'
21
+ })
22
+ end
23
+
24
+ private
25
+ def count_passed_failed(report)
26
+ return if report == 'No examples found.'
27
+ report.each_char do |value|
28
+ @passed += 1 if value == '.'
29
+ @failed += 1 if value == 'F'
30
+ end
31
+ end
32
+
33
+ def calc_percent_passed
34
+ return 0.00 if @passed.zero? && @failed.zero?
35
+ (@passed.to_f / ( @passed + @failed) * 100).round(2)
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
41
+
42
+
@@ -0,0 +1,22 @@
1
+ module HwCheker
2
+ module HomeWorkChecker
3
+ module TestRun
4
+ def self.detect_language(path)
5
+ raise "Subdirectory 'test' don't exist in folder #{path}" unless Dir::exist?("#{path}/test")
6
+ Dir::foreach("#{path}/test") do |p|
7
+ if File::file?("#{path}/test/#{p}") && LANGUAGE_TYPES.include?(File::extname p)
8
+ return File::extname p
9
+ end
10
+ end
11
+ raise "Any .rb/.py file doesn't exist"
12
+ end
13
+
14
+ def generate_xml(path, hash)
15
+ File.open("#{path}.xml", 'w') do |file|
16
+ file.write hash.to_xml
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
22
+
@@ -0,0 +1,3 @@
1
+ module HwCheker
2
+ VERSION = "1.2.0"
3
+ end
@@ -0,0 +1,14 @@
1
+ module HwCheker
2
+ module HomeWorkChecker
3
+ module Unarchive
4
+ class Zip
5
+
6
+ def initialize(filename, tmp_path = '/tmp')
7
+ @file = filename
8
+ `7za t #{@file}`
9
+ `7z x #{@file} -o#{tmp_path}`
10
+ end
11
+ end
12
+ end
13
+ end
14
+ end
metadata ADDED
@@ -0,0 +1,97 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: hw_cheker
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.2.0
5
+ platform: ruby
6
+ authors:
7
+ - LAMR-085
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-05-23 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: rspec
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
+ description: Home work checker for
56
+ email:
57
+ - andriy.baran.v@gmail.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - lib/hw_cheker/ruby_test_run.rb
63
+ - lib/hw_cheker/file_scan.rb
64
+ - lib/hw_cheker/version.rb
65
+ - lib/hw_cheker/test_run.rb
66
+ - lib/hw_cheker/zip.rb
67
+ - lib/hw_cheker/base.rb
68
+ - lib/hw_cheker/python_test_run.rb
69
+ - lib/hw_cheker.rb
70
+ - bin/hw_cheker
71
+ - LICENSE.txt
72
+ - README.md
73
+ homepage: ''
74
+ licenses:
75
+ - MIT
76
+ metadata: {}
77
+ post_install_message:
78
+ rdoc_options: []
79
+ require_paths:
80
+ - lib
81
+ required_ruby_version: !ruby/object:Gem::Requirement
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ required_rubygems_version: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - ! '>='
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
91
+ requirements: []
92
+ rubyforge_project:
93
+ rubygems_version: 2.0.3
94
+ signing_key:
95
+ specification_version: 4
96
+ summary: Hola!
97
+ test_files: []