moss_ruby 1.1.1 → 1.1.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +5 -5
  2. data/lib/moss_ruby.rb +42 -25
  3. metadata +68 -12
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 6388f6ab27c44a591101464aa52b353023baf4e8
4
- data.tar.gz: a6ea6678cab87b739629d4dfe96070b5b07d9669
2
+ SHA256:
3
+ metadata.gz: 78627675df04c3b8c8a178e690f2c64f3f8588f451541dfd348b9fc0d4377ab5
4
+ data.tar.gz: 6f6c14edc678829dcf1a8b28ed1494ae64bfc0f5be0902ac9976b84ddc201e92
5
5
  SHA512:
6
- metadata.gz: 230ff756021bca01adfb49e4f91103b421922b8ef10a05dde7754681d9426d0ccc2b32bbbddbefda2a4908f21b81b66d3be173961b97f72e8d75cce59debaeed
7
- data.tar.gz: 1533a081ee20ba3f568338e1663af6bce61c6f8827360a4c8a07988f23eab25bab0b1bfafa6d15e6e3020bc490da586f5b6486e132aff417468a833acb7acee3
6
+ metadata.gz: 9e46b7f5ca7d20c833a6e3d8729a53611392f86379ac71c1de9c9695088f870ba7a651169ac9d5bb5a85a71500382404c0467babad16be7da32292c2a99d78d9
7
+ data.tar.gz: cb30039ddb1641f4b2c860021402497846e1e2dcd713417794a3987c9cf495a6079d45f442c33662770ca5de4d7638b95cf2015778ec56124bc19a6f21543e2b
data/lib/moss_ruby.rb CHANGED
@@ -20,7 +20,7 @@
20
20
  # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
21
  # SOFTWARE.
22
22
 
23
- require 'socket'
23
+ require 'tcp_timeout'
24
24
  require 'open-uri'
25
25
 
26
26
  #
@@ -61,15 +61,13 @@ class MossRuby
61
61
  end
62
62
 
63
63
  def upload_file (moss_server, file, id = 0)
64
- filename = file.strip.tap do |name|
65
- name.gsub! /[^\w\-\/.]/, '_'
66
- end
64
+ filename = file.strip.encode('UTF-8', invalid: :replace, undef: :replace, replace: '').gsub /[^\w\-\/.]/, '_'
67
65
 
68
- content = IO.read(filename)
66
+ content = IO.read(file)
69
67
  size = content.bytes.length
70
68
 
71
- if size > 0
72
- moss_server.write "file #{id} #{@options[:language]} #{size} #{file}\n"
69
+ if size > 0
70
+ moss_server.write "file #{id} #{@options[:language]} #{size} #{filename}\n"
73
71
  moss_server.write content
74
72
  end
75
73
  end
@@ -77,7 +75,7 @@ class MossRuby
77
75
  def check(files_dict, callback=nil)
78
76
  # Chech that the files_dict contains valid filenames
79
77
  files_dict[:base_files].each do |file_search|
80
- if Dir.glob(file_search, File::FNM_CASEFOLD).length == 0
78
+ if Dir.glob(file_search).length == 0
81
79
  raise "Unable to locate base file(s) matching #{file_search}"
82
80
  end
83
81
  end
@@ -87,14 +85,14 @@ class MossRuby
87
85
  end
88
86
 
89
87
  files_dict[:files].each do |file_search|
90
- if Dir.glob(file_search, File::FNM_CASEFOLD).length == 0
88
+ if Dir.glob(file_search).length == 0
91
89
  raise "Unable to locate base file(s) matching #{file_search}"
92
90
  end
93
91
  end
94
92
 
95
93
  # Connect to the server
96
94
  callback.call('Connecting to MOSS') unless callback.nil?
97
- moss_server = TCPSocket.new @server, @port
95
+ moss_server = TCPTimeout::TCPSocket.new @server, @port, connect_timeout: 10, write_timeout: 9, read_timeout: 300
98
96
  begin
99
97
  # Send header details
100
98
  callback.call(' - Sending configuration details') unless callback.nil?
@@ -108,7 +106,7 @@ class MossRuby
108
106
  moss_server.write "language #{@options[:language]}\n"
109
107
 
110
108
  callback.call(' - Checking language') unless callback.nil?
111
- line = moss_server.gets
109
+ line = gets(moss_server)
112
110
  if line.strip() != "yes"
113
111
  moss_server.write "end\n"
114
112
  raise "Invalid language option."
@@ -118,7 +116,7 @@ class MossRuby
118
116
  processing = files_dict[:base_files]
119
117
  processing.each do |file_search|
120
118
  callback.call(" - Sending base files #{count} of #{processing.count} - #{file_search}") unless callback.nil?
121
- files = Dir.glob(file_search, File::FNM_CASEFOLD)
119
+ files = Dir.glob(file_search)
122
120
  file_count = 1
123
121
  files.each do |file|
124
122
  callback.call(" - Base file #{file_count} of #{files.count} - #{file}") unless callback.nil?
@@ -133,7 +131,7 @@ class MossRuby
133
131
  processing = files_dict[:files]
134
132
  processing.each do |file_search|
135
133
  callback.call(" - Sending files #{count} of #{processing.count} - #{file_search}") unless callback.nil?
136
- files = Dir.glob(file_search, File::FNM_CASEFOLD)
134
+ files = Dir.glob(file_search)
137
135
  file_count = 1
138
136
  files.each do |file|
139
137
  callback.call(" - File #{idx} = #{file_count} of #{files.count} - #{file}") unless callback.nil?
@@ -146,7 +144,7 @@ class MossRuby
146
144
  callback.call(" - Waiting for server response") unless callback.nil?
147
145
  moss_server.write "query 0 #{@options[:comment]}\n"
148
146
 
149
- result = moss_server.gets
147
+ result = gets(moss_server)
150
148
 
151
149
  moss_server.write "end\n"
152
150
  return result.strip()
@@ -168,7 +166,7 @@ class MossRuby
168
166
 
169
167
  # read the two match files
170
168
  match_url = "#{uri}/match#{id}-top.html"
171
- match_top = open(match_url).read
169
+ match_top = URI.open(match_url).read().encode('UTF-8', 'binary', invalid: :replace, undef: :replace, replace: '?')
172
170
 
173
171
  callback.call(" - checking match #{match} percents") unless callback.nil?
174
172
  top = read_pcts match_top
@@ -177,8 +175,8 @@ class MossRuby
177
175
 
178
176
  callback.call(" - fetching #{match} html") unless callback.nil?
179
177
 
180
- match_file[0] = open("#{uri}/match#{id}-0.html").read
181
- match_file[1] = open("#{uri}/match#{id}-1.html").read
178
+ match_file[0] = URI.open("#{uri}/match#{id}-0.html").read().encode('UTF-8', 'binary', invalid: :replace, undef: :replace, replace: '?')
179
+ match_file[1] = URI.open("#{uri}/match#{id}-1.html").read().encode('UTF-8', 'binary', invalid: :replace, undef: :replace, replace: '?')
182
180
 
183
181
  # puts match_top
184
182
  # puts "---FILE0\n\n"
@@ -190,22 +188,22 @@ class MossRuby
190
188
 
191
189
  data[0] = read_data match_file[0]
192
190
  data[1] = read_data match_file[1]
193
-
191
+
194
192
  callback.call(" - adding #{match} result") unless callback.nil?
195
- result << [
193
+ result << [
196
194
  {
197
- filename: data[0][:filename],
195
+ filename: data[0][:filename],
198
196
  html: strip_a("<PRE>#{data[0][:html]}</PRE>"),
199
197
  pct: Integer(top[:pct0]),
200
198
  url: match_url,
201
199
  part_url: "#{uri}/match#{id}-0.html"
202
200
  },
203
201
  {
204
- filename: data[1][:filename],
202
+ filename: data[1][:filename],
205
203
  html: strip_a("<PRE>#{data[1][:html]}</PRE>"),
206
204
  pct: Integer(top[:pct1]),
207
205
  url: match_url,
208
- part_url: "#{uri}/match#{id}-1.html"
206
+ part_url: "#{uri}/match#{id}-1.html"
209
207
  }
210
208
  ]
211
209
  end
@@ -222,10 +220,10 @@ class MossRuby
222
220
  result = Array.new
223
221
  begin
224
222
  callback.call(" - Reading match data") unless callback.nil?
225
- page = open("#{uri}").read
223
+ page = URI.open("#{uri}").read().encode('UTF-8', 'binary', invalid: :replace, undef: :replace, replace: '?')
226
224
  regex = /<TR><TD><A HREF=".*?match(?<match_id>\d+).html">.*\((?<pct0>\d+)%\)<\/A>\n.*?<TD><A.*?((?<pct0>\d+)%\))/i
227
225
  # puts "scanning page"
228
- page.scan(regex).each do | match |
226
+ page.scan(regex).each do | match |
229
227
  id, pct0, pct1 = match
230
228
  # puts "#{id}, #{pct0}, #{pct1}"
231
229
  if Integer(pct0) >= min_pct || Integer(pct1) >= min_pct
@@ -251,4 +249,23 @@ class MossRuby
251
249
  regex = /<TH>(?<filename0>\S+)\s\((?<pct0>\d+)%\).*<TH>(?<filename1>\S+)\s\((?<pct1>\d+)%\)/xm
252
250
  top_file.match(regex)
253
251
  end
254
- end
252
+
253
+ ##
254
+ # Reads a line from the server.
255
+ def gets moss_server
256
+ buffer = ""
257
+
258
+ loop do
259
+ tmp = moss_server.read(1)
260
+
261
+ if !tmp.nil?
262
+ buffer += tmp
263
+ end
264
+
265
+ break if tmp.nil? || tmp.include?("\n")
266
+ tmp = ''
267
+ end
268
+
269
+ return buffer.gsub(/\n/, '')
270
+ end
271
+ end
metadata CHANGED
@@ -1,45 +1,101 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: moss_ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.1
4
+ version: 1.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Cain
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-06-29 00:00:00.000000000 Z
12
- dependencies: []
11
+ date: 2022-05-25 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: tcp_timeout
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 0.1.1
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 0.1.1
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '2.3'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '2.3'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '13.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '13.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.11'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.11'
13
69
  description: Moss-ruby is an unofficial ruby gem for the Moss system for Detecting
14
70
  Software Plagiarism (http://theory.stanford.edu/~aiken/moss/)
15
- email: acain@swin.edu.au
71
+ email:
72
+ - macite@gmail.com
16
73
  executables: []
17
74
  extensions: []
18
75
  extra_rdoc_files: []
19
76
  files:
20
77
  - lib/moss_ruby.rb
21
- homepage: https://bitbucket.org/macite/moss-ruby
78
+ homepage: https://github.com/doubtfire-lms/moss-ruby
22
79
  licenses:
23
80
  - MIT
24
81
  metadata: {}
25
- post_install_message:
82
+ post_install_message:
26
83
  rdoc_options: []
27
84
  require_paths:
28
85
  - lib
29
86
  required_ruby_version: !ruby/object:Gem::Requirement
30
87
  requirements:
31
- - - '>='
88
+ - - ">="
32
89
  - !ruby/object:Gem::Version
33
90
  version: '0'
34
91
  required_rubygems_version: !ruby/object:Gem::Requirement
35
92
  requirements:
36
- - - '>='
93
+ - - ">="
37
94
  - !ruby/object:Gem::Version
38
95
  version: '0'
39
96
  requirements: []
40
- rubyforge_project:
41
- rubygems_version: 2.0.14
42
- signing_key:
97
+ rubygems_version: 3.3.7
98
+ signing_key:
43
99
  specification_version: 4
44
100
  summary: Moss gem to access system for Detecting Software Plagiarism
45
101
  test_files: []