oration 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/LICENSE ADDED
@@ -0,0 +1,39 @@
1
+ =begin rdoc
2
+ Software License Agreement (BSD License)
3
+
4
+ Copyright (c) 2008, Regents of the University of California
5
+ All rights reserved.
6
+
7
+ Redistribution and use of this software in source and binary forms, with or
8
+ without modification, are permitted provided that the following conditions
9
+ are met:
10
+
11
+ * Redistributions of source code must retain the above
12
+ copyright notice, this list of conditions and the
13
+ following disclaimer.
14
+
15
+ * Redistributions in binary form must reproduce the above
16
+ copyright notice, this list of conditions and the
17
+ following disclaimer in the documentation and/or other
18
+ materials provided with the distribution.
19
+
20
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23
+ ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
24
+ LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30
+ POSSIBILITY OF SUCH DAMAGE. USERS OF THIS SOFTWARE ACKNOWLEDGE THE POSSIBLE
31
+ PRESENCE OF OTHER OPEN SOURCE LICENSED MATERIAL, COPYRIGHTED MATERIAL OR
32
+ PATENTED MATERIAL IN THIS SOFTWARE, AND IF ANY SUCH MATERIAL IS DISCOVERED THE PARTY
33
+ DISCOVERING IT MAY INFORM DR. CHANDRA KRINTZ AT THE UNIVERSITY OF CALIFORNIA,
34
+ SANTA BARBARA WHO WILL THEN ASCERTAIN THE MOST APPROPRIATE REMEDY, WHICH
35
+ IN THE REGENTS’ DISCRETION MAY INCLUDE, WITHOUT LIMITATION, REPLACEMENT
36
+ OF THE CODE SO IDENTIFIED, LICENSING OF THE CODE SO IDENTIFIED, OR WITHDRAWAL
37
+ OF THE CODE CAPABILITY TO THE EXTENT NEEDED TO COMPLY WITH ANY SUCH LICENSES
38
+ OR RIGHTS.
39
+ =end
data/bin/oration ADDED
@@ -0,0 +1,56 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # Programmer: Chris Bunch
4
+
5
+ $:.unshift File.join(File.dirname(__FILE__), "..", "lib")
6
+ require 'generator'
7
+
8
+
9
+ # This method takes in the arguments given to oration and validates them.
10
+ # Right now it's just three arguments: the name of the main code file to
11
+ # exec, the name of the function in that file that should be exec'd, and
12
+ # where we should write their App Engine app.
13
+ # We validate that the file specified exists and has a function
14
+ # with that name, and that the directory they specified doesn't exist (so
15
+ # that we don't overwrite anything already there).
16
+ def validate_arguments(arguments, file=File)
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
+
25
+ if !file.exists?(main_file)
26
+ abort("#{main_file} didn't exist.")
27
+ end
28
+
29
+ contents = file.open(main_file) { |f| f.read }
30
+
31
+ # Right now we support Python and Go code, so match against method
32
+ # signatures in those languages.
33
+ python_sig = /def #{function_name}\(/
34
+ go_method_sig = /func #{function_name}\(/
35
+ all_languages_method_sig_regex = /#{python_sig}|#{go_method_sig}/
36
+
37
+ if !contents.match(all_languages_method_sig_regex)
38
+ abort("We couldn't find the function #{function_name} in the file " +
39
+ "#{main_file}")
40
+ end
41
+
42
+ if file.exists?(output_dir)
43
+ abort("The output location specified, #{output_dir}, already exists." +
44
+ " Please remove it and try again.")
45
+ end
46
+ end
47
+
48
+
49
+ # Normally we would just check if __FILE__ == $0, but this doesn't work if
50
+ # RubyGems is exec'ing this file, so instead just check if the thing we're
51
+ # executing ends in /bin/oration, the relative location of this file.
52
+ if $0.match(/\/bin\/oration\Z/)
53
+ validate_arguments(ARGV)
54
+ Generator.generate_app(ARGV[0], ARGV[1], ARGV[2])
55
+ puts "Done! Your application can be found at #{ARGV[2]}"
56
+ end
data/bin/oration.rb ADDED
@@ -0,0 +1,56 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # Programmer: Chris Bunch
4
+
5
+ $:.unshift File.join(File.dirname(__FILE__), "..", "lib")
6
+ require 'generator'
7
+
8
+
9
+ # This method takes in the arguments given to oration and validates them.
10
+ # Right now it's just three arguments: the name of the main code file to
11
+ # exec, the name of the function in that file that should be exec'd, and
12
+ # where we should write their App Engine app.
13
+ # We validate that the file specified exists and has a function
14
+ # with that name, and that the directory they specified doesn't exist (so
15
+ # that we don't overwrite anything already there).
16
+ def validate_arguments(arguments, file=File)
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
+
25
+ if !file.exists?(main_file)
26
+ abort("#{main_file} didn't exist.")
27
+ end
28
+
29
+ contents = file.open(main_file) { |f| f.read }
30
+
31
+ # Right now we support Python and Go code, so match against method
32
+ # signatures in those languages.
33
+ python_sig = /def #{function_name}\(/
34
+ go_method_sig = /func #{function_name}\(/
35
+ all_languages_method_sig_regex = /#{python_sig}|#{go_method_sig}/
36
+
37
+ if !contents.match(all_languages_method_sig_regex)
38
+ abort("We couldn't find the function #{function_name} in the file " +
39
+ "#{main_file}")
40
+ end
41
+
42
+ if file.exists?(output_dir)
43
+ abort("The output location specified, #{output_dir}, already exists." +
44
+ " Please remove it and try again.")
45
+ end
46
+ end
47
+
48
+
49
+ # Normally we would just check if __FILE__ == $0, but this doesn't work if
50
+ # RubyGems is exec'ing this file, so instead just check if the thing we're
51
+ # executing ends in /bin/oration, the relative location of this file.
52
+ if $0.match(/\/bin\/oration\Z/)
53
+ validate_arguments(ARGV)
54
+ Generator.generate_app(ARGV[0], ARGV[1], ARGV[2])
55
+ puts "Done! Your application can be found at #{ARGV[2]}"
56
+ end