linecook 0.6.2 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (72) hide show
  1. data/History +139 -0
  2. data/HowTo/Control Virtual Machines +106 -0
  3. data/HowTo/Generate Scripts +263 -0
  4. data/HowTo/Run Scripts +87 -0
  5. data/HowTo/Setup Virtual Machines +76 -0
  6. data/License.txt +1 -1
  7. data/README +78 -59
  8. data/bin/linecook +12 -5
  9. data/bin/linecook_run +45 -0
  10. data/bin/linecook_scp +50 -0
  11. data/lib/linecook.rb +1 -3
  12. data/lib/linecook/attributes.rb +49 -12
  13. data/lib/linecook/commands.rb +9 -4
  14. data/lib/linecook/commands/build.rb +69 -0
  15. data/lib/linecook/commands/command.rb +13 -3
  16. data/lib/linecook/commands/command_error.rb +6 -0
  17. data/lib/linecook/commands/env.rb +74 -8
  18. data/lib/linecook/commands/helper.rb +271 -24
  19. data/lib/linecook/commands/init.rb +10 -6
  20. data/lib/linecook/commands/package.rb +36 -18
  21. data/lib/linecook/commands/run.rb +66 -0
  22. data/lib/linecook/commands/snapshot.rb +114 -0
  23. data/lib/linecook/commands/ssh.rb +39 -0
  24. data/lib/linecook/commands/start.rb +34 -0
  25. data/lib/linecook/commands/state.rb +32 -0
  26. data/lib/linecook/commands/stop.rb +22 -0
  27. data/lib/linecook/commands/vbox_command.rb +130 -0
  28. data/lib/linecook/cookbook.rb +112 -55
  29. data/lib/linecook/package.rb +293 -109
  30. data/lib/linecook/proxy.rb +19 -0
  31. data/lib/linecook/recipe.rb +321 -62
  32. data/lib/linecook/template.rb +7 -101
  33. data/lib/linecook/test.rb +196 -141
  34. data/lib/linecook/test/command_parser.rb +75 -0
  35. data/lib/linecook/test/file_test.rb +153 -35
  36. data/lib/linecook/test/shell_test.rb +176 -0
  37. data/lib/linecook/utils.rb +25 -7
  38. data/lib/linecook/version.rb +4 -4
  39. data/templates/Rakefile +44 -47
  40. data/templates/_gitignore +1 -1
  41. data/templates/attributes/project_name.rb +4 -4
  42. data/templates/config/ssh +15 -0
  43. data/templates/files/help.txt +1 -0
  44. data/templates/helpers/project_name/assert_content_equal.erb +15 -0
  45. data/templates/helpers/project_name/create_dir.erb +9 -0
  46. data/templates/helpers/project_name/create_file.erb +8 -0
  47. data/templates/helpers/project_name/install_file.erb +8 -0
  48. data/templates/packages/abox.yml +4 -0
  49. data/templates/recipes/abox.rb +22 -0
  50. data/templates/recipes/abox_test.rb +14 -0
  51. data/templates/templates/todo.txt.erb +3 -0
  52. data/templates/test/project_name_test.rb +19 -0
  53. data/templates/test/test_helper.rb +14 -0
  54. metadata +43 -41
  55. data/cookbook +0 -0
  56. data/lib/linecook/commands/helpers.rb +0 -28
  57. data/lib/linecook/commands/vbox.rb +0 -85
  58. data/lib/linecook/helper.rb +0 -117
  59. data/lib/linecook/shell.rb +0 -11
  60. data/lib/linecook/shell/posix.rb +0 -145
  61. data/lib/linecook/shell/test.rb +0 -254
  62. data/lib/linecook/shell/unix.rb +0 -117
  63. data/lib/linecook/shell/utils.rb +0 -138
  64. data/templates/README +0 -90
  65. data/templates/files/file.txt +0 -1
  66. data/templates/helpers/project_name/echo.erb +0 -5
  67. data/templates/recipes/project_name.rb +0 -20
  68. data/templates/scripts/project_name.yml +0 -7
  69. data/templates/templates/template.txt.erb +0 -3
  70. data/templates/vbox/setup/virtual_box +0 -86
  71. data/templates/vbox/ssh/id_rsa +0 -27
  72. data/templates/vbox/ssh/id_rsa.pub +0 -1
@@ -0,0 +1,4 @@
1
+ # Attributes set here override those in the attributes directory.
2
+ <%= project_name %>:
3
+ resolutions:
4
+ - I will automate configuration of my servers.
@@ -0,0 +1,22 @@
1
+ #############################################################################
2
+ helpers '<%= project_name %>'
3
+ attributes '<%= project_name %>'
4
+ #############################################################################
5
+
6
+ # Write to the script using write/writeln
7
+ writeln '# An example script.'
8
+
9
+ # Attributes are available, as are helpers.
10
+ file = "~/#{attrs['<%= project_name %>']['year']}/resolutions.txt"
11
+ content = attrs['<%= project_name %>']['resolutions'].join("\n")
12
+ create_file file, content
13
+
14
+ # Use file_path to add a file to the package and return a path to it.
15
+ source = file_path('help.txt')
16
+ target = "~/#{attrs['<%= project_name %>']['year']}/help.txt"
17
+ install_file source, target
18
+
19
+ # Same for templates. Attributes are available in the template.
20
+ source = template_path('todo.txt')
21
+ target = "~/#{attrs['<%= project_name %>']['year']}/todo.txt"
22
+ install_file source, target
@@ -0,0 +1,14 @@
1
+ #############################################################################
2
+ helpers '<%= project_name %>'
3
+ attributes '<%= project_name %>'
4
+ #############################################################################
5
+
6
+ # Validations can be using the same techniques as in run.
7
+ assert_content_equal %{
8
+ I will automate configuration of my servers.
9
+ }.lstrip, '~/2011/resolutions.txt'
10
+
11
+ assert_content_equal %{
12
+ # TODO
13
+ * automate configuration of my servers
14
+ }.lstrip, '~/2011/todo.txt'
@@ -0,0 +1,3 @@
1
+ # TODO<%= '<' %>% attrs['<%= project_name %>']['resolutions'].each do |resolution| %<%= '>' %>
2
+ * <%= '<' %>%= resolution.gsub('I will', '').chomp('.').strip %<%= '>' %>
3
+ <%= '<' %>% end %<%= '>' %>
@@ -0,0 +1,19 @@
1
+ require File.expand_path('../test_helper', __FILE__)
2
+
3
+ class <%= const_name %>Test < Test::Unit::TestCase
4
+ include Linecook::Test
5
+
6
+ #
7
+ # package test
8
+ #
9
+
10
+ no_cleanup
11
+
12
+ def test_<%= project_name %>
13
+ result, cmd = build_project
14
+ assert_equal 0, $?.exitstatus, cmd
15
+
16
+ result, cmd = run_project
17
+ assert_equal 0, $?.exitstatus, cmd
18
+ end
19
+ end
@@ -0,0 +1,14 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+ Bundler.setup
4
+
5
+ require 'test/unit'
6
+ require 'linecook/test'
7
+
8
+ if testcase = ENV['TESTCASE']
9
+ ARGV << "--testcase=#{testcase}"
10
+ end
11
+
12
+ if name = ENV['NAME']
13
+ ARGV << "--name=#{name}"
14
+ end
metadata CHANGED
@@ -1,13 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: linecook
3
3
  version: !ruby/object:Gem::Version
4
- hash: 3
5
4
  prerelease: false
6
5
  segments:
6
+ - 1
7
7
  - 0
8
- - 6
9
- - 2
10
- version: 0.6.2
8
+ - 0
9
+ version: 1.0.0
11
10
  platform: ruby
12
11
  authors:
13
12
  - Simon Chiang
@@ -15,18 +14,16 @@ autorequire:
15
14
  bindir: bin
16
15
  cert_chain: []
17
16
 
18
- date: 2011-01-07 00:00:00 -07:00
17
+ date: 2011-04-26 00:00:00 -06:00
19
18
  default_executable:
20
19
  dependencies:
21
20
  - !ruby/object:Gem::Dependency
22
21
  name: rake
23
22
  prerelease: false
24
23
  requirement: &id001 !ruby/object:Gem::Requirement
25
- none: false
26
24
  requirements:
27
25
  - - ~>
28
26
  - !ruby/object:Gem::Version
29
- hash: 49
30
27
  segments:
31
28
  - 0
32
29
  - 8
@@ -38,11 +35,9 @@ dependencies:
38
35
  name: configurable
39
36
  prerelease: false
40
37
  requirement: &id002 !ruby/object:Gem::Requirement
41
- none: false
42
38
  requirements:
43
39
  - - ~>
44
40
  - !ruby/object:Gem::Version
45
- hash: 3
46
41
  segments:
47
42
  - 0
48
43
  - 7
@@ -54,20 +49,17 @@ dependencies:
54
49
  name: bundler
55
50
  prerelease: false
56
51
  requirement: &id003 !ruby/object:Gem::Requirement
57
- none: false
58
52
  requirements:
59
53
  - - ~>
60
54
  - !ruby/object:Gem::Version
61
- hash: 25
62
55
  segments:
63
56
  - 1
64
57
  - 0
65
- - 7
66
- version: 1.0.7
67
- type: :development
58
+ version: "1.0"
59
+ type: :runtime
68
60
  version_requirements: *id003
69
- description:
70
- email: simon.chiang@pinnacol.com
61
+ description: Linecook generates shell scripts using an extensible set of ERB helpers. The shell scripts and associated resources (files, subscripts, etc) make up packages that can be used, for example, to provision servers.
62
+ email: simon.a.chiang@gmail.com
71
63
  executables:
72
64
  - linecook
73
65
  extensions: []
@@ -76,53 +68,67 @@ extra_rdoc_files:
76
68
  - History
77
69
  - README
78
70
  - License.txt
71
+ - HowTo/Control Virtual Machines
72
+ - HowTo/Generate Scripts
73
+ - HowTo/Run Scripts
74
+ - HowTo/Setup Virtual Machines
79
75
  files:
80
- - cookbook
76
+ - bin/linecook_run
77
+ - bin/linecook_scp
81
78
  - lib/linecook.rb
82
79
  - lib/linecook/attributes.rb
83
80
  - lib/linecook/commands.rb
81
+ - lib/linecook/commands/build.rb
84
82
  - lib/linecook/commands/command.rb
85
83
  - lib/linecook/commands/command_error.rb
86
84
  - lib/linecook/commands/env.rb
87
85
  - lib/linecook/commands/helper.rb
88
- - lib/linecook/commands/helpers.rb
89
86
  - lib/linecook/commands/init.rb
90
87
  - lib/linecook/commands/package.rb
91
- - lib/linecook/commands/vbox.rb
88
+ - lib/linecook/commands/run.rb
89
+ - lib/linecook/commands/snapshot.rb
90
+ - lib/linecook/commands/ssh.rb
91
+ - lib/linecook/commands/start.rb
92
+ - lib/linecook/commands/state.rb
93
+ - lib/linecook/commands/stop.rb
94
+ - lib/linecook/commands/vbox_command.rb
92
95
  - lib/linecook/cookbook.rb
93
- - lib/linecook/helper.rb
94
96
  - lib/linecook/package.rb
97
+ - lib/linecook/proxy.rb
95
98
  - lib/linecook/recipe.rb
96
- - lib/linecook/shell.rb
97
- - lib/linecook/shell/posix.rb
98
- - lib/linecook/shell/test.rb
99
- - lib/linecook/shell/unix.rb
100
- - lib/linecook/shell/utils.rb
101
99
  - lib/linecook/template.rb
102
100
  - lib/linecook/test.rb
101
+ - lib/linecook/test/command_parser.rb
103
102
  - lib/linecook/test/file_test.rb
104
103
  - lib/linecook/test/regexp_escape.rb
104
+ - lib/linecook/test/shell_test.rb
105
105
  - lib/linecook/utils.rb
106
106
  - lib/linecook/version.rb
107
107
  - templates/Gemfile
108
- - templates/README
109
108
  - templates/Rakefile
110
109
  - templates/_gitignore
111
110
  - templates/attributes/project_name.rb
111
+ - templates/config/ssh
112
112
  - templates/cookbook
113
- - templates/files/file.txt
114
- - templates/helpers/project_name/echo.erb
113
+ - templates/files/help.txt
114
+ - templates/helpers/project_name/assert_content_equal.erb
115
+ - templates/helpers/project_name/create_dir.erb
116
+ - templates/helpers/project_name/create_file.erb
117
+ - templates/helpers/project_name/install_file.erb
118
+ - templates/packages/abox.yml
115
119
  - templates/project_name.gemspec
116
- - templates/recipes/project_name.rb
117
- - templates/scripts/project_name.yml
118
- - templates/templates/template.txt.erb
119
- - templates/vbox/setup/virtual_box
120
- - templates/vbox/ssh/id_rsa
121
- - templates/vbox/ssh/id_rsa.pub
122
- - bin/linecook
120
+ - templates/recipes/abox.rb
121
+ - templates/recipes/abox_test.rb
122
+ - templates/templates/todo.txt.erb
123
+ - templates/test/project_name_test.rb
124
+ - templates/test/test_helper.rb
123
125
  - History
124
126
  - README
125
127
  - License.txt
128
+ - HowTo/Control Virtual Machines
129
+ - HowTo/Generate Scripts
130
+ - HowTo/Run Scripts
131
+ - HowTo/Setup Virtual Machines
126
132
  has_rdoc: true
127
133
  homepage: http://github.com/pinnacol/linecook
128
134
  licenses: []
@@ -138,27 +144,23 @@ rdoc_options:
138
144
  require_paths:
139
145
  - lib
140
146
  required_ruby_version: !ruby/object:Gem::Requirement
141
- none: false
142
147
  requirements:
143
148
  - - ">="
144
149
  - !ruby/object:Gem::Version
145
- hash: 3
146
150
  segments:
147
151
  - 0
148
152
  version: "0"
149
153
  required_rubygems_version: !ruby/object:Gem::Requirement
150
- none: false
151
154
  requirements:
152
155
  - - ">="
153
156
  - !ruby/object:Gem::Version
154
- hash: 3
155
157
  segments:
156
158
  - 0
157
159
  version: "0"
158
160
  requirements: []
159
161
 
160
- rubyforge_project: ""
161
- rubygems_version: 1.3.7
162
+ rubyforge_project:
163
+ rubygems_version: 1.3.6
162
164
  signing_key:
163
165
  specification_version: 3
164
166
  summary: A shell script generator.
data/cookbook DELETED
File without changes
@@ -1,28 +0,0 @@
1
- require 'linecook/commands/helper'
2
-
3
- module Linecook
4
- module Commands
5
-
6
- # ::desc generates all helpers
7
- #
8
- # Generates helpers that match the input patterns (by default all,
9
- # helpers).
10
- #
11
- class Helpers < Helper
12
- def process
13
- helpers_dir = File.expand_path('helpers', cookbook_dir)
14
-
15
- sources = {}
16
- Dir.glob("#{helpers_dir}/**/*").each do |source|
17
- next if File.directory?(source)
18
- (sources[File.dirname(source)] ||= []) << source
19
- end
20
-
21
- sources.each_pair do |dir, sources|
22
- name = dir[(helpers_dir.length+1)..-1]
23
- super(name, *sources)
24
- end
25
- end
26
- end
27
- end
28
- end
@@ -1,85 +0,0 @@
1
- module Linecook
2
- module Commands
3
-
4
- # Linecook::Commands::Start::desc start the vm
5
- class Start < Command
6
- config :type, 'headless'
7
-
8
- def process(vmname='vbox')
9
- unless `VBoxManage -q list runningvms`.include?(VMNAME)
10
- sh "VBoxManage -q startvm #{vmname} --type #{type}"
11
- end
12
- end
13
- end
14
-
15
- # Linecook::Commands::Stop::desc stop the vm
16
- class Stop < Command
17
- def process(vmname='vbox')
18
- if `VBoxManage -q list runningvms`.include?(vmname)
19
- sh "VBoxManage -q controlvm #{vmname} poweroff"
20
- end
21
- end
22
- end
23
-
24
- # Linecook::Commands::Reset::desc reset vm to a snapshot
25
- class Reset < Command
26
-
27
- config :type, 'headless'
28
- config :snapshot, 'BASE'
29
-
30
- def process(vmname='vbox')
31
- if `VBoxManage -q list runningvms`.include?(vmname)
32
- sh "VBoxManage -q controlvm #{vmname} poweroff"
33
- end
34
-
35
- sh "VBoxManage -q snapshot #{vmname} restore #{snapshot.upcase}"
36
- sh "VBoxManage -q startvm #{vmname} --type #{type}"
37
- end
38
- end
39
-
40
- # Linecook::Commands::Snapshot::desc take a snapshop
41
- class Snapshot < Command
42
- def process(snapshot, vmname='vbox')
43
- `VBoxManage -q snapshot #{vmname} delete #{snapshot.upcase} > /dev/null`
44
- sh "VBoxManage -q snapshot #{vmname} take #{snapshot.upcase}"
45
- end
46
- end
47
-
48
- # Linecook::Commands::State::desc print the vm state
49
- class State < Command
50
- def process(vmname='vbox')
51
- if `VBoxManage -q list runningvms`.include?(vmname)
52
- puts "running"
53
- else
54
- puts "stopped"
55
- end
56
- end
57
- end
58
-
59
- # Linecook::Commands::Ssh::desc ssh to vm
60
- class Ssh < Command
61
-
62
- config :port, 2222, &c.integer
63
- config :user, 'vbox'
64
- config :keypath, File.expand_path('../../../../vbox/ssh/id_rsa', __FILE__)
65
-
66
- def process(cmd=nil)
67
- # To prevent ssh errors, protect the private key
68
- FileUtils.chmod(0600, keypath)
69
-
70
- # Patterned after vagrant/ssh.rb (circa 0.6.6)
71
- platform = RUBY_PLATFORM.to_s.downcase
72
- ssh = "ssh -p #{port} -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -o IdentitiesOnly=yes -i #{keypath} #{user}@localhost #{cmd}"
73
-
74
- # Some hackery going on here. On Mac OS X Leopard (10.5), exec fails
75
- # (GH-51). As a workaround, we fork and wait. On all other platforms, we
76
- # simply exec.
77
-
78
- pid = nil
79
- pid = fork if platform.include?("darwin9") || platform.include?("darwin8")
80
- Kernel.exec(ssh) if pid.nil?
81
- Process.wait(pid) if pid
82
- end
83
- end
84
- end
85
- end
@@ -1,117 +0,0 @@
1
- require 'linecook/template'
2
-
3
- module Linecook
4
- class Helper < Template
5
- attr_reader :const_name
6
- attr_reader :sources
7
-
8
- def initialize(const_name, sources)
9
- @const_name = const_name
10
- @sources = sources.select {|source| File.file?(source) }
11
- @section_paths, @definition_paths = @sources.partition {|path| File.basename(path)[0] == ?_ }
12
- super()
13
- end
14
-
15
- def build
16
- eval MODULE_TEMPLATE, binding, __FILE__, MODULE_TEMPLATE_LINE
17
- result
18
- end
19
-
20
- def sections
21
- @sections ||= begin
22
- sections = {}
23
-
24
- @section_paths.each do |path|
25
- key = File.basename(path)[1..-1]
26
- key.chomp! File.extname(path)
27
- sections[key.to_sym] = File.read(path)
28
- end
29
-
30
- sections
31
- end
32
- end
33
-
34
- def definitions
35
- @definitions ||= @definition_paths.collect do |path|
36
- name = File.basename(path).chomp File.extname(path)
37
- desc, signature, body = parse File.read(path)
38
-
39
- eval ERB_TEMPLATE, binding, __FILE__, ERB_TEMPLATE_LINE
40
- end
41
- end
42
-
43
- private
44
-
45
- def parse(str)
46
- head, body = str.split(/^--.*\n/, 2)
47
- head, body = '', head if body.nil?
48
- signature, desc = parse_head(head)
49
-
50
- [desc.join("\n"), signature.join("\n"), body]
51
- end
52
-
53
- def parse_head(head)
54
- found_signature = false
55
- head.split("\n").partition do |line|
56
- found_signature = true if line =~ /^\s*\(.*?\)/
57
- found_signature
58
- end
59
- end
60
-
61
- def method_name(name)
62
- case name
63
- when /_check$/ then name.sub(/_check$/, '?')
64
- when /_bang$/ then name.sub(/_bang$/, '!')
65
- else name
66
- end
67
- end
68
-
69
- def module_nest(const_name, indent=" ", line_sep="\n")
70
- nestings = const_name.split(/::/).collect {|name| ["module #{name}", "end"]}
71
- nestings << {:indent => indent, :line_sep => line_sep}
72
-
73
- nest(*nestings) { yield }
74
- end
75
-
76
- MODULE_TEMPLATE_LINE = __LINE__ + 2
77
- MODULE_TEMPLATE = "self." + ERB.new(<<-DOC, nil, '<>').src
78
- require 'erb'
79
- <%= sections[:header] %>
80
-
81
- # Generated by Linecook, do not edit.
82
- <% module_nest(const_name, '') do %>
83
- <%= sections[:head] %>
84
- <% definitions.each do |definition| %>
85
-
86
- <%= definition %>
87
- <% end %>
88
- <%= sections[:tail] %>
89
- <% end %>
90
-
91
- <%= sections[:footer] %>
92
- DOC
93
-
94
- ERB_TEMPLATE_LINE = __LINE__ + 2
95
- ERB_TEMPLATE = ERB.new(<<-DOC, nil, '<>').src
96
- # :stopdoc:
97
- <%= name.upcase %>_LINE = __LINE__ + 2
98
- <%= name.upcase %> = "self." + ERB.new(<<'END_OF_TEMPLATE', nil, '<>').src
99
- <%= body %>
100
-
101
- END_OF_TEMPLATE
102
- # :startdoc:
103
-
104
- <% desc.each do |line| %>
105
- # <%= line %>
106
- <% end %>
107
- def <%= method_name(name) %><%= signature %>
108
- eval(<%= name.upcase %>, binding, __FILE__, <%= name.upcase %>_LINE)
109
- nil
110
- end
111
-
112
- def _<%= method_name(name) %>(*args, &block) # :nodoc:
113
- capture { <%= method_name(name) %>(*args, &block) }
114
- end
115
- DOC
116
- end
117
- end