oddjob 1.6.0 → 1.7.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 38b952a30ef59eab2aecda48c84c792a02daff9e
4
- data.tar.gz: 6d0f3456c227c1bef0888db3971a80671054ba1d
3
+ metadata.gz: 3b38a613bae0128e48baaf4e6df262e2fdf9a7a7
4
+ data.tar.gz: 4359f741c6bf217138c4094d4d57dc5bc5b6be0a
5
5
  SHA512:
6
- metadata.gz: 71b6164c4462f00a4e7c6cb6385eec124b2d13aea477301ae205d4aac46ed288293ada192acc5499bfa106963ee2edca41e422da83bcd6f54dac620c55c09ef8
7
- data.tar.gz: aab8882dd01c9585ec228f6a3ba481f9f746b0e906345bbef4fd7f3ae00817ce74fde44c3e9a38feffba4b58bcd8cc340934b26538165a138c3f4af582b8b68b
6
+ metadata.gz: 23a926175279b4e046611c9230aec7367a5f7e3df64672cf307028ff0fc3c1ff796669ac6980fc4e9521d178041d83b31da4b4c714140aac59a86e27be320fdc
7
+ data.tar.gz: 4a21400cce090e8e0cc762fdb58005e7d4514bfffa963bc31d41b38443d11a938a597266da0f3beea7ed3e8cfdbc19b34c9530d4b0e2ad821e27528b64f1c230
data/.gitignore CHANGED
@@ -1,4 +1,5 @@
1
1
  *.swp
2
+ *.gem
2
3
  .ruby-version
3
4
  .bundle
4
5
  vendor
data/README.md CHANGED
@@ -1,5 +1,7 @@
1
1
  # oddjob #
2
2
 
3
+ [![Gem Version](https://badge.fury.io/rb/oddjob.svg)](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 simply use gem like so:
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 server's root directory.
60
- The default server root is the current working directory.
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 the
101
- `http://localhost:4400/` URL. File upload is available at
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 the built in ruby's
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
- begin
32
- require 'oddjob' # Installed as a gem.
33
- rescue LoadError
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
@@ -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
- " <h1>#{File.basename($0)}</h1>",
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,7 +166,7 @@ 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
  #
@@ -189,12 +193,12 @@ module OddJob
189
193
  puts "-- END File Upload POST Request --"
190
194
  end
191
195
 
192
- all_files = Array.new
196
+ all_uploads = Array.new
193
197
  ['file', 'file[]'].each do |name|
194
198
  if request.query[name]
195
199
  request.query[name].each_data do |data|
196
-
197
- all_files.push(data.filename)
200
+ upload = OpenStruct.new
201
+ upload.name = data.filename
198
202
 
199
203
  if @save_directory.nil? # File contents to server STDOUT.
200
204
  puts "== BEGIN #{data.filename} Contents =="
@@ -204,14 +208,17 @@ module OddJob
204
208
  output_name = unique_name(data.filename, @save_directory)
205
209
  File.open(output_name, "w"){|f| f.print(data.to_s)}
206
210
  puts "#{data.filename} uploaded, saved to #{output_name}"
211
+ upload.output_name = File.expand_path(output_name)
207
212
  end
213
+
214
+ all_uploads.push(upload)
208
215
  end
209
216
  end
210
217
  end
211
218
 
212
219
  response.status = 200
213
220
  response['Content-type'] = 'text/html'
214
- response.body = uploaded_page(all_files)
221
+ response.body = uploaded_page(all_uploads)
215
222
 
216
223
  sleep(@simulated_delay)
217
224
  end
@@ -240,7 +247,7 @@ module OddJob
240
247
 
241
248
  final_base = full_base = File.join(save_directory, base)
242
249
  i = 1
243
- while(File.exist?(final_base + ext))
250
+ while File.exist?(final_base + ext)
244
251
  final_base = "#{full_base}_#{i}"
245
252
  i += 1
246
253
  end
@@ -252,18 +259,42 @@ module OddJob
252
259
  # Returns a string holding the full HTML page with the file upload form.
253
260
  def uploader_page
254
261
  html = [
255
- "<h1>Uploader</h1>",
262
+ "<h2>Oddjob File Uploader</h2>",
256
263
  "<form action='' method='POST' enctype='multipart/form-data'>",
257
- " <p>",
258
- " Select file(s) to upload:",
264
+ " <label for='file'>Select one or more files to upload:</label>",
259
265
  " <br><br>",
260
266
  " <input type='file' name='file' multiple='true'>",
261
267
  " <br><br>",
262
- " <input type='submit'>",
263
- " </p>",
268
+ " <input type='submit' value='Upload'>",
264
269
  "</form>",
270
+ "<br>",
265
271
  ]
266
272
 
273
+ if @save_directory.nil?
274
+ html += [
275
+ "<p class=\"fineprint\">",
276
+ "Currently file uploads will <strong>not</strong> be saved, instead",
277
+ "their contents will be printed to oddjob's standard output.",
278
+ "In this configuration it is recommended that you only upload",
279
+ "text files.",
280
+ "</p>",
281
+ "<p class=\"fineprint\">",
282
+ "To upload any kind of file (binary or text) specify an output",
283
+ "directory where files will be saved instead. To see how visit the",
284
+ "<a href=\"#{INFO_PATH}\">info page</a>.",
285
+ "</p>",
286
+ ]
287
+ else
288
+ html += [
289
+ "<p class=\"fineprint\">",
290
+ "Uploaded files will be saved in the",
291
+ "<strong>#{File.expand_path(@save_directory)}</strong> directory.",
292
+ "New files do not overwrite existing ones, instead they are given",
293
+ "a unique numbered suffix.",
294
+ "</p>",
295
+ ]
296
+ end
297
+
267
298
  page(html, "Uploader")
268
299
  end
269
300
 
@@ -272,12 +303,24 @@ module OddJob
272
303
  #
273
304
  # +names+ is an array of the uploaded file names. These are names
274
305
  # as submitted. Saved names may be different to avoid overwritting.
275
- def uploaded_page(names)
306
+ def uploaded_page(uploads)
276
307
  html = [
277
- "<h1>Results</h1>",
278
- "<p>Uploaded:",
279
- " <strong>#{names.join("</strong>, <strong>")}</strong>",
280
- "</p>",
308
+ "<h2>Results</h2>",
309
+ "<p>Uploaded:</p>",
310
+ "<ul>",
311
+ ]
312
+
313
+ uploads.each do |upload|
314
+ html += [
315
+ "<li>",
316
+ "<strong>#{upload.name}</strong>",
317
+ upload.output_name ? " - saved to: #{upload.output_name}" : "",
318
+ "</li>",
319
+ ]
320
+ end
321
+
322
+ html += [
323
+ "</ul>",
281
324
  "<p><a href=''>Return to upload page</a></p>",
282
325
  ]
283
326
 
@@ -1,3 +1,3 @@
1
1
  module OddJob
2
- VERSION = '1.6.0'
2
+ VERSION = '1.7.0'
3
3
  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.6.0
4
+ version: 1.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mike Fellows
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-02-13 00:00:00.000000000 Z
11
+ date: 2016-04-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler