oddjob 1.6.0 → 1.8.0
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 +5 -5
- data/.gitignore +1 -0
- data/README.md +15 -8
- data/bin/oddjob +5 -6
- data/lib/oddjob/version.rb +1 -1
- data/lib/oddjob.rb +64 -22
- data/oddjob.gemspec +3 -3
- metadata +14 -15
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 2dbc6617b76ae46bd5d37a94cad38cc122a35fa2bd60658902872d4104f35b0c
|
4
|
+
data.tar.gz: 496f1b23dcafaaabf98cf2ea7751613e4b7f669621ebb6755813ceadd2a656c3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: '071408f5075dfa22aace08f64629ebea052d256179372a020da28b9a84db29a0a6d911340fc19bc23eba670ec743adf3d0df78494ff6f3f4399cf5617da84724'
|
7
|
+
data.tar.gz: bea3a00076c04ee82f22b8a8ed09a3f971f790c00900a586da7cd710f33b12fa18725c6bc725e569938380ab9ca50826d35d8c98bbb46820b35920754e15fbd4
|
data/.gitignore
CHANGED
data/README.md
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
# oddjob #
|
2
2
|
|
3
|
+
[](https://badge.fury.io/rb/oddjob)
|
4
|
+
|
3
5
|
oddjob is a lightweight, command line controlled web server. Built for
|
4
6
|
development and testing purposes, it can be used to serve static content for
|
5
7
|
local web development and has basic file upload capabilities. It was initially
|
@@ -26,7 +28,7 @@ out of the included `bin` directory.
|
|
26
28
|
## Installation ##
|
27
29
|
|
28
30
|
oddjob is available as a ruby gem. To install it for general command line
|
29
|
-
use
|
31
|
+
use gem install:
|
30
32
|
|
31
33
|
```sh
|
32
34
|
gem install oddjob
|
@@ -42,11 +44,16 @@ gem 'oddjob'
|
|
42
44
|
And then execute:
|
43
45
|
|
44
46
|
```sh
|
45
|
-
bundle
|
47
|
+
bundle install
|
46
48
|
```
|
47
49
|
|
48
50
|
You can also run oddjob directly from the git repo. Clone the git repo and run
|
49
|
-
oddjob directly from the repo's bin directory.
|
51
|
+
oddjob directly from the repo's bin directory. For example:
|
52
|
+
|
53
|
+
```sh
|
54
|
+
git clone https://github.com/MCF/oddjob.git
|
55
|
+
./oddjob/bin/oddjob
|
56
|
+
```
|
50
57
|
|
51
58
|
## Usage ##
|
52
59
|
|
@@ -56,8 +63,8 @@ Command line usage is:
|
|
56
63
|
oddjob [OPTIONS] [server_root]
|
57
64
|
```
|
58
65
|
|
59
|
-
Where the optional server_root argument will be the
|
60
|
-
|
66
|
+
Where the optional server_root argument will be the served root directory. The
|
67
|
+
default server root is the current working directory.
|
61
68
|
|
62
69
|
The default file upload behaviour will print the contents of the HTTP POST
|
63
70
|
request, and the contents of any uploaded files, to the server's STDOUT. It is
|
@@ -97,8 +104,8 @@ To stop oddjob use the normal interrupt key combination (usually Ctrl-C).
|
|
97
104
|
oddjob
|
98
105
|
```
|
99
106
|
|
100
|
-
Serves the files and directories in your current working directory at
|
101
|
-
`http://localhost:4400
|
107
|
+
Serves the files and directories in your current working directory at
|
108
|
+
`http://localhost:4400/`. File upload is available at
|
102
109
|
`http://localhost:4400/oj_upload`
|
103
110
|
|
104
111
|
```sh
|
@@ -113,7 +120,7 @@ Serves the contents of the `./my-site` directory at the
|
|
113
120
|
## Environment ##
|
114
121
|
|
115
122
|
oddjob is written in ruby and its only required dependency is a standard ruby
|
116
|
-
install. oddjob makes use of
|
123
|
+
install. oddjob makes use of ruby's built in
|
117
124
|
[webrick](http://ruby-doc.org/stdlib-2.0.0/libdoc/webrick/rdoc/WEBrick.html)
|
118
125
|
web server library. No gems are required for running oddjob. oddjob has been
|
119
126
|
tested with ruby 1.8.7 and up.
|
data/bin/oddjob
CHANGED
@@ -28,15 +28,14 @@ begin
|
|
28
28
|
rescue LoadError
|
29
29
|
end
|
30
30
|
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
lib = File.expand_path('../lib', File.dirname( __FILE__))
|
31
|
+
# Prefer the local repo's lib directory.
|
32
|
+
lib = File.expand_path('../lib', File.dirname( __FILE__))
|
33
|
+
if File.exist?(File.join(lib, 'oddjob.rb'))
|
35
34
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
36
|
-
|
37
|
-
require 'oddjob' # Simply run from the repo, no gems.
|
38
35
|
end
|
39
36
|
|
37
|
+
require 'oddjob'
|
38
|
+
|
40
39
|
def show_version
|
41
40
|
STDOUT.puts("Version: #{OddJob::VERSION}")
|
42
41
|
exit
|
data/lib/oddjob/version.rb
CHANGED
data/lib/oddjob.rb
CHANGED
@@ -20,6 +20,7 @@
|
|
20
20
|
# DEALINGS IN THE SOFTWARE.
|
21
21
|
#++
|
22
22
|
|
23
|
+
require 'ostruct'
|
23
24
|
require 'webrick'
|
24
25
|
require 'oddjob/version'
|
25
26
|
|
@@ -103,10 +104,13 @@ module OddJob
|
|
103
104
|
" a {text-decoration:none; color:rgb(248,157,30)}",
|
104
105
|
" a:hover {color:rgb(239,131,0);}",
|
105
106
|
" .header {font-size:0.75em; float:right; margin-bottom: 2.0em;}",
|
107
|
+
" .fineprint {font-size:0.85em;}",
|
108
|
+
" li {margin-bottom:0.4em;}",
|
106
109
|
" </style>",
|
107
110
|
"</head>",
|
108
111
|
"<html><body>",
|
109
112
|
" <div class=\"header\">",
|
113
|
+
" <em>v#{VERSION}</em>",
|
110
114
|
" <a href=\"https://github.com/MCF/oddjob\">OddJob on github</a>",
|
111
115
|
" </div>",
|
112
116
|
" <div style=\"clear:both;\"></div>",
|
@@ -145,7 +149,7 @@ module OddJob
|
|
145
149
|
# Render the HTML for the informational page.
|
146
150
|
def info_page
|
147
151
|
html = [
|
148
|
-
" <
|
152
|
+
" <h2>#{File.basename($0)}</h2>",
|
149
153
|
" <p>Version: <strong>#{VERSION}</strong></p>"
|
150
154
|
]
|
151
155
|
html << " <pre>#{@usage}</pre>" unless @usage.nil?
|
@@ -162,15 +166,14 @@ module OddJob
|
|
162
166
|
|
163
167
|
##
|
164
168
|
# Standard servlet initialization function with additional arguments.
|
165
|
-
#
|
169
|
+
#
|
166
170
|
# +delay+ is the seconds of simulated network delay to wait before
|
167
171
|
# responding after an upload request.
|
168
172
|
#
|
169
|
-
# +save_directory+ is
|
170
|
-
#
|
171
|
-
#
|
172
|
-
# contents of each file. Generally only useful for small
|
173
|
-
# files.
|
173
|
+
# +save_directory+ is where uploaded files are saved. If +save_directory+
|
174
|
+
# is not set, or set to nil, uploaded files are not saved. Instead the
|
175
|
+
# entire http request is printed on STDOUT, followed by the name and
|
176
|
+
# contents of each file. Generally only useful for small text files.
|
174
177
|
def initialize(server, delay, save_directory, *options)
|
175
178
|
@simulated_delay = delay
|
176
179
|
@save_directory = save_directory
|
@@ -189,12 +192,12 @@ module OddJob
|
|
189
192
|
puts "-- END File Upload POST Request --"
|
190
193
|
end
|
191
194
|
|
192
|
-
|
195
|
+
all_uploads = Array.new
|
193
196
|
['file', 'file[]'].each do |name|
|
194
197
|
if request.query[name]
|
195
198
|
request.query[name].each_data do |data|
|
196
|
-
|
197
|
-
|
199
|
+
upload = OpenStruct.new
|
200
|
+
upload.name = data.filename
|
198
201
|
|
199
202
|
if @save_directory.nil? # File contents to server STDOUT.
|
200
203
|
puts "== BEGIN #{data.filename} Contents =="
|
@@ -204,14 +207,17 @@ module OddJob
|
|
204
207
|
output_name = unique_name(data.filename, @save_directory)
|
205
208
|
File.open(output_name, "w"){|f| f.print(data.to_s)}
|
206
209
|
puts "#{data.filename} uploaded, saved to #{output_name}"
|
210
|
+
upload.output_name = File.expand_path(output_name)
|
207
211
|
end
|
212
|
+
|
213
|
+
all_uploads.push(upload)
|
208
214
|
end
|
209
215
|
end
|
210
216
|
end
|
211
217
|
|
212
218
|
response.status = 200
|
213
219
|
response['Content-type'] = 'text/html'
|
214
|
-
response.body = uploaded_page(
|
220
|
+
response.body = uploaded_page(all_uploads)
|
215
221
|
|
216
222
|
sleep(@simulated_delay)
|
217
223
|
end
|
@@ -240,7 +246,7 @@ module OddJob
|
|
240
246
|
|
241
247
|
final_base = full_base = File.join(save_directory, base)
|
242
248
|
i = 1
|
243
|
-
while
|
249
|
+
while File.exist?(final_base + ext)
|
244
250
|
final_base = "#{full_base}_#{i}"
|
245
251
|
i += 1
|
246
252
|
end
|
@@ -252,18 +258,42 @@ module OddJob
|
|
252
258
|
# Returns a string holding the full HTML page with the file upload form.
|
253
259
|
def uploader_page
|
254
260
|
html = [
|
255
|
-
"<
|
261
|
+
"<h2>Oddjob File Uploader</h2>",
|
256
262
|
"<form action='' method='POST' enctype='multipart/form-data'>",
|
257
|
-
"
|
258
|
-
" Select file(s) to upload:",
|
263
|
+
" <label for='file'>Select one or more files to upload:</label>",
|
259
264
|
" <br><br>",
|
260
265
|
" <input type='file' name='file' multiple='true'>",
|
261
266
|
" <br><br>",
|
262
|
-
" <input type='submit'>",
|
263
|
-
" </p>",
|
267
|
+
" <input type='submit' value='Upload'>",
|
264
268
|
"</form>",
|
269
|
+
"<br>",
|
265
270
|
]
|
266
271
|
|
272
|
+
if @save_directory.nil?
|
273
|
+
html += [
|
274
|
+
"<p class=\"fineprint\">",
|
275
|
+
"Currently file uploads will <strong>not</strong> be saved, instead",
|
276
|
+
"their contents will be printed to oddjob's standard output.",
|
277
|
+
"In this configuration it is recommended that you only upload",
|
278
|
+
"text files.",
|
279
|
+
"</p>",
|
280
|
+
"<p class=\"fineprint\">",
|
281
|
+
"To upload any kind of file (binary or text) specify an output",
|
282
|
+
"directory where files will be saved instead. To see how visit the",
|
283
|
+
"<a href=\"#{INFO_PATH}\">info page</a>.",
|
284
|
+
"</p>",
|
285
|
+
]
|
286
|
+
else
|
287
|
+
html += [
|
288
|
+
"<p class=\"fineprint\">",
|
289
|
+
"Uploaded files will be saved in the",
|
290
|
+
"<strong>#{File.expand_path(@save_directory)}</strong> directory.",
|
291
|
+
"New files do not overwrite existing ones, instead they are given",
|
292
|
+
"a unique numbered suffix.",
|
293
|
+
"</p>",
|
294
|
+
]
|
295
|
+
end
|
296
|
+
|
267
297
|
page(html, "Uploader")
|
268
298
|
end
|
269
299
|
|
@@ -272,12 +302,24 @@ module OddJob
|
|
272
302
|
#
|
273
303
|
# +names+ is an array of the uploaded file names. These are names
|
274
304
|
# as submitted. Saved names may be different to avoid overwritting.
|
275
|
-
def uploaded_page(
|
305
|
+
def uploaded_page(uploads)
|
276
306
|
html = [
|
277
|
-
"<
|
278
|
-
"<p>Uploaded
|
279
|
-
"
|
280
|
-
|
307
|
+
"<h2>Results</h2>",
|
308
|
+
"<p>Uploaded:</p>",
|
309
|
+
"<ul>",
|
310
|
+
]
|
311
|
+
|
312
|
+
uploads.each do |upload|
|
313
|
+
html += [
|
314
|
+
"<li>",
|
315
|
+
"<strong>#{upload.name}</strong>",
|
316
|
+
upload.output_name ? " - saved to: #{upload.output_name}" : "",
|
317
|
+
"</li>",
|
318
|
+
]
|
319
|
+
end
|
320
|
+
|
321
|
+
html += [
|
322
|
+
"</ul>",
|
281
323
|
"<p><a href=''>Return to upload page</a></p>",
|
282
324
|
]
|
283
325
|
|
data/oddjob.gemspec
CHANGED
@@ -34,7 +34,7 @@ TXT
|
|
34
34
|
spec.extra_rdoc_files = ['README.md', 'MIT-LICENSE']
|
35
35
|
spec.rdoc_options = ['--main', 'README.md']
|
36
36
|
|
37
|
-
spec.add_development_dependency('bundler', '~>
|
38
|
-
spec.add_development_dependency('rake', '~>
|
39
|
-
spec.add_development_dependency('rspec')
|
37
|
+
spec.add_development_dependency('bundler', '~> 2.5' )
|
38
|
+
spec.add_development_dependency('rake', '~> 13.0')
|
39
|
+
spec.add_development_dependency('rspec', '~> 3.12')
|
40
40
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: oddjob
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.8.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mike Fellows
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-04-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -16,42 +16,42 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
19
|
+
version: '2.5'
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '
|
26
|
+
version: '2.5'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rake
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
33
|
+
version: '13.0'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: '
|
40
|
+
version: '13.0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: rspec
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- - "
|
45
|
+
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: '
|
47
|
+
version: '3.12'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- - "
|
52
|
+
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: '
|
54
|
+
version: '3.12'
|
55
55
|
description: |
|
56
56
|
Oddjob is a simple command line driver web server, written in ruby and
|
57
57
|
utilizing ruby's built in web server webrick. It is meant to be a test and
|
@@ -85,7 +85,7 @@ homepage: https://github.com/MCF/oddjob
|
|
85
85
|
licenses:
|
86
86
|
- MIT
|
87
87
|
metadata: {}
|
88
|
-
post_install_message:
|
88
|
+
post_install_message:
|
89
89
|
rdoc_options:
|
90
90
|
- "--main"
|
91
91
|
- README.md
|
@@ -102,9 +102,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
102
102
|
- !ruby/object:Gem::Version
|
103
103
|
version: '0'
|
104
104
|
requirements: []
|
105
|
-
|
106
|
-
|
107
|
-
signing_key:
|
105
|
+
rubygems_version: 3.3.15
|
106
|
+
signing_key:
|
108
107
|
specification_version: 4
|
109
108
|
summary: OddJob is simple command line driven web server
|
110
109
|
test_files: []
|