haikulearning_mongrel_upload_progress 0.2.3
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.
- data/CHANGELOG +3 -0
- data/COPYING +1 -0
- data/LICENSE +55 -0
- data/Manifest +9 -0
- data/README.rdoc +7 -0
- data/Rakefile +15 -0
- data/haikulearning_mongrel_upload_progress.gemspec +36 -0
- data/lib/haikulearning_mongrel_upload_progress/init.rb +104 -0
- data/resources/defaults.yaml +3 -0
- metadata +117 -0
data/CHANGELOG
ADDED
data/COPYING
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
No copying restrictions/license given.
|
data/LICENSE
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
Mongrel Web Server (Mongrel) is copyrighted free software by Zed A. Shaw
|
2
|
+
<zedshaw at zedshaw dot com> and contributors. You can redistribute it
|
3
|
+
and/or modify it under either the terms of the GPL2 or the conditions below:
|
4
|
+
|
5
|
+
1. You may make and give away verbatim copies of the source form of the
|
6
|
+
software without restriction, provided that you duplicate all of the
|
7
|
+
original copyright notices and associated disclaimers.
|
8
|
+
|
9
|
+
2. You may modify your copy of the software in any way, provided that
|
10
|
+
you do at least ONE of the following:
|
11
|
+
|
12
|
+
a) place your modifications in the Public Domain or otherwise make them
|
13
|
+
Freely Available, such as by posting said modifications to Usenet or an
|
14
|
+
equivalent medium, or by allowing the author to include your
|
15
|
+
modifications in the software.
|
16
|
+
|
17
|
+
b) use the modified software only within your corporation or
|
18
|
+
organization.
|
19
|
+
|
20
|
+
c) rename any non-standard executables so the names do not conflict with
|
21
|
+
standard executables, which must also be provided.
|
22
|
+
|
23
|
+
d) make other distribution arrangements with the author.
|
24
|
+
|
25
|
+
3. You may distribute the software in object code or executable
|
26
|
+
form, provided that you do at least ONE of the following:
|
27
|
+
|
28
|
+
a) distribute the executables and library files of the software,
|
29
|
+
together with instructions (in the manual page or equivalent) on where
|
30
|
+
to get the original distribution.
|
31
|
+
|
32
|
+
b) accompany the distribution with the machine-readable source of the
|
33
|
+
software.
|
34
|
+
|
35
|
+
c) give non-standard executables non-standard names, with
|
36
|
+
instructions on where to get the original software distribution.
|
37
|
+
|
38
|
+
d) make other distribution arrangements with the author.
|
39
|
+
|
40
|
+
4. You may modify and include the part of the software into any other
|
41
|
+
software (possibly commercial). But some files in the distribution
|
42
|
+
are not written by the author, so that they are not under this terms.
|
43
|
+
|
44
|
+
5. The scripts and library files supplied as input to or produced as
|
45
|
+
output from the software do not automatically fall under the
|
46
|
+
copyright of the software, but belong to whomever generated them,
|
47
|
+
and may be sold commercially, and may be aggregated with this
|
48
|
+
software.
|
49
|
+
|
50
|
+
6. THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR
|
51
|
+
IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
|
52
|
+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
53
|
+
PURPOSE.
|
54
|
+
|
55
|
+
|
data/Manifest
ADDED
data/README.rdoc
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
= {haikulearning_mongrel_upload_progress}[http://rubygems.org/gems/haikulearning_mongrel_upload_progress]
|
2
|
+
|
3
|
+
A mongrel plugin that makes it possible to check the progress of in-transit uploads.
|
4
|
+
|
5
|
+
== Haiku Learning Systems Modifications
|
6
|
+
|
7
|
+
This fork of the {original mongrel_upload_progress gem}[http://rubygems.org/gems/mongrel_upload_progress] has been modified by {Haiku Learning Systems}[http://www.haikulearning.com] to add a few features. Please read the CHANGELOG for more details about these changes.
|
data/Rakefile
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
begin
|
2
|
+
require 'echoe'
|
3
|
+
|
4
|
+
Echoe.new("haikulearning_mongrel_upload_progress") do |p|
|
5
|
+
p.summary = "The haikulearning fork of the mongrel_upload_progress gemplugin"
|
6
|
+
p.author= "The Mongrel team, with modifications by Marcos Wright Kuhns"
|
7
|
+
p.dependencies = ['mongrel >=0.3.13.3', 'gem_plugin >=0.2.1']
|
8
|
+
p.url = "https://github.com/haikulearning/mongrel_upload_progress"
|
9
|
+
|
10
|
+
p.need_tar_gz = false
|
11
|
+
p.need_tgz = true
|
12
|
+
end
|
13
|
+
rescue LoadError
|
14
|
+
puts "Echoe not available. Install it with: gem install echoe"
|
15
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
Gem::Specification.new do |s|
|
4
|
+
s.name = %q{haikulearning_mongrel_upload_progress}
|
5
|
+
s.version = "0.2.3"
|
6
|
+
|
7
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
|
8
|
+
s.authors = ["The Mongrel team, with modifications by Marcos Wright Kuhns"]
|
9
|
+
s.date = %q{2011-03-07}
|
10
|
+
s.description = %q{The haikulearning fork of the mongrel_upload_progress gemplugin}
|
11
|
+
s.email = %q{}
|
12
|
+
s.extra_rdoc_files = ["CHANGELOG", "COPYING", "LICENSE", "README.rdoc", "lib/haikulearning_mongrel_upload_progress/init.rb"]
|
13
|
+
s.files = ["CHANGELOG", "COPYING", "LICENSE", "Manifest", "README.rdoc", "Rakefile", "haikulearning_mongrel_upload_progress.gemspec", "lib/haikulearning_mongrel_upload_progress/init.rb", "resources/defaults.yaml"]
|
14
|
+
s.homepage = %q{https://github.com/haikulearning/mongrel_upload_progress}
|
15
|
+
s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Haikulearning_mongrel_upload_progress", "--main", "README.rdoc"]
|
16
|
+
s.require_paths = ["lib"]
|
17
|
+
s.rubyforge_project = %q{haikulearning_mongrel_upload_progress}
|
18
|
+
s.rubygems_version = %q{1.3.7}
|
19
|
+
s.summary = %q{The haikulearning fork of the mongrel_upload_progress gemplugin}
|
20
|
+
|
21
|
+
if s.respond_to? :specification_version then
|
22
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
23
|
+
s.specification_version = 3
|
24
|
+
|
25
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
26
|
+
s.add_runtime_dependency(%q<mongrel>, [">= 0.3.13.3"])
|
27
|
+
s.add_runtime_dependency(%q<gem_plugin>, [">= 0.2.1"])
|
28
|
+
else
|
29
|
+
s.add_dependency(%q<mongrel>, [">= 0.3.13.3"])
|
30
|
+
s.add_dependency(%q<gem_plugin>, [">= 0.2.1"])
|
31
|
+
end
|
32
|
+
else
|
33
|
+
s.add_dependency(%q<mongrel>, [">= 0.3.13.3"])
|
34
|
+
s.add_dependency(%q<gem_plugin>, [">= 0.2.1"])
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,104 @@
|
|
1
|
+
require 'mongrel'
|
2
|
+
require 'gem_plugin'
|
3
|
+
require 'yaml'
|
4
|
+
|
5
|
+
class Upload < GemPlugin::Plugin "/handlers"
|
6
|
+
include Mongrel::HttpHandlerPlugin
|
7
|
+
|
8
|
+
def initialize(options = {})
|
9
|
+
@path_info = Array(options[:path_info])
|
10
|
+
@frequency = options[:frequency] || 3
|
11
|
+
@request_notify = true
|
12
|
+
if options[:drb]
|
13
|
+
require 'drb'
|
14
|
+
DRb.start_service
|
15
|
+
Mongrel.const_set :Uploads, DRbObject.new(nil, options[:drb])
|
16
|
+
else
|
17
|
+
Mongrel.const_set :Uploads, Mongrel::UploadProgress.new
|
18
|
+
end
|
19
|
+
Mongrel::Uploads.debug = true if options[:debug]
|
20
|
+
end
|
21
|
+
|
22
|
+
def request_begins(params)
|
23
|
+
upload_notify(:add, params, params[Mongrel::Const::CONTENT_LENGTH].to_i)
|
24
|
+
end
|
25
|
+
|
26
|
+
def request_progress(params, clen, total)
|
27
|
+
upload_notify(:mark, params, clen)
|
28
|
+
end
|
29
|
+
|
30
|
+
def process(request, response)
|
31
|
+
upload_notify(:finish, request.params)
|
32
|
+
end
|
33
|
+
|
34
|
+
private
|
35
|
+
def upload_notify(action, params, *args)
|
36
|
+
return unless params[Mongrel::Const::REQUEST_METHOD] == 'POST' &&
|
37
|
+
@path_info.detect { |r| r === params['PATH_INFO'] } &&
|
38
|
+
upload_id = Mongrel::HttpRequest.query_parse(params['QUERY_STRING'])['upload_id']
|
39
|
+
if action == :mark
|
40
|
+
last_checked_time = Mongrel::Uploads.last_checked(upload_id)
|
41
|
+
return unless last_checked_time && Time.now - last_checked_time > @frequency
|
42
|
+
end
|
43
|
+
Mongrel::Uploads.send(action, upload_id, *args)
|
44
|
+
Mongrel::Uploads.update_checked_time(upload_id) unless action == :finish
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
# Keeps track of the status of all currently processing uploads
|
49
|
+
class Mongrel::UploadProgress
|
50
|
+
attr_accessor :debug
|
51
|
+
def initialize
|
52
|
+
@guard = Mutex.new
|
53
|
+
@counters = {}
|
54
|
+
end
|
55
|
+
|
56
|
+
def check(upid)
|
57
|
+
@counters[upid].last rescue nil
|
58
|
+
end
|
59
|
+
|
60
|
+
def last_checked(upid)
|
61
|
+
@counters[upid].first rescue nil
|
62
|
+
end
|
63
|
+
|
64
|
+
def update_checked_time(upid)
|
65
|
+
@guard.synchronize { @counters[upid][0] = Time.now }
|
66
|
+
end
|
67
|
+
|
68
|
+
def add(upid, size)
|
69
|
+
@guard.synchronize do
|
70
|
+
@counters[upid] = [Time.now, {:size => size, :received => 0}]
|
71
|
+
puts "#{upid}: Added" if @debug
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
def mark(upid, len)
|
76
|
+
return unless status = check(upid)
|
77
|
+
puts "#{upid}: Marking" if @debug
|
78
|
+
@guard.synchronize { status[:received] = status[:size] - len }
|
79
|
+
end
|
80
|
+
|
81
|
+
def finish(upid)
|
82
|
+
@guard.synchronize do
|
83
|
+
puts "#{upid}: Finished" if @debug
|
84
|
+
@counters.delete(upid)
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
def list
|
89
|
+
@counters.keys.sort
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
class Mongrel::UploadProgressConfig
|
94
|
+
class<<self
|
95
|
+
def options(root_dir)
|
96
|
+
case ::RAILS_ENV
|
97
|
+
when 'production'
|
98
|
+
YAML.load_file(File.join(root_dir, 'config/mongrel_upload_progress_prod.yml'))
|
99
|
+
else
|
100
|
+
YAML.load_file(File.join(root_dir, 'config/mongrel_upload_progress_dev.yml'))
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
metadata
ADDED
@@ -0,0 +1,117 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: haikulearning_mongrel_upload_progress
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 17
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 2
|
9
|
+
- 3
|
10
|
+
version: 0.2.3
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- The Mongrel team, with modifications by Marcos Wright Kuhns
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2011-03-07 00:00:00 -08:00
|
19
|
+
default_executable:
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
name: mongrel
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
hash: 101
|
30
|
+
segments:
|
31
|
+
- 0
|
32
|
+
- 3
|
33
|
+
- 13
|
34
|
+
- 3
|
35
|
+
version: 0.3.13.3
|
36
|
+
type: :runtime
|
37
|
+
version_requirements: *id001
|
38
|
+
- !ruby/object:Gem::Dependency
|
39
|
+
name: gem_plugin
|
40
|
+
prerelease: false
|
41
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
42
|
+
none: false
|
43
|
+
requirements:
|
44
|
+
- - ">="
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
hash: 21
|
47
|
+
segments:
|
48
|
+
- 0
|
49
|
+
- 2
|
50
|
+
- 1
|
51
|
+
version: 0.2.1
|
52
|
+
type: :runtime
|
53
|
+
version_requirements: *id002
|
54
|
+
description: The haikulearning fork of the mongrel_upload_progress gemplugin
|
55
|
+
email: ""
|
56
|
+
executables: []
|
57
|
+
|
58
|
+
extensions: []
|
59
|
+
|
60
|
+
extra_rdoc_files:
|
61
|
+
- CHANGELOG
|
62
|
+
- COPYING
|
63
|
+
- LICENSE
|
64
|
+
- README.rdoc
|
65
|
+
- lib/haikulearning_mongrel_upload_progress/init.rb
|
66
|
+
files:
|
67
|
+
- CHANGELOG
|
68
|
+
- COPYING
|
69
|
+
- LICENSE
|
70
|
+
- Manifest
|
71
|
+
- README.rdoc
|
72
|
+
- Rakefile
|
73
|
+
- haikulearning_mongrel_upload_progress.gemspec
|
74
|
+
- lib/haikulearning_mongrel_upload_progress/init.rb
|
75
|
+
- resources/defaults.yaml
|
76
|
+
has_rdoc: true
|
77
|
+
homepage: https://github.com/haikulearning/mongrel_upload_progress
|
78
|
+
licenses: []
|
79
|
+
|
80
|
+
post_install_message:
|
81
|
+
rdoc_options:
|
82
|
+
- --line-numbers
|
83
|
+
- --inline-source
|
84
|
+
- --title
|
85
|
+
- Haikulearning_mongrel_upload_progress
|
86
|
+
- --main
|
87
|
+
- README.rdoc
|
88
|
+
require_paths:
|
89
|
+
- lib
|
90
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
91
|
+
none: false
|
92
|
+
requirements:
|
93
|
+
- - ">="
|
94
|
+
- !ruby/object:Gem::Version
|
95
|
+
hash: 3
|
96
|
+
segments:
|
97
|
+
- 0
|
98
|
+
version: "0"
|
99
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
100
|
+
none: false
|
101
|
+
requirements:
|
102
|
+
- - ">="
|
103
|
+
- !ruby/object:Gem::Version
|
104
|
+
hash: 11
|
105
|
+
segments:
|
106
|
+
- 1
|
107
|
+
- 2
|
108
|
+
version: "1.2"
|
109
|
+
requirements: []
|
110
|
+
|
111
|
+
rubyforge_project: haikulearning_mongrel_upload_progress
|
112
|
+
rubygems_version: 1.3.7
|
113
|
+
signing_key:
|
114
|
+
specification_version: 3
|
115
|
+
summary: The haikulearning fork of the mongrel_upload_progress gemplugin
|
116
|
+
test_files: []
|
117
|
+
|