rook 0.0.2 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (87) hide show
  1. data/README.txt +124 -37
  2. data/bin/rook +8 -902
  3. data/doc-api/classes/BZ2.html +111 -0
  4. data/doc-api/classes/BZ2/Reader.html +234 -0
  5. data/doc-api/classes/Digest.html +107 -0
  6. data/doc-api/classes/Digest/Base.html +254 -0
  7. data/doc-api/classes/Enumerable.html +430 -0
  8. data/doc-api/classes/File.html +208 -0
  9. data/doc-api/classes/FileUtils.html +758 -0
  10. data/doc-api/classes/Kernel.html +317 -0
  11. data/doc-api/classes/Rook.html +148 -0
  12. data/doc-api/classes/Rook/Assertion.html +164 -0
  13. data/doc-api/classes/Rook/AssertionError.html +111 -0
  14. data/doc-api/classes/Rook/CommandOptionError.html +113 -0
  15. data/doc-api/classes/Rook/Commands.html +1158 -0
  16. data/doc-api/classes/Rook/Cookbook.html +357 -0
  17. data/doc-api/classes/Rook/CookbookError.html +161 -0
  18. data/doc-api/classes/Rook/CookbookValidator.html +215 -0
  19. data/doc-api/classes/Rook/Kitchen.html +875 -0
  20. data/doc-api/classes/Rook/KitchenHelper.html +386 -0
  21. data/doc-api/classes/Rook/Main.html +325 -0
  22. data/doc-api/classes/Rook/Parameters.html +443 -0
  23. data/doc-api/classes/Rook/Recipe.html +546 -0
  24. data/doc-api/classes/Rook/RookError.html +111 -0
  25. data/doc-api/classes/Rook/Util.html +408 -0
  26. data/doc-api/classes/Rook/Util/UndefinedPropertyError.html +160 -0
  27. data/doc-api/created.rid +1 -0
  28. data/doc-api/files/__/README_txt.html +313 -0
  29. data/doc-api/files/rook/commands_rb.html +115 -0
  30. data/doc-api/files/rook/cookbook_rb.html +115 -0
  31. data/doc-api/files/rook/helper/bz2_rb.html +114 -0
  32. data/doc-api/files/rook/helper/digest_rb.html +114 -0
  33. data/doc-api/files/rook/helper/enumerable_rb.html +107 -0
  34. data/doc-api/files/rook/helper/file_rb.html +107 -0
  35. data/doc-api/files/rook/helper/fileutils_rb.html +124 -0
  36. data/doc-api/files/rook/helper/kernel_rb.html +107 -0
  37. data/doc-api/files/rook/kitchen_rb.html +117 -0
  38. data/doc-api/files/rook/main_rb.html +117 -0
  39. data/doc-api/files/rook/recipe_rb.html +114 -0
  40. data/doc-api/files/rook/util_rb.html +115 -0
  41. data/doc-api/files/rook_rb.html +122 -0
  42. data/doc-api/fr_class_index.html +50 -0
  43. data/doc-api/fr_file_index.html +40 -0
  44. data/doc-api/fr_method_index.html +181 -0
  45. data/doc-api/index.html +24 -0
  46. data/doc-api/rdoc-style.css +208 -0
  47. data/examples/hello_c/Rookbook.rb +37 -0
  48. data/examples/hello_c/Rookbook.yaml +45 -0
  49. data/examples/hello_c/hello.c +6 -3
  50. data/examples/project/README.txt +8 -0
  51. data/examples/project/Rookbook.props +1 -0
  52. data/examples/project/Rookbook.rb +120 -0
  53. data/examples/project/Rookbook.yaml +117 -0
  54. data/examples/project/bin/example +12 -0
  55. data/examples/project/example.gemspec +29 -0
  56. data/examples/project/lib/example.rb +36 -0
  57. data/examples/{archive → project}/lib/example/bar.rb +0 -0
  58. data/examples/{archive → project}/lib/example/baz.rb +0 -0
  59. data/examples/{archive → project}/lib/example/foo.rb +0 -0
  60. data/examples/project/setup.rb +1331 -0
  61. data/examples/project/test/test.rb +27 -0
  62. data/lib/rook.rb +50 -0
  63. data/lib/rook/commands.rb +426 -0
  64. data/lib/rook/cookbook.rb +237 -0
  65. data/lib/rook/helper/bz2.rb +39 -0
  66. data/lib/rook/helper/digest.rb +76 -0
  67. data/lib/rook/helper/enumerable.rb +121 -0
  68. data/lib/rook/helper/file.rb +50 -0
  69. data/lib/rook/helper/fileutils.rb +340 -0
  70. data/lib/rook/helper/kernel.rb +108 -0
  71. data/lib/rook/kitchen.rb +668 -0
  72. data/lib/rook/main.rb +280 -0
  73. data/lib/rook/recipe.rb +259 -0
  74. data/lib/rook/rookbook.schema.yaml +156 -0
  75. data/lib/rook/util.rb +172 -0
  76. data/rook.gemspec +56 -0
  77. metadata +139 -45
  78. data/examples/archive/COPYING +0 -340
  79. data/examples/archive/README.txt +0 -1
  80. data/examples/archive/Rookbook +0 -56
  81. data/examples/archive/bin/example +0 -0
  82. data/examples/archive/doc/index.html +0 -0
  83. data/examples/archive/doc/index.txt +0 -0
  84. data/examples/archive/lib/example.rb +0 -0
  85. data/examples/archive/test/test1.rb +0 -0
  86. data/examples/archive/test/test2.rb +0 -0
  87. data/examples/hello_c/Rookbook +0 -24
@@ -0,0 +1,280 @@
1
+ ##
2
+ ## $Rev: 29 $
3
+ ## $Release: 0.1.0 $
4
+ ## copyright(c) 2006 kuwata-lab.com all rights reserved.
5
+ ##
6
+
7
+ require 'rook'
8
+ require 'pp'
9
+
10
+ #require 'rook/dsl'
11
+ #include Rook::DslHelper
12
+
13
+ require 'rook/helper/kernel'
14
+ require 'rook/helper/enumerable'
15
+
16
+
17
+
18
+ module Rook
19
+
20
+
21
+
22
+ class CommandOptionError < RookError
23
+ end
24
+
25
+
26
+
27
+ class Main
28
+
29
+
30
+ def initialize(argv=ARGV, stdout=$stdout, stderr=$stderr)
31
+ @argv = argv
32
+ @stdout = stdout
33
+ @stderr = stderr
34
+ @options, @properties = parse_argv(@argv)
35
+ @options[?h] = true if @properties['help'] == true
36
+ @products = argv
37
+ end
38
+
39
+
40
+ def self.main(argv=ARGV, stdout=$stdout, stderr=$stderr)
41
+ status = 0
42
+ begin
43
+ main = self.new(argv, stdout, stderr)
44
+ main.execute()
45
+ rescue RookError => ex
46
+ status = 1
47
+ raise ex if $rook_debug
48
+ stderr.puts "*** error: #{ex.message}"
49
+ end
50
+ exit status
51
+ end
52
+
53
+
54
+ def execute
55
+ options = @options
56
+ properties = @properties
57
+ products = @products
58
+
59
+ ##
60
+ $rook_debug = true if @options[?D] # or $DEBUG
61
+ $KCODE = @options[?k] if @options[?k]
62
+
63
+ ## help and version
64
+ if @options[?h] || @options[?v]
65
+ cmdname = File.basename($0)
66
+ #desc = "#{cmdname} - a SCM (software configuration management) tool like Make, Rake, Ant, or Cook.\n"
67
+ desc = "#{cmdname} - a SCM (Software Cooking Management) tool like Make, Rake, Ant, or Cook.\n"
68
+ @stdout.puts version() if @options[?v]
69
+ @stdout.puts desc if @options[?h]
70
+ @stdout.puts help() if @options[?h]
71
+ return
72
+ end
73
+
74
+ ## require libraries
75
+ @options[?r].split(/,/).each { |lib| require lib } if @options[?r]
76
+
77
+ ## bookname
78
+ bookname = @options[?f] || @options[?b]
79
+ if bookname
80
+ test(?f, bookname) or raise CommandOptionError.new("cookbook '#{bookname}' not found.")
81
+ else
82
+ ['.yaml', '.yml', '.rb', ''].each do |suffix|
83
+ break if test(?f, bookname = "Rookbook#{suffix}")
84
+ break if test(?f, bookname = "rookbook#{suffix}")
85
+ bookname = nil
86
+ end
87
+ bookname or raise CommandOptionError.new("cookbook 'Rookbook.yaml' or 'Rookbook.rb' not found.")
88
+ end
89
+
90
+ ## properties filename
91
+ propfile = @options[?P]
92
+ if propfile
93
+ test(?f, propfile) or raise CommandOptionError.new("file '#{propfile}' not found.")
94
+ else
95
+ %w[Rookbook.props properties.yaml].each do |f|
96
+ break propfile = f if test(?f, f)
97
+ end
98
+ end
99
+ if propfile
100
+ props = YAML.load_file(propfile)
101
+ props.each do |k, v|
102
+ @properties[k] = v unless @properties.key?(k)
103
+ end
104
+ end
105
+
106
+ ## global options
107
+ $rook_verbose = @options[?V] ? true : (@options[?q] ? false : nil)
108
+ $rook_forced = @options[?F]
109
+ $rook_noexec = @options[?n] ? 1 : (@options[?N] ? 2 : nil)
110
+
111
+ # kitchen
112
+ props = { :verbose=>$rook_verbose, :forced=>$rook_forced, :noexec=>$rook_noexec }
113
+ kitchen = Kitchen.new(@properties, props)
114
+
115
+ ## cookbook
116
+ if bookname =~ /\.ya?ml\z/
117
+ flag_expand_tab = !options[?T]
118
+ begin
119
+ cookbook = Cookbook.new(bookname, true, flag_expand_tab)
120
+ rescue CookbookError => ex
121
+ @stderr.puts "validation error:"
122
+ ex.errors.each do |error|
123
+ e = error
124
+ @stderr.puts " - line #{e.linenum}: [#{e.path}] #{e.message}"
125
+ end
126
+ return
127
+ end
128
+ kitchen.load_book(cookbook)
129
+ else
130
+ kitchen.load_script(bookname)
131
+ end
132
+
133
+ ## list recipes
134
+ if @options[?l] || @options[?L]
135
+ show_all = @options[?L] ? true : false
136
+ list_properties(kitchen, show_all)
137
+ @stdout.puts
138
+ list_recipes(kitchen, @options[?L])
139
+ return
140
+ end
141
+
142
+ ## show property value
143
+ if @options[?p]
144
+ @options[?p].split(/,/).each do |pname|
145
+ pp kitchen.get_property(pname)
146
+ end
147
+ return
148
+ end
149
+
150
+ ## target product
151
+ if @products && !@products.empty?
152
+ products = @products
153
+ elsif kitchen.find_specific_recipe(:default)
154
+ products = [ :default ]
155
+ elsif prod = kitchen.get_variable('rook_product')
156
+ products = [ prod ]
157
+ elsif prod = kitchen.get_property('rook_product')
158
+ products = [ prod ]
159
+ else
160
+ @stderr.puts "*** no product specified."
161
+ list_recipes(kitchen)
162
+ return
163
+ end
164
+
165
+ ## start cooking
166
+ products.each do |product|
167
+ product = product.sub(/\A:/, '').intern if product.is_a?(String) && product[0] == ?:
168
+ kitchen.start_cooking(product)
169
+ end
170
+
171
+ end
172
+
173
+
174
+ private
175
+
176
+
177
+ def list_properties(kitchen, show_all=false)
178
+ @stdout.puts "properites:"
179
+ kitchen.properties.each do |hash|
180
+ next unless show_all || hash['access'] == 'public'
181
+ @stdout.puts " %-18s = %s" % [hash['name'], hash['value'].inspect]
182
+ end
183
+ return unless show_all
184
+ @stdout.puts "\nvariables:"
185
+ kitchen.variables.each do |hash|
186
+ @stdout.puts " %-18s = %s" % [hash['name'], hash['value'].inspect]
187
+ end
188
+ end
189
+
190
+
191
+ def list_recipes(kitchen, show_all=false)
192
+ @stdout.puts "recipes:"
193
+ kitchen.recipes.each do |r|
194
+ @stdout.puts " %-18s : %s" % [Util.to_str(r.product), r.desc] if show_all || r.public?
195
+ end
196
+ end
197
+
198
+
199
+ def help
200
+ cmdname = File.basename($0)
201
+ s = ""
202
+ #s << " http://www.kuwata-lab.com/rook/\n"
203
+ s << "Usage: #{cmdname} [-hvTFnNqQVlLc] [-f bookname] [-k kanji] [-F[n]] product...\n"
204
+ s << " -h : help\n"
205
+ s << " -v : version\n"
206
+ s << " -t : expand tab character in cookbook\n"
207
+ s << " -T : don't expand tab character in cookbook\n"
208
+ s << " -n : no execute\n"
209
+ s << " -N : never execute\n"
210
+ s << " -q : quiet\n"
211
+ s << " -Q : more quiet\n"
212
+ s << " -V : verbose\n"
213
+ s << " -l : list public recipes and properties\n"
214
+ s << " -L : list all recipes, properties, and variables\n"
215
+ s << " -c : validation check of cookbook\n"
216
+ s << " -F : execute forcelly\n"
217
+ s << " -b bookname : cookbook name\n"
218
+ s << " -f bookname : equal to `-b bookname'\n"
219
+ s << " -p property : show property value in 'pp' format\n"
220
+ s << " -k kanji : kanji code (euc/sjis/utf8)\n"
221
+ s << " -r file[,..] : require libraries\n"
222
+ s << " --name=value : property name and value\n"
223
+ return s
224
+ end
225
+
226
+
227
+ def version
228
+ return ('$Release: 0.1.0 $' =~ /[\.\d]+/) && $&
229
+ end
230
+
231
+
232
+ def parse_argv(argv)
233
+ options = {}
234
+ properties = {}
235
+ while !argv.empty? && argv[0][0] == ?-
236
+ optstr = argv.shift
237
+ break if optstr == '-'
238
+ if optstr[1] == ?- # property
239
+ unless optstr =~ /\A--([a-zA-Z_]\w*)(?:=(.*))?\z/
240
+ raise CommandOptionError.new("#{optstr}: invalid option pattern.")
241
+ end
242
+ name = $1
243
+ value = YAML.load($2)
244
+ properties[name] = value
245
+ else # option
246
+ optstr = optstr.sub(/^-/, '')
247
+ while optstr && !optstr.empty?
248
+ optch = optstr[0]
249
+ optstr[0, 1] = ''
250
+ case optch
251
+ when ?h, ?v, ?c, ?t, ?T, ?n, ?N, ?q, ?Q, ?V, ?l, ?L
252
+ options[optch] = true
253
+ when ?f, ?b, ?k, ?r, ?p
254
+ arg = optstr.empty? ? argv.shift : optstr
255
+ unless arg
256
+ hash = { ?f => 'bookname', ?b => 'bookname', ?k => 'kanji code',
257
+ ?r => 'library', ?p => 'property', }
258
+ raise CommandOptionError.new("-#{optch.chr}: #{hash[optch]} required.")
259
+ end
260
+ options[optch] = arg
261
+ optstr = nil
262
+ when ?F, ?D
263
+ arg = optstr.empty? ? true : optstr
264
+ options[optch] = arg
265
+ optstr = nil
266
+ else
267
+ raise CommandOptionError.new("-#{optch.chr}: invalid option.")
268
+ end
269
+ end
270
+ end
271
+ end
272
+ return options, properties
273
+ end
274
+
275
+
276
+ end
277
+
278
+
279
+
280
+ end
@@ -0,0 +1,259 @@
1
+ ##
2
+ ## $Rev: 28 $
3
+ ## $Release: 0.1.0 $
4
+ ## copyright(c) 2006 kuwata-lab.com all rights reserved.
5
+ ##
6
+
7
+
8
+ require 'rook/util'
9
+
10
+
11
+
12
+ module Rook
13
+
14
+
15
+
16
+ ##
17
+ ## recipe
18
+ ##
19
+ ## ex.
20
+ ## hash = {
21
+ ## 'product'=>'hello.o',
22
+ ## 'ingreds'=>['hello.c'],
23
+ ## 'options'=>['hello.h'],
24
+ ## }
25
+ ##
26
+ ## recipe1 = Recipe.new(hash) { gcc -o #{@product} #{@ingred} }
27
+ ## recipe1.invoke()
28
+ ##
29
+ ## hash['method'] = 'gcc -o #{@product} #{@ingred}'
30
+ ## recipe2 = Recipe.new(hash)
31
+ ## recipe2.invoke()
32
+ ##
33
+ class Recipe
34
+ include Assertion
35
+
36
+
37
+ alias __method__ method
38
+ alias __methods__ methods
39
+
40
+
41
+ def initialize(hash, &block)
42
+ @product = hash['product']
43
+ @product = eval @product if @product.is_a?(String) && @product =~ /\A\/(.*)\/\z/
44
+ @ingreds = (hash['ingreds'] || []).flatten()
45
+ @coprods = (hash['coprods'] || []).flatten()
46
+ @byprods = (hash['byprods'] || []).flatten()
47
+ @options = (hash['options'] || []).flatten()
48
+ @kind = hash['kind'] || _detect_kind(@product)
49
+ @desc = hash['desc']
50
+ @method = hash['method']
51
+ @block = block || hash['block']
52
+ @desc = hash['desc'] || _default_desc(@product)
53
+ @access = hash['access'] || (@desc ? 'public' : 'private')
54
+ @forced = hash.key?('forced') ? hash['forced'] : @product.is_a?(Symbol)
55
+ @symbolic = hash.key?('symbolic') ? hash['symbolic'] : @product.is_a?(Symbol)
56
+ @verbose = hash['verbose']
57
+ @fingerprint = hash['fingerprint']
58
+ @bookname = hash['bookname']
59
+ @linenum = hash['linenum'] # start linenumber of method part
60
+ @pattern = _compile_pattern(@product) if @kind == 'generic'
61
+ end
62
+ attr_accessor :product, :ingreds, :coprods, :byprods, :options, :kind, :desc, :method
63
+ attr_accessor :block, :access, :forced, :symbolic, :verbose, :fingerprint
64
+ attr_accessor :bookname, :linenum, :pattern, :matches
65
+
66
+
67
+ #--
68
+ #def _member_names
69
+ # return %w[product ingreds coprods byprods options desc kind method
70
+ # block access forced symbolic verbose bookname linenum]
71
+ #end
72
+ #private :_member_names
73
+ #++
74
+
75
+
76
+ def match?(product)
77
+ return (@pattern || @product) === product
78
+ end
79
+
80
+
81
+ def public?
82
+ return @access == 'public'
83
+ end
84
+
85
+
86
+ def forced?
87
+ return @forced
88
+ end
89
+
90
+
91
+ def verbose?
92
+ return @verbose
93
+ end
94
+
95
+
96
+ def symbolic?
97
+ return @symbolic
98
+ end
99
+
100
+
101
+ def all_products
102
+ list = [ @product ]
103
+ list.concat @coprods if @coprods
104
+ list.concat @byprods if @byprods
105
+ return list
106
+ end
107
+
108
+
109
+ def all_ingredients
110
+ list = []
111
+ list.concat @ingreds if @ingreds
112
+ list.concat @options if @options
113
+ return list
114
+ end
115
+
116
+
117
+ def _default_desc(product)
118
+ return nil unless product.is_a?(Symbol)
119
+ case @product
120
+ when :all ; return 'cook all'
121
+ when :clean ; return 'remove all byproducts and itermediates'
122
+ when :clear ; return 'remove all byproducts, intermediates, and products'
123
+ when :compile ; return 'compile ingredients'
124
+ when :test ; return 'do test'
125
+ when :config ; return 'configure'
126
+ when :setup ; return 'do setup'
127
+ when :install ; return 'do install'
128
+ when :deploy ; return 'deploy modules'
129
+ when :package ; return 'create package'
130
+ when :doc ; return 'generate documents'
131
+ else ; return nil
132
+ end
133
+ end
134
+ private :_default_desc
135
+
136
+
137
+ def _detect_kind(product)
138
+ case product
139
+ when Symbol ; return 'specific'
140
+ when Regexp ; return 'generic'
141
+ #when /\A\/.*\/i?\z/ ; return 'generic'
142
+ else
143
+ return Util.has_meta?(product) ? 'generic' : 'specific'
144
+ end
145
+ end
146
+ private :_detect_kind
147
+
148
+
149
+ def _compile_pattern(product)
150
+ return product if product.is_a?(Regexp)
151
+ return eval(product) if product =~ /\A\/.*\/i?\z/
152
+ return Util.meta2regexp(product)
153
+ end
154
+ private :_compile_pattern
155
+
156
+
157
+ def to_specific(product)
158
+ return self unless @pattern
159
+ matches = @pattern.match(product)
160
+ matches or raise RookError.new("product '#{product}' doesn't match to /#{@pattern.source}/")
161
+ hash = { 'product' => product }
162
+ instance_variables.each do |var|
163
+ next if var == '@product'
164
+ w = var[1, var.length-1] # '@name' => 'name'
165
+ hash[w] = Util.expand_matches(instance_variable_get(var), matches)
166
+ end
167
+ hash['kind'] = 'specific'
168
+ recipe = Recipe.new(hash)
169
+ recipe.matches = matches
170
+ return recipe
171
+ end
172
+
173
+
174
+ def invoke(parameters)
175
+ Oven.new(self).bake(parameters)
176
+ end
177
+
178
+
179
+ end
180
+
181
+
182
+
183
+ class Oven # :nodoc:
184
+ include Commands, Assertion
185
+
186
+
187
+ def initialize(recipe)
188
+ recipe.instance_variables.each do |name|
189
+ value = recipe.instance_variable_get(name)
190
+ instance_variable_set(name, value)
191
+ end
192
+ @ingred = @ingreds.first if @ingreds
193
+ @coprod = @coprods.first if @coprods
194
+ @byprod = @byprods.first if @byprods
195
+ @option = @options.first if @options
196
+ end
197
+
198
+
199
+ def bake(_parameters)
200
+ ## copy properties as instance variable
201
+ _parameters.property_names.each do |name|
202
+ instance_variable_set("@#{name}", _parameters.get_property(name))
203
+ end
204
+ ## invoke @block or @method
205
+ if @block
206
+ self.instance_eval(&@block)
207
+ elsif @method
208
+ ## set variables as local vars
209
+ @_vars = {}
210
+ _code = []
211
+ _parameters.variable_names.each do |name|
212
+ @_vars[name] = _parameters.get_variable(name)
213
+ _code << "#{name}=@_vars['#{name}'];"
214
+ end
215
+ _code << @method
216
+ self.instance_eval(_code.join, @bookname, @linenum)
217
+ end
218
+ end
219
+
220
+
221
+ end
222
+
223
+
224
+
225
+ # class SymbolicRecipe < Recipe
226
+ # def match?(product)
227
+ # @product == product
228
+ # end
229
+ # def to_specific(product)
230
+ # self
231
+ # end
232
+ # end
233
+ #
234
+ # class SpecificRecipe < Recipe
235
+ # def match?(product)
236
+ # @product == product
237
+ # end
238
+ # def to_specific(product)
239
+ # self
240
+ # end
241
+ # end
242
+ #
243
+ # class GenericRecipe < Recipe
244
+ # def match?(product)
245
+ # @pattern =~ product
246
+ # end
247
+ # def to_specific(product)
248
+ # matches = @pattern.match(product)
249
+ # hash = { 'product' => product }
250
+ # _member_names.each do |name|
251
+ # hash[name] = Util.expand_matches(instance_variable_get(name), matches)
252
+ # end
253
+ # SpecificRecipe.new(hash)
254
+ # end
255
+ # end
256
+
257
+
258
+
259
+ end