mybot 0.0.4 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (53) hide show
  1. data/Botfile +7 -61
  2. data/CHANGELOG.md +2 -25
  3. data/README.md +72 -189
  4. data/lib/mybot.rb +20 -21
  5. data/lib/mybot/base.rb +6 -2
  6. data/lib/mybot/cli.rb +45 -5
  7. data/lib/mybot/command.rb +37 -28
  8. data/lib/mybot/fmt.rb +143 -52
  9. data/lib/mybot/helpers.rb +24 -0
  10. data/lib/mybot/installer.rb +31 -0
  11. data/lib/mybot/lib.rb +20 -59
  12. data/lib/mybot/libs.rb +31 -28
  13. data/lib/mybot/loader.rb +25 -0
  14. data/lib/mybot/node.rb +100 -47
  15. data/lib/mybot/nodes.rb +16 -0
  16. data/lib/mybot/tasks.rb +47 -11
  17. data/lib/mybot/template.rb +8 -8
  18. data/lib/mybot/templates.rb +15 -0
  19. data/lib/mybot/version.rb +1 -1
  20. data/vendor/lib/{core/.gitkeep → .gitkeep} +0 -0
  21. data/vendor/{recipes → plugins}/.gitkeep +0 -0
  22. data/vendor/{tpl/core → tasks}/.gitkeep +0 -0
  23. data/vendor/tpl/.gitkeep +0 -0
  24. metadata +11 -34
  25. data/lib/mybot/aws.rb +0 -54
  26. data/lib/mybot/commands.rb +0 -108
  27. data/lib/mybot/core-ext/array.rb +0 -9
  28. data/lib/mybot/core-ext/class.rb +0 -53
  29. data/lib/mybot/core-ext/kernel.rb +0 -21
  30. data/lib/mybot/messages.rb +0 -30
  31. data/lib/mybot/recipes.rb +0 -25
  32. data/lib/mybot/result.rb +0 -26
  33. data/lib/mybot/utils.rb +0 -7
  34. data/vendor/lib/core/fs.rb +0 -191
  35. data/vendor/lib/core/osx/git.rb +0 -31
  36. data/vendor/lib/core/osx/rails.rb +0 -31
  37. data/vendor/lib/core/osx/static.rb +0 -31
  38. data/vendor/lib/core/ubuntu/apache.rb +0 -42
  39. data/vendor/lib/core/ubuntu/apt.rb +0 -57
  40. data/vendor/lib/core/ubuntu/git.rb +0 -48
  41. data/vendor/lib/core/ubuntu/mysql.rb +0 -214
  42. data/vendor/lib/core/ubuntu/nginx.rb +0 -43
  43. data/vendor/lib/core/ubuntu/passenger.rb +0 -55
  44. data/vendor/lib/core/ubuntu/php.rb +0 -76
  45. data/vendor/lib/core/ubuntu/rails.rb +0 -105
  46. data/vendor/lib/core/ubuntu/ruby.rb +0 -166
  47. data/vendor/lib/core/ubuntu/service.rb +0 -30
  48. data/vendor/lib/core/ubuntu/static.rb +0 -50
  49. data/vendor/lib/core/ubuntu/users.rb +0 -76
  50. data/vendor/lib/core/ubuntu/vim.rb +0 -31
  51. data/vendor/tpl/core/ubuntu/apache/apache2.conf.erb +0 -80
  52. data/vendor/tpl/core/ubuntu/nginx/nginx.conf.erb +0 -72
  53. data/vendor/tpl/core/ubuntu/php/php.ini.erb +0 -1818
@@ -2,13 +2,13 @@ require "ostruct"
2
2
  require "erb"
3
3
 
4
4
  module Mybot
5
- class Template
6
- def initialize(tpl)
7
- @tpl = tpl
8
- end
5
+ class Template
6
+ def initialize(tpl)
7
+ @tpl = tpl
8
+ end
9
9
 
10
- def render(params = {})
11
- ERB.new(@tpl).result(OpenStruct.new(params).instance_eval { binding })
12
- end
13
- end
10
+ def render(params = {})
11
+ ERB.new(@tpl).result(OpenStruct.new(params).instance_eval { binding })
12
+ end
13
+ end
14
14
  end
@@ -0,0 +1,15 @@
1
+ module Mybot
2
+ module Templates
3
+ def tpl(content)
4
+ case content
5
+ when String
6
+ Template.new(content)
7
+ when Hash
8
+ error "template file is required" unless content[:file]
9
+ tpl = File.join(TPL_PATH, content[:file])
10
+ error "template file '#{tpl}' does not exists" unless File.exists?(tpl)
11
+ Template.new(File.read(tpl))
12
+ end
13
+ end
14
+ end
15
+ end
@@ -1,3 +1,3 @@
1
1
  module Mybot
2
- VERSION = "0.0.4"
2
+ VERSION = "0.1.0"
3
3
  end
File without changes
File without changes
File without changes
File without changes
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mybot
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.1.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-04-21 00:00:00.000000000 Z
12
+ date: 2013-04-25 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: thor
@@ -124,49 +124,26 @@ files:
124
124
  - Rakefile
125
125
  - bin/bot
126
126
  - lib/mybot.rb
127
- - lib/mybot/aws.rb
128
127
  - lib/mybot/base.rb
129
128
  - lib/mybot/cli.rb
130
129
  - lib/mybot/command.rb
131
- - lib/mybot/commands.rb
132
- - lib/mybot/core-ext/array.rb
133
- - lib/mybot/core-ext/class.rb
134
- - lib/mybot/core-ext/kernel.rb
135
130
  - lib/mybot/fmt.rb
131
+ - lib/mybot/helpers.rb
132
+ - lib/mybot/installer.rb
136
133
  - lib/mybot/lib.rb
137
134
  - lib/mybot/libs.rb
138
- - lib/mybot/messages.rb
135
+ - lib/mybot/loader.rb
139
136
  - lib/mybot/node.rb
140
- - lib/mybot/recipes.rb
141
- - lib/mybot/result.rb
137
+ - lib/mybot/nodes.rb
142
138
  - lib/mybot/tasks.rb
143
139
  - lib/mybot/template.rb
144
- - lib/mybot/utils.rb
140
+ - lib/mybot/templates.rb
145
141
  - lib/mybot/version.rb
146
142
  - mybot.gemspec
147
- - vendor/lib/core/.gitkeep
148
- - vendor/lib/core/fs.rb
149
- - vendor/lib/core/osx/git.rb
150
- - vendor/lib/core/osx/rails.rb
151
- - vendor/lib/core/osx/static.rb
152
- - vendor/lib/core/ubuntu/apache.rb
153
- - vendor/lib/core/ubuntu/apt.rb
154
- - vendor/lib/core/ubuntu/git.rb
155
- - vendor/lib/core/ubuntu/mysql.rb
156
- - vendor/lib/core/ubuntu/nginx.rb
157
- - vendor/lib/core/ubuntu/passenger.rb
158
- - vendor/lib/core/ubuntu/php.rb
159
- - vendor/lib/core/ubuntu/rails.rb
160
- - vendor/lib/core/ubuntu/ruby.rb
161
- - vendor/lib/core/ubuntu/service.rb
162
- - vendor/lib/core/ubuntu/static.rb
163
- - vendor/lib/core/ubuntu/users.rb
164
- - vendor/lib/core/ubuntu/vim.rb
165
- - vendor/recipes/.gitkeep
166
- - vendor/tpl/core/.gitkeep
167
- - vendor/tpl/core/ubuntu/apache/apache2.conf.erb
168
- - vendor/tpl/core/ubuntu/nginx/nginx.conf.erb
169
- - vendor/tpl/core/ubuntu/php/php.ini.erb
143
+ - vendor/lib/.gitkeep
144
+ - vendor/plugins/.gitkeep
145
+ - vendor/tasks/.gitkeep
146
+ - vendor/tpl/.gitkeep
170
147
  homepage: https://github.com/sebastiansito/mybot
171
148
  licenses:
172
149
  - MIT
@@ -1,54 +0,0 @@
1
- require "fog"
2
-
3
- module Mybot
4
- class Aws
5
- include Messages
6
-
7
- PROVIDER = "AWS"
8
-
9
- def initialize(options = {})
10
- error "access_key_id is required" unless options[:access_key_id]
11
- error "secret_access_key is required" unless options[:secret_access_key]
12
-
13
- @options = options
14
- end
15
-
16
- def aws
17
- @aws ||= Fog::Compute.new({
18
- :provider => PROVIDER,
19
- :aws_access_key_id => @options[:access_key_id],
20
- :aws_secret_access_key => @options[:secret_access_key]
21
- })
22
- end
23
-
24
- def instances
25
- aws.servers.all
26
- end
27
-
28
- def instance_exists?(name)
29
- instances.each do |i|
30
- return true if i.tags["Name"] == name and i.state == "running"
31
- end
32
-
33
- false
34
- end
35
-
36
- def instance_by_name(name)
37
- instances.each do |i|
38
- return i if i.tags["Name"] == name and i.state != "terminated"
39
- end
40
-
41
- nil
42
- end
43
-
44
- def instance_create(options = {})
45
- instance = @aws.servers.create(options)
46
-
47
- instance.wait_for do
48
- ready?
49
- end
50
-
51
- instance
52
- end
53
- end
54
- end
@@ -1,108 +0,0 @@
1
- require "listen"
2
-
3
- module Mybot
4
- module Commands
5
- include Messages
6
-
7
- def node(host, user, options = {})
8
- Node.new(host, user, options)
9
- end
10
-
11
- def aws(options = {})
12
- Aws.new(options)
13
- end
14
-
15
- def namespace(name)
16
- outer_ns, @namespace = @namespace, name.to_s
17
- if outer_ns && outer_ns != ""
18
- @namespace = "#{outer_ns}:#{@namespace}"
19
- end
20
-
21
- yield
22
- ensure
23
- @namespace = outer_ns
24
- end
25
-
26
- def task(name, &block)
27
- name, deps = *case name
28
- when Hash
29
- name.shift
30
- else
31
- [name, []]
32
- end
33
-
34
- namespaced_deps = Array(deps).map do |d|
35
- case d
36
- when Symbol
37
- "#{@namespace}:#{d}"
38
- when String
39
- if d.include? ":"
40
- d
41
- else
42
- "#{@namespace}:#{d}"
43
- end
44
- end
45
- end.uniq
46
-
47
- task = tasks.find do |t|
48
- t[:name] == name.to_s && t[:namespace] == @namespace
49
- end
50
-
51
- tasks.push({
52
- :name => name.to_s,
53
- :namespace => @namespace,
54
- :deps => namespaced_deps,
55
- :block => block
56
- }) unless task
57
- end
58
-
59
- def tpl(content)
60
- Template.new(content)
61
- end
62
-
63
- def tpl_file(file)
64
- tpl = File.join(TPL_PATH, file)
65
- error "template file '#{tpl}' does not exists" unless File.exists?(tpl)
66
- Template.new(File.read(tpl))
67
- end
68
-
69
- def wait
70
- $stdout.print "Press any key to continue..."
71
- $stdin.gets
72
- end
73
-
74
- def ask(q = "")
75
- $stdout.print "#{q}"
76
- $stdin.gets.chomp
77
- end
78
-
79
- def yes?(q = "")
80
- result = ""
81
- loop do
82
- $stdout.print "#{q}"
83
- result = $stdin.gets.chomp
84
- break if result =~ /y|yes|Y|YES|Yes|n|no|N|NO|No/
85
- end
86
-
87
- result =~ /y|yes|Y|YES|Yes/
88
- end
89
-
90
- def add_listener(*args, &block)
91
- @listeners ||= []
92
-
93
- l = Listen.to *args
94
- l.change do
95
- block.call
96
- end
97
-
98
- @listeners << l
99
- info "added listener for #{args[0]}"
100
- end
101
-
102
- def start_listeners
103
- info "starting listeners"
104
- @listeners[0..-2].each { |l| l.start(false) }
105
- @listeners.last.start(true)
106
- end
107
- end
108
- end
@@ -1,9 +0,0 @@
1
- class Array
2
- def extract_options!
3
- if last.is_a?(Hash)
4
- pop
5
- else
6
- {}
7
- end
8
- end
9
- end
@@ -1,53 +0,0 @@
1
- class Class
2
- def cattr_reader(*syms)
3
- options = syms.extract_options!
4
- syms.each do |sym|
5
- class_eval(<<-EOS, __FILE__, __LINE__ + 1)
6
- unless defined? @@#{sym}
7
- @@#{sym} = nil
8
- end
9
-
10
- def self.#{sym}
11
- @@#{sym}
12
- end
13
- EOS
14
-
15
- unless options[:instance_reader] == false || options[:instance_accessor] == false
16
- class_eval(<<-EOS, __FILE__, __LINE__ + 1)
17
- def #{sym}
18
- @@#{sym}
19
- end
20
- EOS
21
- end
22
- end
23
- end
24
-
25
- def cattr_writer(*syms)
26
- options = syms.extract_options!
27
- syms.each do |sym|
28
- class_eval(<<-EOS, __FILE__, __LINE__ + 1)
29
- unless defined? @@#{sym}
30
- @@#{sym} = nil
31
- end
32
-
33
- def self.#{sym}=(obj)
34
- @@#{sym} = obj
35
- end
36
- EOS
37
-
38
- unless options[:instance_writer] == false || options[:instance_accessor] == false
39
- class_eval(<<-EOS, __FILE__, __LINE__ + 1)
40
- def #{sym}=(obj)
41
- @@#{sym} = obj
42
- end
43
- EOS
44
- end
45
- self.send("#{sym}=", yield) if block_given?
46
- end
47
- end
48
-
49
- def cattr_accessor(*syms, &blk)
50
- cattr_reader(*syms)
51
- cattr_writer(*syms, &blk)
52
- end
53
- end
@@ -1,21 +0,0 @@
1
- module Kernel
2
- def qualified_const_get(str)
3
- path = str.to_s.split('::')
4
- from_root = path[0].empty?
5
- if from_root
6
- from_root = []
7
- path = path[1..-1]
8
- else
9
- start_ns = ((Class === self) || (Module === self)) ? self : self.class
10
- from_root = start_ns.to_s.split('::')
11
- end
12
- until from_root.empty?
13
- begin
14
- return (from_root+path).inject(Object) { |ns,name| ns.const_get(name) }
15
- rescue NameError
16
- from_root.delete_at(-1)
17
- end
18
- end
19
- path.inject(Object) { |ns,name| ns.const_get(name) }
20
- end
21
- end
@@ -1,30 +0,0 @@
1
- require "colored"
2
-
3
- module Mybot
4
- module Messages
5
- def info(msg)
6
- info_format = "INFO"
7
- info_format = info_format.blue.bold if Fmt.use_color
8
- puts "#{info_format} #{msg}"
9
- end
10
-
11
- def warning(msg)
12
- warning_format = "WARNING"
13
- warning_format = warning_format.magenta.bold if Fmt.use_color
14
- puts "#{warning_format} #{msg}"
15
- end
16
-
17
- def error(msg)
18
- error_format = "ERROR"
19
- error_format = error_format.red.bold if Fmt.use_color
20
- puts "#{error_format} #{msg}"
21
- abort
22
- end
23
-
24
- def task_info(name)
25
- task_format = "TASK"
26
- task_format = task_format.green.bold if Fmt.use_color
27
- puts "#{task_format} #{name}"
28
- end
29
- end
30
- end
@@ -1,25 +0,0 @@
1
- module Mybot
2
- module Recipes
3
- include Messages
4
-
5
- def recipes
6
- @recipes ||= (
7
- Dir["Botfile"] +
8
- Dir[File.join(GEM_PATH, "Botfile")] +
9
- Dir[File.join(MYBOT_PATH, "recipes", "**", "*.rb")].flatten +
10
- Dir[File.join(".mybot", "**", "*.rb")].flatten
11
- ).reject { |f| !File.exists?(f) }
12
- end
13
-
14
- def load_recipes
15
- recipes.each { |r| self.load_recipe(r) }
16
- end
17
-
18
- def load_recipe(r)
19
- instance_eval(File.read(r), __FILE__, __LINE__)
20
- rescue Exception => e
21
- warning "cannot load recipe #{r}"
22
- raise(e)
23
- end
24
- end
25
- end
@@ -1,26 +0,0 @@
1
- module Mybot
2
- class Result
3
- attr_accessor :exit_status
4
- attr_writer :stdout, :stderr
5
-
6
- def initialize
7
- @stdout = @stderr = ""
8
- @exit_status = -1
9
- end
10
-
11
- def stdout
12
- filter(@stdout)
13
- end
14
-
15
- def stderr
16
- filter(@stderr)
17
- end
18
-
19
- private
20
-
21
- def filter(data)
22
- data.gsub(/\[sudo\]\ password\ for\ [a-zA-Z0-9_].+\:/, "")
23
- end
24
-
25
- end
26
- end