knife-chop 0.2.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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,161 @@
1
+ #
2
+ # Author:: Christo De Lange (<opscode@dldinternet.com>)
3
+ # Copyright:: Copyright (c) 2013 DLDInternet, 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
+ require 'chef/knife/chop_base'
20
+ require 'chef/knife/chop_upload' # Because knife chop translate --action upload ...
21
+
22
+ class Chef
23
+ class Knife
24
+ class ChopTranslate < Knife
25
+
26
+ include ChopBase
27
+
28
+ # --------------------------------------------------------------------------------
29
+ def run
30
+ $stdout.sync = true
31
+ watch_for_break
32
+
33
+ @config[:parts].each{ |p|
34
+ @config[:actions].each{ |a|
35
+ actor = @actors[a]
36
+ raise ChopInternalError.new("Actor for action '#{a.to_s}' cannot be nil!") unless actor
37
+ method = %(#{a.to_s}_#{p.to_s})
38
+ raise ChopInternalError.new "Internal error: Method '#{method}' is not implemented in actor #{actor.class.name}!" unless actor.respond_to?(method,true)
39
+ actor.send(method)
40
+ }
41
+ }
42
+ end
43
+
44
+ # --------------------------------------------------------------------------------
45
+ private
46
+ # --------------------------------------------------------------------------------
47
+
48
+ # --------------------------------------------------------------------------------
49
+ def getNameArgs(xtra,set,key=nil)
50
+ @logger.info "Translating these #{set.map{|name,file| file}.ai} ... "
51
+ name_args = []
52
+ name_args << xtra if xtra != ''
53
+ name_args << key if key
54
+ name_args << set.map{ |name,file|
55
+ file
56
+ }
57
+ name_args.flatten
58
+ end
59
+
60
+ # --------------------------------------------------------------------------------
61
+ def translateSet(set,args={})
62
+ raise ChopInternalError.new "Incorrect use of translateSet method from #{Kernel.caller[0].ai}. Received #{args.class.name}" unless args.is_a?(Hash)
63
+ raise ChopError.new "Must specify the :resource type" unless args[:resource]
64
+ @logger.debug "Translate set: #{set.ai}"
65
+ unless set.size > 0
66
+ @logger.warn("The translate set is empty!")
67
+ return
68
+ end
69
+ rsrc = args[:resource]
70
+ verb = args[:verb] || "from file"
71
+ xtra = args[:extra] || ''
72
+ cmdp = args[:command] || lambda{|rsrc,verb,xtra|
73
+ %(knife #{rsrc} #{verb} #{xtra})
74
+ }
75
+ filp = args[:fileproc] || lambda{|cmd,name,file|
76
+ # name not used/needed
77
+ %(#{cmd} #{file})
78
+ }
79
+ cmd = callCmdProc(cmdp, rsrc,verb,xtra)
80
+
81
+ raise ChopInternalError.new("Translation not possible without using Chef/Knife API") unless @use_knife_api
82
+ argv = "#{rsrc} #{verb}".split(%r(\s+))
83
+ klass= Chef::Knife.subcommand_class_from(argv)
84
+ subc = klass.new()
85
+ subc.config = @config.dup
86
+ subc.config[:logger] =
87
+ subc.logger = @logger
88
+
89
+ scna = []
90
+ if args[:aggregate] and @use_knife_api
91
+ if rsrc == 'data bag'
92
+ set.each{|k,v|
93
+ scna << getNameArgs(xtra,v,k)
94
+ }
95
+ else
96
+ scna << getNameArgs(xtra,set)
97
+ end
98
+ else
99
+ scna << set.map{ |name,file|
100
+ if @use_knife_api
101
+ "#{xtra} #{rsrc == 'cookbook' ? name : file}"
102
+ else
103
+ cmd = callCmdProc(filp, cmd, name, file)
104
+ cmd
105
+ end
106
+ }
107
+ end
108
+ unless @config[:dry_run]
109
+ begin
110
+ scna.each{|batch|
111
+ if args[:aggregate] and @use_knife_api
112
+ subc.name_args = batch
113
+ subc.translate()
114
+ else
115
+ batch.each{|a|
116
+ if @use_knife_api
117
+ subc.name_args = a
118
+ subc.translate()
119
+ else
120
+ a.each{|file,cmd|
121
+ execute cmd,"#{File.basename(file)} ... "
122
+ }
123
+ end
124
+ }
125
+ end
126
+ }
127
+ rescue => e
128
+ @logger.error "#{e.class.name} #{e.message}"
129
+ raise e
130
+ end
131
+ end
132
+ end
133
+
134
+ # --------------------------------------------------------------------------------
135
+ def translate_environments()
136
+ logStep "Translate environments"
137
+ # We are only interested in the ext we are starting with!
138
+ translateSet(environments(@config,[@config[:translate][0]]), :resource => "environment", :aggregate => true)
139
+ end
140
+
141
+ # --------------------------------------------------------------------------------
142
+ def translate_roles()
143
+ logStep "Translate roles"
144
+ translateSet(roles(@config,[@config[:translate][0]]), :resource => "role", :aggregate => true)
145
+ end
146
+
147
+ # --------------------------------------------------------------------------------
148
+ def translate_databags()
149
+ @logger.warn("Data bags cannot be translated to Ruby! (yet?)")
150
+ #logStep "Translate databags"
151
+ #translateSet(databags(@config,[@config[:translate][0]]), :resource => "data bag", :aggregate => true)
152
+ end
153
+
154
+ # --------------------------------------------------------------------------------
155
+ def translate_cookbooks()
156
+ @logger.info("Cookbooks do not need to be translated to Ruby!")
157
+ end
158
+
159
+ end
160
+ end
161
+ end
@@ -0,0 +1,199 @@
1
+ #
2
+ # Author:: Christo De Lange (<opscode@dldinternet.com>)
3
+ # Copyright:: Copyright (c) 2013 DLDInternet, 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
+ require 'chef/exceptions'
19
+ require 'chef/knife/chop_base'
20
+ require 'chef/knife/chop_translate' # Because knife chop upload --action translate ...
21
+
22
+ class Chef
23
+ class Knife
24
+ class ChopUpload < Knife
25
+
26
+ include ChopBase
27
+
28
+ # --------------------------------------------------------------------------------
29
+ def run
30
+ $stdout.sync = true
31
+ watch_for_break
32
+
33
+ @config[:parts].each{ |p|
34
+ @config[:actions].each{ |a|
35
+ actor = @actors[a]
36
+ raise ChopInternalError.new("Actor for action '#{a.to_s}' cannot be nil!") unless actor
37
+ method = %(#{a.to_s}_#{p.to_s})
38
+ raise ChopError.new "Internal error: Method '#{method}' is not implemented in actor #{actor.class.name}!" unless actor.respond_to?(method,true)
39
+ actor.send(method)
40
+ }
41
+ }
42
+ end
43
+
44
+ # --------------------------------------------------------------------------------
45
+ private
46
+ # --------------------------------------------------------------------------------
47
+
48
+ # --------------------------------------------------------------------------------
49
+ def uploadSet(set,args={})
50
+ raise ChopInternalError.new "Incorrect use of uploadSet method from #{Kernel.caller[0].ai}" unless args.is_a?(Hash)
51
+ raise ChopError.new "Must specify the :resource type" unless args[:resource]
52
+ unless set.size > 0
53
+ @logger.warn("The upload set is empty!")
54
+ return
55
+ end
56
+ rsrc = args[:resource]
57
+ verb = args[:verb] || "from file"
58
+ xtra = args[:extra] || ''
59
+ cmdp = args[:command] || lambda{|rsrc,verb,xtra|
60
+ %(knife #{rsrc} #{verb} #{xtra})
61
+ }
62
+ filp = args[:fileproc] || lambda{|cmd,name,file|
63
+ # name not used/needed
64
+ %(#{cmd} #{file})
65
+ }
66
+ cmd = callCmdProc(cmdp, rsrc,verb,xtra)
67
+
68
+ if @use_knife_api
69
+ argv = "#{rsrc} #{verb}".split(%r(\s+))
70
+ klass= Chef::Knife.subcommand_class_from(argv)
71
+ subc = klass.new()
72
+ subc.config = @config.dup
73
+ subc.config[:cookbook_path] = @config[:cookbook_path].map{|p| p.match(%r(^/)) ? p : "#{@config[:repo_path]}/#{p}" } #.join(::File::PATH_SEPARATOR)
74
+ subc.ui = ::Chef::Knife::ChopUI.new(@logger,@config)
75
+ end
76
+
77
+ if args[:aggregate] and @use_knife_api
78
+ subc.name_args << xtra if xtra != ''
79
+ subc.name_args << set.map{ |name,file|
80
+ file
81
+ }
82
+ subc.name_args.flatten!
83
+ #cmd = callCmdProc(filp, cmd, set.map{|name,file| name}.to_s, set.map{|name,file| file}.join(' '))
84
+ @logger.info "#{cmd} #{set.map{|name,file| file}.ai} ... "
85
+ unless @config[:dry_run]
86
+ begin
87
+ subc.run
88
+ rescue => e
89
+ @logger.error "#{e.class.name} #{e.message} #{e.response.body if e.respond_to?('response')}"
90
+ raise e
91
+ end
92
+ end
93
+ else
94
+ set.each{ |name,file|
95
+ cmd = callCmdProc(filp, cmd, name, file)
96
+ fLog = false
97
+ if rsrc == 'cookbook'
98
+ fLog = @logger.info "#{args[:environment]}:#{File.basename(file)} (Dependencies: #{@config[:depends]})"
99
+ else
100
+ fLog = @logger.info File.basename(file)
101
+ end
102
+ @logger.debug "... #{cmd}" if fLog
103
+ if @use_knife_api
104
+ unless @config[:dry_run]
105
+ subc.name_args = rsrc == 'cookbook' ? [ name ] : [ file ]
106
+ subc.run
107
+ end
108
+ else
109
+ unless @config[:dry_run]
110
+ execute cmd,"#{File.basename(file)} ... "
111
+ end
112
+ end
113
+ }
114
+ end
115
+ end
116
+
117
+ # --------------------------------------------------------------------------------
118
+ def upload_environments
119
+ logStep "Upload environments"
120
+ uploadSet(environments, :resource => 'environment', :aggregate => true )
121
+ end
122
+
123
+ # --------------------------------------------------------------------------------
124
+ def upload_roles
125
+ logStep "Upload roles"
126
+ uploadSet(roles, :resource => 'role', :aggregate => true)
127
+ end
128
+
129
+ # --------------------------------------------------------------------------------
130
+ def upload_databags
131
+ logStep "Upload data bags"
132
+ want = Hash.new
133
+ @config[:databags].each{ |b|
134
+ match = b.match(%r/^(.*):(.*)$/)
135
+ if match
136
+ want[match[1]] = parseOptionString(match[2],';')
137
+ end
138
+ }
139
+ @logger.debug want.ai
140
+ databags={}
141
+ Dir.glob(File.expand_path(@config[:repo_path])+'/data_bags/*').each{ |d|
142
+ if File.directory?(d)
143
+ name = File.basename(d)
144
+ regex = "^(#{want.keys.join('|')})"
145
+ match = matches(name,regex)
146
+ if match
147
+ databags[name] = getPathSet(want[name], "data_bags/#{name}")
148
+ @logger.debug "Data bags: (#{name}) #{databags[name].ai}"
149
+ end
150
+ end
151
+ }
152
+ @logger.info "Data bag list: (#{@config[:databags]}) #{databags.ai}"
153
+ databags.each{ |bag,files|
154
+ uploadSet(files, :resource => 'data bag', :extra => bag, :aggregate => true)
155
+ }
156
+ end
157
+
158
+ # --------------------------------------------------------------------------------
159
+ def cookbooks
160
+ unless @cookbooks
161
+ @cookbooks = {}
162
+ @config[:cookbook_path].each{|p| # .split(%r/[,:]/)
163
+ path=File.basename(p)
164
+ @logger.debug "cookbook path: #{p} ==> #{path}"
165
+ @cookbooks.merge! getPathSet(@config[:cookbooks], path, [])
166
+ @logger.debug "Cookbook list: #{@cookbooks.ai} (dependencies: #{@config[:depends].yesno})"
167
+ }
168
+ end
169
+ @cookbooks
170
+ end
171
+
172
+ # --------------------------------------------------------------------------------
173
+ def upload_cookbooks
174
+ logStep "Upload cookbooks"
175
+ @logger.info "Cookbook list: #{cookbooks.ai} (dependencies: #{@config[:depends].yesno})"
176
+ cbpaths = @config[:cookbook_path].dup.map!{|p|
177
+ if p.match(%r(^/))
178
+ p
179
+ else
180
+ File.expand_path("#{@config[:repo_path]}/#{p}")
181
+ end
182
+ }
183
+
184
+ cmdp = lambda{ |resource,verb,xtra|
185
+ "#{resource} #{verb} #{xtra} --cookbook-path #{cbpaths.join(File::PATH_SEPARATOR)}"
186
+ }
187
+ environments.each{ |name,file|
188
+ @logger.info "Environment: #{name}"
189
+ filp = lambda{ |cbcmd,cbname,cbfile|
190
+ s = "#{cbcmd} -E #{name} #{@config[:depends] ? '--include-dependencies' : ''} #{cbname}"
191
+ s
192
+ }
193
+ uploadSet(cookbooks, :resource => 'cookbook', :verb => 'upload', :command => cmdp, :fileproc => filp, :environment => name)
194
+ }
195
+ end
196
+
197
+ end
198
+ end
199
+ end
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in ruby-beautify.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Ernie Brodeur
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,39 @@
1
+ # RBeautify
2
+
3
+ This gem provides a cli binary named 'rbeautify' that will pretty up ruby code.
4
+
5
+ ## Installation
6
+
7
+ $ gem install ruby-beautify
8
+
9
+ ## Usage
10
+
11
+ To Pretty up a file:
12
+
13
+ $ rbeautify filename
14
+
15
+ It can take mulitple filenames:
16
+
17
+ $ rbeautify a b c
18
+
19
+ Without a filename it reads from STDIN, suitable for piping:
20
+
21
+ $ curl 'http://example.org/ugly-file.rb' | rbeautify
22
+
23
+ It has help:
24
+
25
+ $ rbeautify -h
26
+
27
+ ## Contributing
28
+
29
+ 1. Fork it
30
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
31
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
32
+ 4. Push to the branch (`git push origin my-new-feature`)
33
+ 5. Create new Pull Request
34
+
35
+ # History
36
+
37
+ The original analyzer is available at: http://www.arachnoid.com/ruby/rubyBeautifier.html.
38
+
39
+ My work is based off of this sublime-text2 plugin: https://github.com/CraigWilliams/BeautifyRuby but cleaned up and made suitable for use directly in a shell.
@@ -0,0 +1,13 @@
1
+ # Release Notes
2
+
3
+ #### 0.92.0
4
+ * Renamed a require in rspec so they would work again.
5
+ * Dropped filemagic since this already has excellent file parsing and is platform agnostic.
6
+ * Dropped the rest of app.rb, since it wasn't adding anything but line count at this point.
7
+ * Added a RELEASE.md to track changes as I go.
8
+ * Dropped the unneeded yajl and sys-proctree deps since it doesn't use them.
9
+
10
+ #### 0.91.0
11
+ * Stripped out the few bits of my cli stuff that I used and dropped app.rb, cli.rb and filemagic.rb, since all the functionality was present elsewhere.
12
+ * Fixed up the gem related files, generating a proper gemspec, fixed the deps.
13
+ * Fixed up the README.md to give a few usage examples and brief explanation.
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"