oration 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/bin/oration +30 -12
- data/bin/oration.rb +30 -12
- data/doc/Generator.html +76 -28
- data/doc/Object.html +5 -11
- data/doc/OrationFlags.html +128 -0
- data/doc/bin/oration.html +5 -1
- data/doc/bin/oration_rb.html +5 -1
- data/doc/created.rid +4 -4
- data/doc/index.html +4 -0
- data/doc/lib/generator_rb.html +1 -1
- data/lib/generator.rb +29 -14
- data/test/test_generator.rb +10 -9
- data/test/test_oration.rb +14 -17
- metadata +21 -6
data/bin/oration
CHANGED
@@ -2,9 +2,31 @@
|
|
2
2
|
|
3
3
|
# Programmer: Chris Bunch
|
4
4
|
|
5
|
+
require 'rubygems'
|
6
|
+
require 'optiflag'
|
7
|
+
|
5
8
|
$:.unshift File.join(File.dirname(__FILE__), "..", "lib")
|
6
9
|
require 'generator'
|
7
10
|
|
11
|
+
|
12
|
+
module OrationFlags extend OptiFlagSet
|
13
|
+
flag "file" do
|
14
|
+
description "The name of the file containing the function to execute."
|
15
|
+
end
|
16
|
+
|
17
|
+
flag "function" do
|
18
|
+
description "The name of the function that should be remotely executed."
|
19
|
+
end
|
20
|
+
|
21
|
+
flag "output" do
|
22
|
+
description "Where the newly constructed app should be written to."
|
23
|
+
end
|
24
|
+
|
25
|
+
flag "appid" do
|
26
|
+
description "The Google App Engine appid that should be used for this app."
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
8
30
|
|
9
31
|
# This method takes in the arguments given to oration and validates them.
|
10
32
|
# Right now it's just three arguments: the name of the main code file to
|
@@ -13,15 +35,7 @@ $:.unshift File.join(File.dirname(__FILE__), "..", "lib")
|
|
13
35
|
# We validate that the file specified exists and has a function
|
14
36
|
# with that name, and that the directory they specified doesn't exist (so
|
15
37
|
# that we don't overwrite anything already there).
|
16
|
-
def validate_arguments(
|
17
|
-
if arguments.length != 3
|
18
|
-
abort("Usage: oration path-to-file function-name output-location")
|
19
|
-
end
|
20
|
-
|
21
|
-
main_file = arguments[0]
|
22
|
-
function_name = arguments[1]
|
23
|
-
output_dir = arguments[2]
|
24
|
-
|
38
|
+
def validate_arguments(main_file, function_name, output_dir, app_id, file=File)
|
25
39
|
if !file.exists?(main_file)
|
26
40
|
abort("#{main_file} didn't exist.")
|
27
41
|
end
|
@@ -50,7 +64,11 @@ end
|
|
50
64
|
# RubyGems is exec'ing this file, so instead just check if the thing we're
|
51
65
|
# executing ends in /bin/oration, the relative location of this file.
|
52
66
|
if $0.match(/\/bin\/oration\Z/)
|
53
|
-
|
54
|
-
|
55
|
-
|
67
|
+
OrationFlags.and_process!
|
68
|
+
|
69
|
+
validate_arguments(ARGV.flags.file, ARGV.flags.function, ARGV.flags.output,
|
70
|
+
ARGV.flags.appid)
|
71
|
+
Generator.generate_app(ARGV.flags.file, ARGV.flags.function,
|
72
|
+
ARGV.flags.output, ARGV.flags.appid)
|
73
|
+
puts "Done! Your application can be found at #{ARGV.flags.output}"
|
56
74
|
end
|
data/bin/oration.rb
CHANGED
@@ -2,9 +2,31 @@
|
|
2
2
|
|
3
3
|
# Programmer: Chris Bunch
|
4
4
|
|
5
|
+
require 'rubygems'
|
6
|
+
require 'optiflag'
|
7
|
+
|
5
8
|
$:.unshift File.join(File.dirname(__FILE__), "..", "lib")
|
6
9
|
require 'generator'
|
7
10
|
|
11
|
+
|
12
|
+
module OrationFlags extend OptiFlagSet
|
13
|
+
flag "file" do
|
14
|
+
description "The name of the file containing the function to execute."
|
15
|
+
end
|
16
|
+
|
17
|
+
flag "function" do
|
18
|
+
description "The name of the function that should be remotely executed."
|
19
|
+
end
|
20
|
+
|
21
|
+
flag "output" do
|
22
|
+
description "Where the newly constructed app should be written to."
|
23
|
+
end
|
24
|
+
|
25
|
+
flag "appid" do
|
26
|
+
description "The Google App Engine appid that should be used for this app."
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
8
30
|
|
9
31
|
# This method takes in the arguments given to oration and validates them.
|
10
32
|
# Right now it's just three arguments: the name of the main code file to
|
@@ -13,15 +35,7 @@ $:.unshift File.join(File.dirname(__FILE__), "..", "lib")
|
|
13
35
|
# We validate that the file specified exists and has a function
|
14
36
|
# with that name, and that the directory they specified doesn't exist (so
|
15
37
|
# that we don't overwrite anything already there).
|
16
|
-
def validate_arguments(
|
17
|
-
if arguments.length != 3
|
18
|
-
abort("Usage: oration path-to-file function-name output-location")
|
19
|
-
end
|
20
|
-
|
21
|
-
main_file = arguments[0]
|
22
|
-
function_name = arguments[1]
|
23
|
-
output_dir = arguments[2]
|
24
|
-
|
38
|
+
def validate_arguments(main_file, function_name, output_dir, app_id, file=File)
|
25
39
|
if !file.exists?(main_file)
|
26
40
|
abort("#{main_file} didn't exist.")
|
27
41
|
end
|
@@ -50,7 +64,11 @@ end
|
|
50
64
|
# RubyGems is exec'ing this file, so instead just check if the thing we're
|
51
65
|
# executing ends in /bin/oration, the relative location of this file.
|
52
66
|
if $0.match(/\/bin\/oration\Z/)
|
53
|
-
|
54
|
-
|
55
|
-
|
67
|
+
OrationFlags.and_process!
|
68
|
+
|
69
|
+
validate_arguments(ARGV.flags.file, ARGV.flags.function, ARGV.flags.output,
|
70
|
+
ARGV.flags.appid)
|
71
|
+
Generator.generate_app(ARGV.flags.file, ARGV.flags.function,
|
72
|
+
ARGV.flags.output, ARGV.flags.appid)
|
73
|
+
puts "Done! Your application can be found at #{ARGV.flags.output}"
|
56
74
|
end
|
data/doc/Generator.html
CHANGED
@@ -62,6 +62,8 @@
|
|
62
62
|
<h3 class="section-header">Methods</h3>
|
63
63
|
<ul class="link-list">
|
64
64
|
|
65
|
+
<li><a href="#method-c-copy_app_files">::copy_app_files</a></li>
|
66
|
+
|
65
67
|
<li><a href="#method-c-generate_app">::generate_app</a></li>
|
66
68
|
|
67
69
|
<li><a href="#method-c-generate_go_app">::generate_go_app</a></li>
|
@@ -111,6 +113,8 @@
|
|
111
113
|
|
112
114
|
<li><a href="./Object.html">Object</a></li>
|
113
115
|
|
116
|
+
<li><a href="./OrationFlags.html">OrationFlags</a></li>
|
117
|
+
|
114
118
|
</ul>
|
115
119
|
<div id="no-class-search-results" style="display: none;">No matching classes.</div>
|
116
120
|
</div>
|
@@ -138,13 +142,49 @@
|
|
138
142
|
<h3 class="section-header">Public Class Methods</h3>
|
139
143
|
|
140
144
|
|
145
|
+
<div id="copy_app_files-method" class="method-detail ">
|
146
|
+
<a name="method-c-copy_app_files"></a>
|
147
|
+
|
148
|
+
|
149
|
+
<div class="method-heading">
|
150
|
+
<span class="method-name">copy_app_files</span><span
|
151
|
+
class="method-args">(main_file, output_dir, fileutils=FileUtils)</span>
|
152
|
+
<span class="method-click-advice">click to toggle source</span>
|
153
|
+
</div>
|
154
|
+
|
155
|
+
|
156
|
+
<div class="method-description">
|
157
|
+
|
158
|
+
<p>Copies over any files in the directory the user has given us over to the
|
159
|
+
new directory we are making for their App Engine app.</p>
|
160
|
+
|
161
|
+
|
162
|
+
|
163
|
+
<div class="method-source-code"
|
164
|
+
id="copy_app_files-source">
|
165
|
+
<pre>
|
166
|
+
<span class="ruby-comment"># File lib/generator.rb, line 185</span>
|
167
|
+
def self.copy_app_files(main_file, output_dir, fileutils=<span class="ruby-constant">FileUtils</span>)
|
168
|
+
source_dir = <span class="ruby-constant">File</span>.dirname(main_file) + <span class="ruby-string">"/."</span>
|
169
|
+
<span class="ruby-constant">FileUtils</span>.cp_r(source_dir, output_dir)
|
170
|
+
end</pre>
|
171
|
+
</div>
|
172
|
+
|
173
|
+
</div>
|
174
|
+
|
175
|
+
|
176
|
+
|
177
|
+
|
178
|
+
</div>
|
179
|
+
|
180
|
+
|
141
181
|
<div id="generate_app-method" class="method-detail ">
|
142
182
|
<a name="method-c-generate_app"></a>
|
143
183
|
|
144
184
|
|
145
185
|
<div class="method-heading">
|
146
186
|
<span class="method-name">generate_app</span><span
|
147
|
-
class="method-args">(main_file, function_name, output_dir, generate_python_app=Generator.method(:generate_python_app), generate_go_app=Generator.method(:generate_go_app))</span>
|
187
|
+
class="method-args">(main_file, function_name, output_dir, app_id, generate_python_app=Generator.method(:generate_python_app), generate_go_app=Generator.method(:generate_go_app))</span>
|
148
188
|
<span class="method-click-advice">click to toggle source</span>
|
149
189
|
</div>
|
150
190
|
|
@@ -165,6 +205,7 @@ supported languages.</p>
|
|
165
205
|
def self.generate_app(main_file,
|
166
206
|
function_name,
|
167
207
|
output_dir,
|
208
|
+
app_id,
|
168
209
|
generate_python_app=<span class="ruby-constant">Generator</span>.method(:generate_python_app),
|
169
210
|
generate_go_app=<span class="ruby-constant">Generator</span>.method(:generate_go_app))
|
170
211
|
|
@@ -181,9 +222,9 @@ def self.generate_app(main_file,
|
|
181
222
|
|
182
223
|
case file_suffix
|
183
224
|
when <span class="ruby-string">"py"</span>
|
184
|
-
generate_python_app.call(main_file, function_name, output_dir)
|
225
|
+
generate_python_app.call(main_file, function_name, output_dir, app_id)
|
185
226
|
when <span class="ruby-string">"go"</span>
|
186
|
-
generate_go_app.call(main_file, function_name, output_dir)
|
227
|
+
generate_go_app.call(main_file, function_name, output_dir, app_id)
|
187
228
|
end
|
188
229
|
end</pre>
|
189
230
|
</div>
|
@@ -202,7 +243,7 @@ end</pre>
|
|
202
243
|
|
203
244
|
<div class="method-heading">
|
204
245
|
<span class="method-name">generate_go_app</span><span
|
205
|
-
class="method-args">(main_file, function_name, output_dir, get_go_function=Generator.method(:get_go_function), make_directory=FileUtils.method(:mkdir_p), write_go_app_yaml=Generator.method(:write_go_app_yaml_file), write_go_cicero_code=Generator.method(:write_go_cicero_code))</span>
|
246
|
+
class="method-args">(main_file, function_name, output_dir, app_id, get_go_function=Generator.method(:get_go_function), make_directory=FileUtils.method(:mkdir_p), write_go_app_yaml=Generator.method(:write_go_app_yaml_file), write_go_cicero_code=Generator.method(:write_go_cicero_code))</span>
|
206
247
|
<span class="method-click-advice">click to toggle source</span>
|
207
248
|
</div>
|
208
249
|
|
@@ -217,8 +258,8 @@ function that the user specified.</p>
|
|
217
258
|
<div class="method-source-code"
|
218
259
|
id="generate_go_app-source">
|
219
260
|
<pre>
|
220
|
-
<span class="ruby-comment"># File lib/generator.rb, line
|
221
|
-
def self.generate_go_app(main_file, function_name, output_dir,
|
261
|
+
<span class="ruby-comment"># File lib/generator.rb, line 65</span>
|
262
|
+
def self.generate_go_app(main_file, function_name, output_dir, app_id,
|
222
263
|
get_go_function=<span class="ruby-constant">Generator</span>.method(:get_go_function),
|
223
264
|
make_directory=<span class="ruby-constant">FileUtils</span>.method(:mkdir_p),
|
224
265
|
write_go_app_yaml=<span class="ruby-constant">Generator</span>.method(:write_go_app_yaml_file),
|
@@ -230,7 +271,7 @@ def self.generate_go_app(main_file, function_name, output_dir,
|
|
230
271
|
go_code_folder = output_dir + <span class="ruby-constant">File</span>::<span class="ruby-constant">Separator</span> + function_name
|
231
272
|
make_directory.call(go_code_folder)
|
232
273
|
|
233
|
-
write_go_app_yaml.call(
|
274
|
+
write_go_app_yaml.call(app_id, output_dir)
|
234
275
|
write_go_cicero_code.call(function, function_name, go_code_folder)
|
235
276
|
end</pre>
|
236
277
|
</div>
|
@@ -249,7 +290,7 @@ end</pre>
|
|
249
290
|
|
250
291
|
<div class="method-heading">
|
251
292
|
<span class="method-name">generate_python_app</span><span
|
252
|
-
class="method-args">(main_file, function_name, output_dir, get_python_function=Generator.method(:get_python_function), make_directory=FileUtils.method(:mkdir_p), write_python_app_yaml=Generator.method(:write_python_app_yaml_file), write_python_cicero_code=Generator.method(:write_python_cicero_code))</span>
|
293
|
+
class="method-args">(main_file, function_name, output_dir, app_id, get_python_function=Generator.method(:get_python_function), make_directory=FileUtils.method(:mkdir_p), write_python_app_yaml=Generator.method(:write_python_app_yaml_file), write_python_cicero_code=Generator.method(:write_python_cicero_code), copy_app_files=Generator.method(:copy_app_files))</span>
|
253
294
|
<span class="method-click-advice">click to toggle source</span>
|
254
295
|
</div>
|
255
296
|
|
@@ -267,17 +308,19 @@ function.</p>
|
|
267
308
|
<div class="method-source-code"
|
268
309
|
id="generate_python_app-source">
|
269
310
|
<pre>
|
270
|
-
<span class="ruby-comment"># File lib/generator.rb, line
|
271
|
-
def self.generate_python_app(main_file, function_name, output_dir,
|
311
|
+
<span class="ruby-comment"># File lib/generator.rb, line 49</span>
|
312
|
+
def self.generate_python_app(main_file, function_name, output_dir, app_id,
|
272
313
|
get_python_function=<span class="ruby-constant">Generator</span>.method(:get_python_function),
|
273
314
|
make_directory=<span class="ruby-constant">FileUtils</span>.method(:mkdir_p),
|
274
315
|
write_python_app_yaml=<span class="ruby-constant">Generator</span>.method(:write_python_app_yaml_file),
|
275
|
-
write_python_cicero_code=<span class="ruby-constant">Generator</span>.method(:write_python_cicero_code)
|
316
|
+
write_python_cicero_code=<span class="ruby-constant">Generator</span>.method(:write_python_cicero_code),
|
317
|
+
copy_app_files=<span class="ruby-constant">Generator</span>.method(:copy_app_files))
|
276
318
|
|
277
319
|
function = get_python_function.call(main_file, function_name)
|
278
320
|
make_directory.call(output_dir)
|
279
|
-
write_python_app_yaml.call(
|
280
|
-
write_python_cicero_code.call(
|
321
|
+
write_python_app_yaml.call(app_id, output_dir)
|
322
|
+
write_python_cicero_code.call(main_file, function_name, output_dir)
|
323
|
+
copy_app_files.call(main_file, output_dir)
|
281
324
|
end</pre>
|
282
325
|
</div>
|
283
326
|
|
@@ -312,7 +355,7 @@ starts.</p>
|
|
312
355
|
<div class="method-source-code"
|
313
356
|
id="get_go_function-source">
|
314
357
|
<pre>
|
315
|
-
<span class="ruby-comment"># File lib/generator.rb, line
|
358
|
+
<span class="ruby-comment"># File lib/generator.rb, line 139</span>
|
316
359
|
def self.get_go_function(main_file, function_name, file=<span class="ruby-constant">File</span>)
|
317
360
|
contents = file.open(main_file) { |f| f.read }
|
318
361
|
function = contents.scan(/(func #{function_name}(.|\n)*)/).flatten[0]
|
@@ -351,7 +394,7 @@ zero or more import statements.</p>
|
|
351
394
|
<div class="method-source-code"
|
352
395
|
id="get_python_function-source">
|
353
396
|
<pre>
|
354
|
-
<span class="ruby-comment"># File lib/generator.rb, line
|
397
|
+
<span class="ruby-comment"># File lib/generator.rb, line 85</span>
|
355
398
|
def self.get_python_function(main_file, function_name, file=<span class="ruby-constant">File</span>)
|
356
399
|
contents = file.open(main_file) { |f| f.read }
|
357
400
|
function = contents.scan(/(def #{function_name}(.|\n)*)/).flatten[0]
|
@@ -373,7 +416,7 @@ end</pre>
|
|
373
416
|
|
374
417
|
<div class="method-heading">
|
375
418
|
<span class="method-name">write_go_app_yaml_file</span><span
|
376
|
-
class="method-args">(
|
419
|
+
class="method-args">(app_id, output_dir, file=File)</span>
|
377
420
|
<span class="method-click-advice">click to toggle source</span>
|
378
421
|
</div>
|
379
422
|
|
@@ -390,9 +433,9 @@ automatically put a nice UI on the / url.</p>
|
|
390
433
|
<div class="method-source-code"
|
391
434
|
id="write_go_app_yaml_file-source">
|
392
435
|
<pre>
|
393
|
-
<span class="ruby-comment"># File lib/generator.rb, line
|
394
|
-
def self.write_go_app_yaml_file(
|
395
|
-
app_yaml_contents = <span class="ruby-string">application: #{
|
436
|
+
<span class="ruby-comment"># File lib/generator.rb, line 149</span>
|
437
|
+
def self.write_go_app_yaml_file(app_id, output_dir, file=<span class="ruby-constant">File</span>)
|
438
|
+
app_yaml_contents = <span class="ruby-string">application: #{app_id.downcase}version: 1runtime: goapi_version: 3handlers:- url: /.* script: _go_app</span>
|
396
439
|
|
397
440
|
app_yaml_location = file.expand_path(output_dir + <span class="ruby-constant">File</span>::<span class="ruby-constant">Separator</span> +
|
398
441
|
<span class="ruby-string">"app.yaml"</span>)
|
@@ -430,13 +473,14 @@ the user’s function in it.</p>
|
|
430
473
|
<div class="method-source-code"
|
431
474
|
id="write_go_cicero_code-source">
|
432
475
|
<pre>
|
433
|
-
<span class="ruby-comment"># File lib/generator.rb, line
|
476
|
+
<span class="ruby-comment"># File lib/generator.rb, line 169</span>
|
434
477
|
def self.write_go_cicero_code(function, function_name, output_dir, file=<span class="ruby-constant">File</span>)
|
435
478
|
template_location = <span class="ruby-constant">File</span>.join(<span class="ruby-constant">File</span>.dirname(__FILE__), <span class="ruby-string">".."</span>,
|
436
479
|
<span class="ruby-string">"templates"</span>, <span class="ruby-string">"main.go"</span>)
|
437
480
|
main_go_contents = file.open(template_location) { |f| f.read }
|
438
481
|
main_go_contents.gsub!(<span class="ruby-regexp">/CICERO_FUNCTION_CONTENTS/</span>, function)
|
439
482
|
main_go_contents.gsub!(<span class="ruby-regexp">/CICERO_FUNCTION_NAME/</span>, function_name)
|
483
|
+
main_go_contents.gsub!(<span class="ruby-regexp">/CICERO_PKG_NAME/</span>, function_name.downcase)
|
440
484
|
|
441
485
|
main_go_location = file.expand_path(output_dir + <span class="ruby-constant">File</span>::<span class="ruby-constant">Separator</span> +
|
442
486
|
<span class="ruby-string">"main.go"</span>)
|
@@ -459,7 +503,7 @@ end</pre>
|
|
459
503
|
|
460
504
|
<div class="method-heading">
|
461
505
|
<span class="method-name">write_python_app_yaml_file</span><span
|
462
|
-
class="method-args">(
|
506
|
+
class="method-args">(app_id, output_dir, file=File)</span>
|
463
507
|
<span class="method-click-advice">click to toggle source</span>
|
464
508
|
</div>
|
465
509
|
|
@@ -475,9 +519,9 @@ write those files in the given directory.</p>
|
|
475
519
|
<div class="method-source-code"
|
476
520
|
id="write_python_app_yaml_file-source">
|
477
521
|
<pre>
|
478
|
-
<span class="ruby-comment"># File lib/generator.rb, line
|
479
|
-
def self.write_python_app_yaml_file(
|
480
|
-
app_yaml_contents = <span class="ruby-string">application: #{
|
522
|
+
<span class="ruby-comment"># File lib/generator.rb, line 94</span>
|
523
|
+
def self.write_python_app_yaml_file(app_id, output_dir, file=<span class="ruby-constant">File</span>)
|
524
|
+
app_yaml_contents = <span class="ruby-string">application: #{app_id}version: 1runtime: pythonapi_version: 1handlers:- url: .* script: main.py</span>
|
481
525
|
|
482
526
|
app_yaml_location = file.expand_path(output_dir + <span class="ruby-constant">File</span>::<span class="ruby-constant">Separator</span> +
|
483
527
|
<span class="ruby-string">"app.yaml"</span>)
|
@@ -500,7 +544,7 @@ end</pre>
|
|
500
544
|
|
501
545
|
<div class="method-heading">
|
502
546
|
<span class="method-name">write_python_cicero_code</span><span
|
503
|
-
class="method-args">(
|
547
|
+
class="method-args">(file_name, function_name, output_dir, file=File)</span>
|
504
548
|
<span class="method-click-advice">click to toggle source</span>
|
505
549
|
</div>
|
506
550
|
|
@@ -517,16 +561,20 @@ placing them in as well.</p>
|
|
517
561
|
<div class="method-source-code"
|
518
562
|
id="write_python_cicero_code-source">
|
519
563
|
<pre>
|
520
|
-
<span class="ruby-comment"># File lib/generator.rb, line
|
521
|
-
def self.write_python_cicero_code(
|
564
|
+
<span class="ruby-comment"># File lib/generator.rb, line 116</span>
|
565
|
+
def self.write_python_cicero_code(file_name, function_name, output_dir,
|
522
566
|
file=<span class="ruby-constant">File</span>)
|
523
567
|
|
568
|
+
package_name = <span class="ruby-constant">File</span>.basename(file_name, <span class="ruby-string">".py"</span>)
|
524
569
|
template_location = <span class="ruby-constant">File</span>.join(<span class="ruby-constant">File</span>.dirname(__FILE__), <span class="ruby-string">".."</span>,
|
525
570
|
<span class="ruby-string">"templates"</span>, <span class="ruby-string">"main.py"</span>)
|
526
571
|
main_py_contents = file.open(template_location) { |f| f.read }
|
527
|
-
main_py_contents.gsub!(<span class="ruby-regexp">/
|
572
|
+
main_py_contents.gsub!(<span class="ruby-regexp">/CICERO_PACKAGE_NAME/</span>, package_name)
|
528
573
|
main_py_contents.gsub!(<span class="ruby-regexp">/CICERO_FUNCTION_NAME/</span>, function_name)
|
529
574
|
|
575
|
+
invokable_name = package_name + <span class="ruby-string">"."</span> + function_name
|
576
|
+
main_py_contents.gsub!(<span class="ruby-regexp">/CICERO_PACKAGE_AND_FUNCTION_NAME/</span>, invokable_name)
|
577
|
+
|
530
578
|
main_py_location = file.expand_path(output_dir + <span class="ruby-constant">File</span>::<span class="ruby-constant">Separator</span> +
|
531
579
|
<span class="ruby-string">"main.py"</span>)
|
532
580
|
|
data/doc/Object.html
CHANGED
@@ -108,6 +108,8 @@
|
|
108
108
|
|
109
109
|
<li><a href="./Object.html">Object</a></li>
|
110
110
|
|
111
|
+
<li><a href="./OrationFlags.html">OrationFlags</a></li>
|
112
|
+
|
111
113
|
</ul>
|
112
114
|
<div id="no-class-search-results" style="display: none;">No matching classes.</div>
|
113
115
|
</div>
|
@@ -154,7 +156,7 @@ now it’s just Python and Go. TODO(cgb): Add Java support</p></dd>
|
|
154
156
|
|
155
157
|
<div class="method-heading">
|
156
158
|
<span class="method-name">validate_arguments</span><span
|
157
|
-
class="method-args">(
|
159
|
+
class="method-args">(main_file, function_name, output_dir, app_id, file=File)</span>
|
158
160
|
<span class="method-click-advice">click to toggle source</span>
|
159
161
|
</div>
|
160
162
|
|
@@ -174,16 +176,8 @@ already there).</p>
|
|
174
176
|
<div class="method-source-code"
|
175
177
|
id="validate_arguments-source">
|
176
178
|
<pre>
|
177
|
-
<span class="ruby-comment"># File bin/oration, line
|
178
|
-
def validate_arguments(
|
179
|
-
if arguments.length != 3
|
180
|
-
abort(<span class="ruby-string">"Usage: oration path-to-file function-name output-location"</span>)
|
181
|
-
end
|
182
|
-
|
183
|
-
main_file = arguments[0]
|
184
|
-
function_name = arguments[1]
|
185
|
-
output_dir = arguments[2]
|
186
|
-
|
179
|
+
<span class="ruby-comment"># File bin/oration, line 38</span>
|
180
|
+
def validate_arguments(main_file, function_name, output_dir, app_id, file=<span class="ruby-constant">File</span>)
|
187
181
|
if !file.exists?(main_file)
|
188
182
|
abort("#{main_file} didn't exist.")
|
189
183
|
end
|
@@ -0,0 +1,128 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
+
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
|
3
|
+
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
|
4
|
+
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
5
|
+
<head>
|
6
|
+
<meta content="text/html; charset=UTF-8" http-equiv="Content-Type" />
|
7
|
+
|
8
|
+
<title>Module: OrationFlags</title>
|
9
|
+
|
10
|
+
<link rel="stylesheet" href="./rdoc.css" type="text/css" media="screen" />
|
11
|
+
|
12
|
+
<script src="./js/jquery.js" type="text/javascript"
|
13
|
+
charset="utf-8"></script>
|
14
|
+
<script src="./js/thickbox-compressed.js" type="text/javascript"
|
15
|
+
charset="utf-8"></script>
|
16
|
+
<script src="./js/quicksearch.js" type="text/javascript"
|
17
|
+
charset="utf-8"></script>
|
18
|
+
<script src="./js/darkfish.js" type="text/javascript"
|
19
|
+
charset="utf-8"></script>
|
20
|
+
|
21
|
+
</head>
|
22
|
+
<body class="module">
|
23
|
+
|
24
|
+
<div id="metadata">
|
25
|
+
<div id="home-metadata">
|
26
|
+
<div id="home-section" class="section">
|
27
|
+
<h3 class="section-header">
|
28
|
+
<a href="./index.html">Home</a>
|
29
|
+
<a href="./index.html#classes">Classes</a>
|
30
|
+
<a href="./index.html#methods">Methods</a>
|
31
|
+
</h3>
|
32
|
+
</div>
|
33
|
+
</div>
|
34
|
+
|
35
|
+
<div id="file-metadata">
|
36
|
+
<div id="file-list-section" class="section">
|
37
|
+
<h3 class="section-header">In Files</h3>
|
38
|
+
<div class="section-body">
|
39
|
+
<ul>
|
40
|
+
|
41
|
+
<li><a href="./bin/oration.html?TB_iframe=true&height=550&width=785"
|
42
|
+
class="thickbox" title="bin/oration">bin/oration</a></li>
|
43
|
+
|
44
|
+
<li><a href="./bin/oration_rb.html?TB_iframe=true&height=550&width=785"
|
45
|
+
class="thickbox" title="bin/oration.rb">bin/oration.rb</a></li>
|
46
|
+
|
47
|
+
</ul>
|
48
|
+
</div>
|
49
|
+
</div>
|
50
|
+
|
51
|
+
|
52
|
+
</div>
|
53
|
+
|
54
|
+
<div id="class-metadata">
|
55
|
+
|
56
|
+
<!-- Parent Class -->
|
57
|
+
|
58
|
+
|
59
|
+
<!-- Namespace Contents -->
|
60
|
+
|
61
|
+
|
62
|
+
<!-- Method Quickref -->
|
63
|
+
|
64
|
+
|
65
|
+
<!-- Included Modules -->
|
66
|
+
|
67
|
+
</div>
|
68
|
+
|
69
|
+
<div id="project-metadata">
|
70
|
+
|
71
|
+
|
72
|
+
|
73
|
+
<div id="classindex-section" class="section project-section">
|
74
|
+
<h3 class="section-header">Class/Module Index
|
75
|
+
<span class="search-toggle"><img src="./images/find.png"
|
76
|
+
height="16" width="16" alt="[+]"
|
77
|
+
title="show/hide quicksearch" /></span></h3>
|
78
|
+
<form action="#" method="get" accept-charset="utf-8" class="initially-hidden">
|
79
|
+
<fieldset>
|
80
|
+
<legend>Quicksearch</legend>
|
81
|
+
<input type="text" name="quicksearch" value=""
|
82
|
+
class="quicksearch-field" />
|
83
|
+
</fieldset>
|
84
|
+
</form>
|
85
|
+
|
86
|
+
<ul class="link-list">
|
87
|
+
|
88
|
+
<li><a href="./Generator.html">Generator</a></li>
|
89
|
+
|
90
|
+
<li><a href="./Object.html">Object</a></li>
|
91
|
+
|
92
|
+
<li><a href="./OrationFlags.html">OrationFlags</a></li>
|
93
|
+
|
94
|
+
</ul>
|
95
|
+
<div id="no-class-search-results" style="display: none;">No matching classes.</div>
|
96
|
+
</div>
|
97
|
+
|
98
|
+
|
99
|
+
</div>
|
100
|
+
</div>
|
101
|
+
|
102
|
+
<div id="documentation">
|
103
|
+
<h1 class="module">OrationFlags</h1>
|
104
|
+
|
105
|
+
<div id="description">
|
106
|
+
|
107
|
+
</div>
|
108
|
+
|
109
|
+
<!-- Constants -->
|
110
|
+
|
111
|
+
|
112
|
+
<!-- Attributes -->
|
113
|
+
|
114
|
+
|
115
|
+
<!-- Methods -->
|
116
|
+
|
117
|
+
|
118
|
+
</div>
|
119
|
+
|
120
|
+
<div id="validator-badges">
|
121
|
+
<p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
|
122
|
+
<p><small>Generated with the <a href="http://deveiate.org/projects/Darkfish-Rdoc/">Darkfish
|
123
|
+
Rdoc Generator</a> 2</small>.</p>
|
124
|
+
</div>
|
125
|
+
|
126
|
+
</body>
|
127
|
+
</html>
|
128
|
+
|
data/doc/bin/oration.html
CHANGED
@@ -24,13 +24,17 @@
|
|
24
24
|
<div id="metadata">
|
25
25
|
<dl>
|
26
26
|
<dt class="modified-date">Last Modified</dt>
|
27
|
-
<dd class="modified-date">
|
27
|
+
<dd class="modified-date">Sun Jan 22 12:37:46 -0800 2012</dd>
|
28
28
|
|
29
29
|
|
30
30
|
<dt class="requires">Requires</dt>
|
31
31
|
<dd class="requires">
|
32
32
|
<ul>
|
33
33
|
|
34
|
+
<li>rubygems</li>
|
35
|
+
|
36
|
+
<li>optiflag</li>
|
37
|
+
|
34
38
|
<li>generator</li>
|
35
39
|
|
36
40
|
</ul>
|
data/doc/bin/oration_rb.html
CHANGED
@@ -24,13 +24,17 @@
|
|
24
24
|
<div id="metadata">
|
25
25
|
<dl>
|
26
26
|
<dt class="modified-date">Last Modified</dt>
|
27
|
-
<dd class="modified-date">
|
27
|
+
<dd class="modified-date">Sun Jan 22 12:37:46 -0800 2012</dd>
|
28
28
|
|
29
29
|
|
30
30
|
<dt class="requires">Requires</dt>
|
31
31
|
<dd class="requires">
|
32
32
|
<ul>
|
33
33
|
|
34
|
+
<li>rubygems</li>
|
35
|
+
|
36
|
+
<li>optiflag</li>
|
37
|
+
|
34
38
|
<li>generator</li>
|
35
39
|
|
36
40
|
</ul>
|
data/doc/created.rid
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
|
2
|
-
bin/oration.rb
|
3
|
-
lib/generator.rb
|
4
|
-
bin/oration
|
1
|
+
Sun, 22 Jan 2012 17:45:26 -0800
|
2
|
+
bin/oration.rb Sun, 22 Jan 2012 12:37:46 -0800
|
3
|
+
lib/generator.rb Sun, 22 Jan 2012 12:58:06 -0800
|
4
|
+
bin/oration Sun, 22 Jan 2012 12:37:46 -0800
|
data/doc/index.html
CHANGED
@@ -35,11 +35,15 @@
|
|
35
35
|
|
36
36
|
<li class="class"><a href="Object.html">Object</a></li>
|
37
37
|
|
38
|
+
<li class="module"><a href="OrationFlags.html">OrationFlags</a></li>
|
39
|
+
|
38
40
|
</ul>
|
39
41
|
|
40
42
|
<h2 id="methods">Methods</h2>
|
41
43
|
<ul>
|
42
44
|
|
45
|
+
<li><a href="Generator.html#method-c-copy_app_files">::copy_app_files — Generator</a></li>
|
46
|
+
|
43
47
|
<li><a href="Generator.html#method-c-generate_app">::generate_app — Generator</a></li>
|
44
48
|
|
45
49
|
<li><a href="Generator.html#method-c-generate_go_app">::generate_go_app — Generator</a></li>
|
data/doc/lib/generator_rb.html
CHANGED
data/lib/generator.rb
CHANGED
@@ -18,6 +18,7 @@ module Generator
|
|
18
18
|
def self.generate_app(main_file,
|
19
19
|
function_name,
|
20
20
|
output_dir,
|
21
|
+
app_id,
|
21
22
|
generate_python_app=Generator.method(:generate_python_app),
|
22
23
|
generate_go_app=Generator.method(:generate_go_app))
|
23
24
|
|
@@ -34,9 +35,9 @@ module Generator
|
|
34
35
|
|
35
36
|
case file_suffix
|
36
37
|
when "py"
|
37
|
-
generate_python_app.call(main_file, function_name, output_dir)
|
38
|
+
generate_python_app.call(main_file, function_name, output_dir, app_id)
|
38
39
|
when "go"
|
39
|
-
generate_go_app.call(main_file, function_name, output_dir)
|
40
|
+
generate_go_app.call(main_file, function_name, output_dir, app_id)
|
40
41
|
end
|
41
42
|
end
|
42
43
|
|
@@ -45,21 +46,23 @@ module Generator
|
|
45
46
|
# code for the actual function, make a directory for their app, write
|
46
47
|
# an app.yaml for the app, and a Python file containing our Cicero
|
47
48
|
# interface and their function.
|
48
|
-
def self.generate_python_app(main_file, function_name, output_dir,
|
49
|
+
def self.generate_python_app(main_file, function_name, output_dir, app_id,
|
49
50
|
get_python_function=Generator.method(:get_python_function),
|
50
51
|
make_directory=FileUtils.method(:mkdir_p),
|
51
52
|
write_python_app_yaml=Generator.method(:write_python_app_yaml_file),
|
52
|
-
write_python_cicero_code=Generator.method(:write_python_cicero_code)
|
53
|
+
write_python_cicero_code=Generator.method(:write_python_cicero_code),
|
54
|
+
copy_app_files=Generator.method(:copy_app_files))
|
53
55
|
|
54
56
|
function = get_python_function.call(main_file, function_name)
|
55
57
|
make_directory.call(output_dir)
|
56
|
-
write_python_app_yaml.call(
|
57
|
-
write_python_cicero_code.call(
|
58
|
+
write_python_app_yaml.call(app_id, output_dir)
|
59
|
+
write_python_cicero_code.call(main_file, function_name, output_dir)
|
60
|
+
copy_app_files.call(main_file, output_dir)
|
58
61
|
end
|
59
62
|
|
60
63
|
# This method generates a Go Google App Engine application containing
|
61
64
|
# the function that the user specified.
|
62
|
-
def self.generate_go_app(main_file, function_name, output_dir,
|
65
|
+
def self.generate_go_app(main_file, function_name, output_dir, app_id,
|
63
66
|
get_go_function=Generator.method(:get_go_function),
|
64
67
|
make_directory=FileUtils.method(:mkdir_p),
|
65
68
|
write_go_app_yaml=Generator.method(:write_go_app_yaml_file),
|
@@ -71,7 +74,7 @@ module Generator
|
|
71
74
|
go_code_folder = output_dir + File::Separator + function_name
|
72
75
|
make_directory.call(go_code_folder)
|
73
76
|
|
74
|
-
write_go_app_yaml.call(
|
77
|
+
write_go_app_yaml.call(app_id, output_dir)
|
75
78
|
write_go_cicero_code.call(function, function_name, go_code_folder)
|
76
79
|
end
|
77
80
|
|
@@ -88,13 +91,14 @@ module Generator
|
|
88
91
|
# Writes an app.yaml file for use with Python Google App Engine applications.
|
89
92
|
# TODO(cgb): Add support for jquery and bootstrap? If so, also be sure to
|
90
93
|
# write those files in the given directory.
|
91
|
-
def self.write_python_app_yaml_file(
|
94
|
+
def self.write_python_app_yaml_file(app_id, output_dir, file=File)
|
92
95
|
app_yaml_contents = <<YAML
|
93
|
-
application: #{
|
96
|
+
application: #{app_id}
|
94
97
|
version: 1
|
95
98
|
runtime: python
|
96
99
|
api_version: 1
|
97
100
|
|
101
|
+
handlers:
|
98
102
|
- url: .*
|
99
103
|
script: main.py
|
100
104
|
YAML
|
@@ -109,15 +113,19 @@ YAML
|
|
109
113
|
# Sets up a standard set of routes according to the Cicero API.
|
110
114
|
# TODO(cgb): The user may have their own imports in the code - consider
|
111
115
|
# automatically placing them in as well.
|
112
|
-
def self.write_python_cicero_code(
|
116
|
+
def self.write_python_cicero_code(file_name, function_name, output_dir,
|
113
117
|
file=File)
|
114
118
|
|
119
|
+
package_name = File.basename(file_name, ".py")
|
115
120
|
template_location = File.join(File.dirname(__FILE__), "..",
|
116
121
|
"templates", "main.py")
|
117
122
|
main_py_contents = file.open(template_location) { |f| f.read }
|
118
|
-
main_py_contents.gsub!(/
|
123
|
+
main_py_contents.gsub!(/CICERO_PACKAGE_NAME/, package_name)
|
119
124
|
main_py_contents.gsub!(/CICERO_FUNCTION_NAME/, function_name)
|
120
125
|
|
126
|
+
invokable_name = package_name + "." + function_name
|
127
|
+
main_py_contents.gsub!(/CICERO_PACKAGE_AND_FUNCTION_NAME/, invokable_name)
|
128
|
+
|
121
129
|
main_py_location = file.expand_path(output_dir + File::Separator +
|
122
130
|
"main.py")
|
123
131
|
|
@@ -138,9 +146,9 @@ YAML
|
|
138
146
|
# Right now, we direct all URL requests to the Go app we are about to
|
139
147
|
# construct, but in the future we may add support for jQuery and Bootstrap
|
140
148
|
# to automatically put a nice UI on the / url.
|
141
|
-
def self.write_go_app_yaml_file(
|
149
|
+
def self.write_go_app_yaml_file(app_id, output_dir, file=File)
|
142
150
|
app_yaml_contents = <<YAML
|
143
|
-
application: #{
|
151
|
+
application: #{app_id.downcase}
|
144
152
|
version: 1
|
145
153
|
runtime: go
|
146
154
|
api_version: 3
|
@@ -171,4 +179,11 @@ YAML
|
|
171
179
|
|
172
180
|
file.open(main_go_location, "w+") { |file| file.write(main_go_contents) }
|
173
181
|
end
|
182
|
+
|
183
|
+
# Copies over any files in the directory the user has given us over to the
|
184
|
+
# new directory we are making for their App Engine app.
|
185
|
+
def self.copy_app_files(main_file, output_dir, fileutils=FileUtils)
|
186
|
+
source_dir = File.dirname(main_file) + "/."
|
187
|
+
FileUtils.cp_r(source_dir, output_dir)
|
188
|
+
end
|
174
189
|
end
|
data/test/test_generator.rb
CHANGED
@@ -8,7 +8,7 @@ require 'test/unit'
|
|
8
8
|
|
9
9
|
|
10
10
|
class DoNothingGenerator
|
11
|
-
def self.does_nothing(a, b, c)
|
11
|
+
def self.does_nothing(a, b, c, d)
|
12
12
|
end
|
13
13
|
end
|
14
14
|
|
@@ -121,30 +121,31 @@ class TestGenerator < Test::Unit::TestCase
|
|
121
121
|
# Python or Go application.
|
122
122
|
function = "blarg"
|
123
123
|
output_dir = "output_dir"
|
124
|
+
app_id = "myappid"
|
124
125
|
do_nothing_method = DoNothingGenerator.method(:does_nothing)
|
125
126
|
|
126
127
|
# c files aren't supported, so this should fail
|
127
128
|
assert_raise(SystemExit) {
|
128
|
-
Generator.generate_app("boo.c", function, output_dir,
|
129
|
-
do_nothing_method)
|
129
|
+
Generator.generate_app("boo.c", function, output_dir, app_id,
|
130
|
+
do_nothing_method, do_nothing_method)
|
130
131
|
}
|
131
132
|
|
132
133
|
# files with no extension aren't supported, so this should fail
|
133
134
|
assert_raise(SystemExit) {
|
134
|
-
Generator.generate_app("boo", function, output_dir,
|
135
|
-
do_nothing_method)
|
135
|
+
Generator.generate_app("boo", function, output_dir, app_id,
|
136
|
+
do_nothing_method, do_nothing_method)
|
136
137
|
}
|
137
138
|
|
138
139
|
# python files are supported, so this should succeed
|
139
140
|
assert_nothing_raised(SystemExit) {
|
140
|
-
Generator.generate_app("boo.py", function, output_dir,
|
141
|
-
do_nothing_method)
|
141
|
+
Generator.generate_app("boo.py", function, output_dir, app_id,
|
142
|
+
do_nothing_method, do_nothing_method)
|
142
143
|
}
|
143
144
|
|
144
145
|
# go files are supported, so this should succeed
|
145
146
|
assert_nothing_raised(SystemExit) {
|
146
|
-
Generator.generate_app("boo.go", function, output_dir,
|
147
|
-
do_nothing_method)
|
147
|
+
Generator.generate_app("boo.go", function, output_dir, app_id,
|
148
|
+
do_nothing_method, do_nothing_method)
|
148
149
|
}
|
149
150
|
end
|
150
151
|
|
data/test/test_oration.rb
CHANGED
@@ -23,31 +23,28 @@ end
|
|
23
23
|
|
24
24
|
class TestOration < Test::Unit::TestCase
|
25
25
|
def test_validate_arguments
|
26
|
-
# test when there are the wrong number of args
|
27
|
-
bad_args_1 = %w{}
|
28
|
-
bad_args_2 = %w{boo.go}
|
29
|
-
bad_args_3 = %w{boo.go boo}
|
30
|
-
bad_args_4 = %w{boo.go boo boo boo}
|
31
|
-
[bad_args_1, bad_args_2, bad_args_3, bad_args_4].each { |args|
|
32
|
-
assert_raise(SystemExit) { validate_arguments(args, FakeFile) }
|
33
|
-
}
|
34
|
-
|
35
26
|
# test when the file in question doesn't exist
|
36
|
-
|
37
|
-
|
27
|
+
assert_raise(SystemExit) {
|
28
|
+
validate_arguments('doesnt-exist.go', 'boo', 'output-dir', 'appid',
|
29
|
+
FakeFile)
|
30
|
+
}
|
38
31
|
|
39
32
|
# test when the function to be used doesn't exist in that file
|
40
|
-
|
41
|
-
|
33
|
+
assert_raise(SystemExit) {
|
34
|
+
validate_arguments('good-file.go', 'bad-function-name', 'output-dir',
|
35
|
+
'appid', FakeFile)
|
36
|
+
}
|
42
37
|
|
43
38
|
# test when the output-dir specified already exists
|
44
|
-
|
45
|
-
|
39
|
+
assert_raise(SystemExit) {
|
40
|
+
validate_arguments('good-file.go', 'good-function-name',
|
41
|
+
'output-dir-exists', 'appid', FakeFile)
|
42
|
+
}
|
46
43
|
|
47
44
|
# test when the user gives us a file that exists with the named function
|
48
|
-
good_args = %w{good-file.go good-function-name output-dir}
|
49
45
|
assert_nothing_raised(SystemExit) {
|
50
|
-
validate_arguments(
|
46
|
+
validate_arguments('good-file.go', 'good-function-name', 'output-dir',
|
47
|
+
'appid', FakeFile)
|
51
48
|
}
|
52
49
|
end
|
53
50
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: oration
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 27
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 2
|
10
|
+
version: 0.0.2
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Chris Bunch
|
@@ -15,10 +15,24 @@ autorequire: oration
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date:
|
18
|
+
date: 2012-01-22 00:00:00 -08:00
|
19
19
|
default_executable: oration
|
20
|
-
dependencies:
|
21
|
-
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
name: optiflag
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
hash: 5
|
30
|
+
segments:
|
31
|
+
- 0
|
32
|
+
- 7
|
33
|
+
version: "0.7"
|
34
|
+
type: :runtime
|
35
|
+
version_requirements: *id001
|
22
36
|
description: " Oration converts a function written in Python or Go into a Google App Engine\n application that conforms to the Cicero API, allowing the given function to\n be automatically executed over Google App Engine or AppScale in an\n embarrassingly parallel fashion.\n"
|
23
37
|
email: appscale_community@googlegroups.com
|
24
38
|
executables:
|
@@ -30,6 +44,7 @@ extra_rdoc_files:
|
|
30
44
|
files:
|
31
45
|
- bin/oration
|
32
46
|
- bin/oration.rb
|
47
|
+
- doc/OrationFlags.html
|
33
48
|
- doc/Object.html
|
34
49
|
- doc/js/jquery.js
|
35
50
|
- doc/js/darkfish.js
|