knife-chop 0.2.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (55) hide show
  1. checksums.yaml +15 -0
  2. data/Gemfile +24 -0
  3. data/Gemfile.lock +154 -0
  4. data/LICENSE.txt +20 -0
  5. data/README.rdoc +23 -0
  6. data/Rakefile +54 -0
  7. data/TODO.rdoc +46 -0
  8. data/VERSION +1 -0
  9. data/bin/chop +48 -0
  10. data/knife-chop.gemspec +118 -0
  11. data/lib/chef/knife/chop/chef_data_bag_item.rb +43 -0
  12. data/lib/chef/knife/chop/chef_environment.rb +47 -0
  13. data/lib/chef/knife/chop/chef_knife.rb +85 -0
  14. data/lib/chef/knife/chop/chef_part.rb +191 -0
  15. data/lib/chef/knife/chop/chef_role.rb +48 -0
  16. data/lib/chef/knife/chop/cookbook_upload.rb +143 -0
  17. data/lib/chef/knife/chop/data_bag_from_file.rb +87 -0
  18. data/lib/chef/knife/chop/environment_from_file.rb +79 -0
  19. data/lib/chef/knife/chop/errors.rb +5 -0
  20. data/lib/chef/knife/chop/logging.rb +245 -0
  21. data/lib/chef/knife/chop/role_from_file.rb +45 -0
  22. data/lib/chef/knife/chop/translate.rb +23 -0
  23. data/lib/chef/knife/chop/translate/eden.rb +23 -0
  24. data/lib/chef/knife/chop/translate/rbeautify.rb +24 -0
  25. data/lib/chef/knife/chop/ui.rb +110 -0
  26. data/lib/chef/knife/chop/version.rb +9 -0
  27. data/lib/chef/knife/chop_base.rb +821 -0
  28. data/lib/chef/knife/chop_translate.rb +161 -0
  29. data/lib/chef/knife/chop_upload.rb +199 -0
  30. data/lib/ruby-beautify/Gemfile +4 -0
  31. data/lib/ruby-beautify/LICENSE +22 -0
  32. data/lib/ruby-beautify/README.md +39 -0
  33. data/lib/ruby-beautify/RELEASE.md +13 -0
  34. data/lib/ruby-beautify/Rakefile +2 -0
  35. data/lib/ruby-beautify/bin/rbeautify +28 -0
  36. data/lib/ruby-beautify/lib/beautifier.rb +168 -0
  37. data/lib/ruby-beautify/lib/ruby-beautify.rb +26 -0
  38. data/lib/ruby-beautify/lib/ruby-beautify/block_end.rb +23 -0
  39. data/lib/ruby-beautify/lib/ruby-beautify/block_matcher.rb +153 -0
  40. data/lib/ruby-beautify/lib/ruby-beautify/block_start.rb +119 -0
  41. data/lib/ruby-beautify/lib/ruby-beautify/config/ruby.rb +131 -0
  42. data/lib/ruby-beautify/lib/ruby-beautify/language.rb +37 -0
  43. data/lib/ruby-beautify/lib/ruby-beautify/line.rb +53 -0
  44. data/lib/ruby-beautify/lib/ruby-beautify/version.rb +3 -0
  45. data/lib/ruby-beautify/ruby-beautify.gemspec +17 -0
  46. data/lib/ruby-beautify/spec/fixtures/ruby.yml +408 -0
  47. data/lib/ruby-beautify/spec/rbeautify/block_matcher_spec.rb +89 -0
  48. data/lib/ruby-beautify/spec/rbeautify/block_start_spec.rb +51 -0
  49. data/lib/ruby-beautify/spec/rbeautify/config/ruby_spec.rb +183 -0
  50. data/lib/ruby-beautify/spec/rbeautify/line_spec.rb +73 -0
  51. data/lib/ruby-beautify/spec/rbeautify_spec.rb +1 -0
  52. data/lib/ruby-beautify/spec/spec_helper.rb +124 -0
  53. data/spec/knife-chop_spec.rb +7 -0
  54. data/spec/spec_helper.rb +12 -0
  55. metadata +233 -0
@@ -0,0 +1,87 @@
1
+ #
2
+ # Author:: Adam Jacob (<adam@opscode.com>)
3
+ # Author:: Seth Falcon (<seth@opscode.com>)
4
+ # Copyright:: Copyright (c) 2010 Opscode, Inc.
5
+ # License:: Apache License, Version 2.0
6
+ #
7
+ # Licensed under the Apache License, Version 2.0 (the "License");
8
+ # you may not use this file except in compliance with the License.
9
+ # You may obtain a copy of the License at
10
+ #
11
+ # http://www.apache.org/licenses/LICENSE-2.0
12
+ #
13
+ # Unless required by applicable law or agreed to in writing, software
14
+ # distributed under the License is distributed on an "AS IS" BASIS,
15
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
+ # See the License for the specific language governing permissions and
17
+ # limitations under the License.
18
+ #
19
+
20
+ class ::Chef::Knife::DataBagFromFile
21
+
22
+ # --------------------------------------------------------------------------------------------------------------------
23
+ # Create a new instance of the current class configured for the given
24
+ # arguments and options
25
+ def initialize(argv=[])
26
+ super(argv)
27
+ @rsrctype = 'databag'
28
+ @location = 'data_bags'
29
+ end
30
+
31
+ ## --------------------------------------------------------------------------------------------------------------------
32
+ #def translate()
33
+ # if config[:all] == true
34
+ # translate_all_data_bags()
35
+ # else
36
+ # if @name_args[0].nil?
37
+ # show_usage
38
+ # ui.fatal("You must specify a file to translate")
39
+ # exit 1
40
+ # end
41
+ #
42
+ # @data_bag = @name_args.shift
43
+ # translate_data_bag_items(@data_bag, @name_args)
44
+ # end
45
+ #end
46
+
47
+ ## --------------------------------------------------------------------------------------------------------------------
48
+ #def translate_data_bag_items(data_bag, items = nil)
49
+ # items ||= find_all_data_bag_items(data_bag)
50
+ # item_paths = normalize_item_paths(items)
51
+ # item_paths.each do |item_path|
52
+ # item = loader.load_from("#{data_bags_path}", data_bag, item_path)
53
+ # dbag = ::Chef::DataBagItem.new
54
+ # dbag.data_bag(data_bag)
55
+ # dbag.raw_data = item
56
+ # part = ::Chef::Part.new(dbag,location)
57
+ # part.translate(@config)
58
+ # resource = part.resource
59
+ # output(format_for_display(resource)) if config[:print_after]
60
+ # ui.info("Translated #{@rsrctype.capitalize} #{resource.name}")
61
+ # end
62
+ #end
63
+ #
64
+ ## --------------------------------------------------------------------------------------------------------------------
65
+ #def data_bags_path
66
+ # @data_bag_path ||= "data_bags"
67
+ #end
68
+ #
69
+ ## --------------------------------------------------------------------------------------------------------------------
70
+ #def translate_all_data_bags
71
+ # loader.find_all_object_dirs("./#{data_bags_path}")
72
+ #end
73
+ #
74
+ ## --------------------------------------------------------------------------------------------------------------------
75
+ #def find_all_data_bag_items(data_bag)
76
+ # loader.find_all_objects("./#{data_bags_path}/#{data_bag}")
77
+ #end
78
+ #
79
+ ## --------------------------------------------------------------------------------------------------------------------
80
+ #def translate_all_data_bags(args)
81
+ # data_bags = args.empty? ? find_all_data_bags : [args.shift]
82
+ # data_bags.each do |data_bag|
83
+ # load_data_bag_items(data_bag)
84
+ # end
85
+ #end
86
+
87
+ end
@@ -0,0 +1,79 @@
1
+ #
2
+ # Author:: Stephen Delano (<stephen@opscode.com>)
3
+ # Copyright:: Copyright (c) 2010 Opscode, Inc.
4
+ # License:: Apache License, Version 2.0
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+ #
18
+
19
+ class ::Chef::Knife::EnvironmentFromFile
20
+
21
+ # --------------------------------------------------------------------------------------------------------------------
22
+ # Create a new instance of the current class configured for the given
23
+ # arguments and options
24
+ def initialize(argv=[])
25
+ super(argv)
26
+ @rsrctype = 'environment'
27
+ @location = 'environments'
28
+ end
29
+
30
+ # --------------------------------------------------------------------------------------------------------------------
31
+ def load_environment(env)
32
+ updated = loader.load_from("environments", env)
33
+ updated.save
34
+ output(format_for_display(updated)) if config[:print_after]
35
+ ui.step("Updated Environment #{updated.name}")
36
+ end
37
+
38
+ # --------------------------------------------------------------------------------------------------------------------
39
+ def run
40
+ if config[:all] == true
41
+ load_all_environments
42
+ else
43
+ if @name_args[0].nil?
44
+ show_usage
45
+ ui.fatal("You must specify a file to load")
46
+ exit 1
47
+ end
48
+
49
+ @name_args.each do |arg|
50
+ load_environment(arg)
51
+ end
52
+ end
53
+ end
54
+
55
+ # --------------------------------------------------------------------------------------------------------------------
56
+ private
57
+ # --------------------------------------------------------------------------------------------------------------------
58
+
59
+ # --------------------------------------------------------------------------------------------------------------------
60
+ def translate_all_environments
61
+ environments = find_all_environments
62
+ if environments.empty?
63
+ ui.fatal("Unable to find any environment files in '#{environments_path}'")
64
+ exit(1)
65
+ end
66
+ environments.each do |env|
67
+ translate_environment(env)
68
+ end
69
+ end
70
+
71
+ # --------------------------------------------------------------------------------------------------------------------
72
+ def translate_environment(env)
73
+ updated = loader.load_from("environments", env)
74
+ updated.translate(@config,env)
75
+ output(format_for_display(updated)) if config[:print_after]
76
+ ui.info("Translated Environment #{updated.name}")
77
+ end
78
+
79
+ end
@@ -0,0 +1,5 @@
1
+ module ChopErrors
2
+ class ChopError < StandardError ; end
3
+ class ChopOptionError < ChopError ; end
4
+ class ChopInternalError < ChopError ; end
5
+ end
@@ -0,0 +1,245 @@
1
+ require "rubygems"
2
+ require 'rubygems/gem_runner'
3
+ require 'rubygems/exceptions'
4
+ require 'logging'
5
+
6
+ class Chef
7
+ class Knife
8
+ module ChopLogging
9
+ attr :logger
10
+ attr_reader :args
11
+ attr_reader :step
12
+ attr_reader :TODO
13
+
14
+ class ::Logging::ColorScheme
15
+ def scheme
16
+ @scheme
17
+ end
18
+ end
19
+
20
+ class ::Logging::Logger
21
+ class << self
22
+ def define_log_methods( logger )
23
+ ::Logging::LEVELS.each do |name,num|
24
+ code = "undef :#{name} if method_defined? :#{name}\n"
25
+ code << "undef :#{name}? if method_defined? :#{name}?\n"
26
+
27
+ if logger.level > num
28
+ code << <<-CODE
29
+ def #{name}?( ) false end
30
+ def #{name}( data = nil, trace = false ) false end
31
+ CODE
32
+ else
33
+ code << <<-CODE
34
+ def #{name}?( ) true end
35
+ def #{name}( data = nil, trace = nil )
36
+ caller = Kernel.caller[3]
37
+ num = #{num}
38
+ unless caller.match(%r(/knife-chop/))
39
+ num -= 1
40
+ end
41
+ if num >= #{logger.level}
42
+ data = yield if block_given?
43
+ #log_event(::Logging::LogEvent.new(@name, num, caller, true))
44
+ log_event(::Logging::LogEvent.new(@name, num, data, trace.nil? ? @trace : trace))
45
+ end
46
+ true
47
+ end
48
+ CODE
49
+ end
50
+
51
+ logger._meta_eval(code, __FILE__, __LINE__)
52
+ end
53
+ logger
54
+ end
55
+ end
56
+
57
+ def logEvent(evt)
58
+ log_event evt
59
+ end
60
+ end
61
+
62
+ class ::Logging::Layouts::Pattern
63
+ # Arguments to sprintf keyed to directive letters
64
+ verbose, $VERBOSE = $VERBOSE, nil
65
+ DIRECTIVE_TABLE = {
66
+ 'c' => 'event.logger'.freeze,
67
+ 'd' => 'format_date(event.time)'.freeze,
68
+ 'F' => 'event.file'.freeze,
69
+ 'l' => '::Logging::LNAMES[event.level]'.freeze,
70
+ 'L' => 'event.line'.freeze,
71
+ 'm' => 'format_obj(event.data)'.freeze,
72
+ 'M' => 'event.method'.freeze,
73
+ 'p' => 'Process.pid'.freeze,
74
+ 'r' => 'Integer((event.time-@created_at)*1000).to_s'.freeze,
75
+ 't' => 'Thread.current.object_id.to_s'.freeze,
76
+ 'T' => 'Thread.current[:name]'.freeze,
77
+ 'C' => 'event.file != "" ? "(\e[38;5;25m#{event.file}::#{event.line}\e[0m)" : ""',
78
+ '%' => :placeholder
79
+ }.freeze
80
+
81
+ # Human name aliases for directives - used for colorization of tokens
82
+ COLOR_ALIAS_TABLE = {
83
+ 'c' => :logger,
84
+ 'd' => :date,
85
+ 'm' => :message,
86
+ 'p' => :pid,
87
+ 'r' => :time,
88
+ 'T' => :thread,
89
+ 't' => :thread_id,
90
+ 'F' => :file,
91
+ 'L' => :line,
92
+ 'M' => :method,
93
+ 'X' => :mdc,
94
+ 'x' => :ndc,
95
+ 'C' => :file_line,
96
+ }.freeze
97
+
98
+ ensure
99
+ $VERBOSE = verbose
100
+ end
101
+
102
+ # --------------------------------------------------------------------------------
103
+ def logTodo(msg)
104
+
105
+ # Regular expression used to parse out caller information
106
+ #
107
+ # * $1 == filename
108
+ # * $2 == line number
109
+ # * $3 == method name (might be nil)
110
+ caller_rgxp = %r/([-\.\/\(\)\w]+):(\d+)(?::in `(\w+)')?/o
111
+ #CALLER_INDEX = 2
112
+ caller_index = ((defined? JRUBY_VERSION and JRUBY_VERSION[%r/^1.6/]) or (defined? RUBY_ENGINE and RUBY_ENGINE[%r/^rbx/i])) ? 0 : 0
113
+ stack = Kernel.caller
114
+ return if stack.nil?
115
+
116
+ match = caller_rgxp.match(stack[caller_index])
117
+ file = match[1]
118
+ line = Integer(match[2])
119
+ modl = match[3] unless match[3].nil?
120
+
121
+ unless @TODO["#{file}::#{line}"]
122
+ le = ::Logging::LogEvent.new(@logger, ::Logging::LEVELS['todo'], msg, false)
123
+ @logger.logEvent(le)
124
+ @TODO["#{file}::#{line}"] = true
125
+ end
126
+ end
127
+
128
+ # -----------------------------------------------------------------------------
129
+ def logStep(msg)
130
+ if logger = getLogger(@args,'logStep')
131
+ logger.step "Resource #{@step+=1}: #{msg} ..."
132
+ end
133
+ end
134
+
135
+ # -----------------------------------------------------------------------------
136
+ # Set up logger
137
+
138
+ class FakeLogger
139
+ def method_missing(m, *args, &block)
140
+ puts args[0]
141
+ end
142
+ end
143
+
144
+ def setLogger(logger)
145
+ @logger = logger
146
+ end
147
+
148
+ def getLogger(args,from='',alogger=nil)
149
+ logger = alogger || @logger
150
+ unless logger
151
+ unless from==''
152
+ from = "#{from} - "
153
+ end
154
+ @step = 0
155
+ if args
156
+ if args.key?(:log_file) and args[:log_file]
157
+ args[:log_path] = File.dirname(args[:log_file])
158
+ elsif args[:my_name]
159
+ if args[:log_path]
160
+ args[:log_file] = "#{args[:log_path]}/#{args[:my_name]}.log"
161
+ else
162
+ args[:log_file] = "/tmp/#{args[:my_name]}.log"
163
+ end
164
+ end
165
+
166
+ begin
167
+ ::Logging.init :trace, :debug, :info, :step, :warn, :error, :fatal, :todo unless defined? ::Logging::MAX_LEVEL_LENGTH
168
+ if args[:origins] and args[:origins][:log_level]
169
+ if (::Logging::LEVELS[args[:log_level].to_s] and ::Logging::LEVELS[args[:log_level].to_s] < 2)
170
+ #puts "#{args[:log_level].to_s} = #{::Logging::LEVELS[args[:log_level].to_s]}".light_yellow
171
+ puts "#{args[:origins][:log_level]} says #{args[:log_level]}".light_yellow
172
+ else
173
+ from = ''
174
+ end
175
+ end
176
+ l_opts = args[:log_opts].call(::Logging::MAX_LEVEL_LENGTH) || {
177
+ :pattern => "#{from}%d %#{::Logging::MAX_LEVEL_LENGTH}l: %m\n",
178
+ :date_pattern => '%Y-%m-%d %H:%M:%S',
179
+ }
180
+ logger = ::Logging.logger( STDOUT, l_opts)
181
+ l_opts = args[:log_opts].call(::Logging::MAX_LEVEL_LENGTH) || {
182
+ :pattern => "#{from}%d %#{::Logging::MAX_LEVEL_LENGTH}l: %m %C\n",
183
+ :date_pattern => '%Y-%m-%d %H:%M:%S',
184
+ }
185
+ layout = ::Logging::Layouts::Pattern.new(l_opts)
186
+
187
+ if args[:log_file] and args[:log_file].instance_of?(String)
188
+ dev = args[:log_file]
189
+ a_opts = Hash.new
190
+ a_opts[:filename] = dev
191
+ a_opts[:layout] = layout
192
+ a_opts.merge! l_opts
193
+
194
+ name = case dev
195
+ when String; dev
196
+ when File; dev.path
197
+ else dev.object_id.to_s end
198
+
199
+ appender =
200
+ case dev
201
+ when String
202
+ ::Logging::Appenders::RollingFile.new(name, a_opts)
203
+ else
204
+ ::Logging::Appenders::IO.new(name, dev, a_opts)
205
+ end
206
+ logger.add_appenders appender
207
+ end
208
+
209
+ scheme = ::Logging::ColorScheme.new( 'christo', :levels => {
210
+ :trace => [:blue, :on_white],
211
+ :debug => :cyan,
212
+ :info => :green,
213
+ :step => :green,
214
+ :warn => :yellow,
215
+ :error => :red,
216
+ :fatal => [:red, :on_white],
217
+ :todo => :purple,
218
+ }).scheme
219
+ scheme['todo'] = "\e[38;5;55m"
220
+ l_opts[:color_scheme] = 'christo'
221
+ layout = ::Logging::Layouts::Pattern.new(l_opts)
222
+
223
+ appender = logger.appenders[0]
224
+ appender.layout = layout
225
+ logger.remove_appenders appender
226
+ logger.add_appenders appender
227
+
228
+ logger.level = args[:log_level] ? args[:log_level] : :warn
229
+ logger.trace = true if args[:trace]
230
+ @args = args
231
+ rescue Gem::LoadError
232
+ logger = FakeLogger.new
233
+ rescue => e
234
+ # not installed
235
+ logger = FakeLogger.new
236
+ end
237
+ @TODO = {} if @TODO.nil?
238
+ end # if args
239
+ @logger = alogger || logger
240
+ end # unless logger
241
+ logger
242
+ end # getLogger
243
+ end # module Logging
244
+ end # module MixLib
245
+ end # module DLDInternet
@@ -0,0 +1,45 @@
1
+ #
2
+ # Author:: Adam Jacob (<adam@opscode.com>)
3
+ # Copyright:: Copyright (c) 2009 Opscode, Inc.
4
+ # License:: Apache License, Version 2.0
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+ #
18
+
19
+ class ::Chef::Knife::RoleFromFile
20
+ # --------------------------------------------------------------------------------------------------------------------
21
+ # Create a new instance of the current class configured for the given
22
+ # arguments and options
23
+ def initialize(argv=[])
24
+ super(argv)
25
+ @rsrctype = 'role'
26
+ @location = 'roles'
27
+ end
28
+
29
+ def run
30
+ @name_args.each do |arg|
31
+ updated = loader.load_from("roles", arg)
32
+
33
+ updated.save
34
+
35
+ output(format_for_display(updated)) if config[:print_after]
36
+
37
+ ui.step("Updated Role #{updated.name}!")
38
+ end
39
+ end
40
+ end
41
+
42
+
43
+
44
+
45
+