mybot 0.1.1 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,26 @@
1
+ module Mybot
2
+ module Recipes
3
+ include Fmt
4
+
5
+ def load_recipes
6
+ (
7
+ Dir["Botfile"] +
8
+ Dir[File.join(HOME_PATH, ".mybot", "**", "*.rb")].flatten
9
+ ).reject do |r|
10
+ !File.exists?(r)
11
+ end.each do |r|
12
+ self.load_recipe(r)
13
+ end
14
+ end
15
+
16
+ def load_recipe(r)
17
+ instance_eval(File.read(r), __FILE__, __LINE__)
18
+ rescue Exception => e
19
+ print_cmd! "warning", "cannot load #{r}", :magenta, :bold
20
+ puts e.message
21
+ e.backtrace.each do |line|
22
+ puts line
23
+ end
24
+ end
25
+ end
26
+ end
@@ -1,6 +1,8 @@
1
1
  module Mybot
2
- module Tasks
3
- def tasks
2
+ module Tasks
3
+ include Fmt
4
+
5
+ def tasks
4
6
  @tasks ||= []
5
7
  end
6
8
 
@@ -45,9 +47,9 @@ module Mybot
45
47
  end
46
48
 
47
49
  def find_task(name)
48
- ns = name.split ":"
49
- task = ns.pop
50
- ns = ns.join ":"
50
+ parts = name.split ":"
51
+ task = parts.pop
52
+ ns = parts.join ":"
51
53
 
52
54
  tasks.find do |t|
53
55
  t[:name] == task && (t[:namespace] == ns || t[:namespace].nil?)
@@ -57,10 +59,12 @@ module Mybot
57
59
  def run_task(name, options)
58
60
  task = find_task(name)
59
61
 
60
- error "cannot find task '#{name}' " +
61
- "use 'bot tasks:list' to see available tasks" unless task
62
+ unless task
63
+ print_cmd! "error", "cannot find task '#{name}'", :red, :bold
64
+ abort
65
+ end
62
66
 
63
- task_info name
67
+ print_cmd! "task", name, :cyan, :bold
64
68
 
65
69
  task[:deps].each do |d|
66
70
  run_task(d, options)
@@ -68,5 +72,5 @@ module Mybot
68
72
 
69
73
  task[:block].call(options)
70
74
  end
71
- end
75
+ end
72
76
  end
@@ -5,10 +5,7 @@ module Mybot
5
5
  when String
6
6
  Template.new(content)
7
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))
8
+ Template.new(File.read(content[:file]))
12
9
  end
13
10
  end
14
11
  end
@@ -1,3 +1,3 @@
1
1
  module Mybot
2
- VERSION = "0.1.1"
2
+ VERSION = "0.2.0"
3
3
  end
@@ -1,4 +1,4 @@
1
- # encoding: utf-8
1
+ # coding: utf-8
2
2
  lib = File.expand_path('../lib', __FILE__)
3
3
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
  require 'mybot/version'
@@ -8,8 +8,8 @@ Gem::Specification.new do |spec|
8
8
  spec.version = Mybot::VERSION
9
9
  spec.authors = ["Sebastian Sito"]
10
10
  spec.email = ["sebastian@hypenode.com"]
11
- spec.description = %q{Provision, manage and monitor stuff}
12
- spec.summary = %q{mybot, my personal bot}
11
+ spec.description = %q{Local and remote tasks with ease}
12
+ spec.summary = %q{My personal bot}
13
13
  spec.homepage = "https://github.com/sebastiansito/mybot"
14
14
  spec.license = "MIT"
15
15
 
@@ -18,10 +18,10 @@ Gem::Specification.new do |spec|
18
18
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
19
  spec.require_paths = ["lib"]
20
20
 
21
- spec.add_dependency "thor"
22
- spec.add_dependency "fog"
21
+ spec.add_development_dependency "bundler", "~> 1.3"
22
+ spec.add_development_dependency "rake"
23
+
23
24
  spec.add_dependency "colored"
24
25
  spec.add_dependency "net-ssh"
25
26
  spec.add_dependency "net-sftp"
26
- spec.add_dependency "listen"
27
27
  end
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.1.1
4
+ version: 0.2.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,33 +9,33 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-04-25 00:00:00.000000000 Z
12
+ date: 2013-05-03 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
- name: thor
15
+ name: bundler
16
16
  requirement: !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
- - - ! '>='
19
+ - - ~>
20
20
  - !ruby/object:Gem::Version
21
- version: '0'
22
- type: :runtime
21
+ version: '1.3'
22
+ type: :development
23
23
  prerelease: false
24
24
  version_requirements: !ruby/object:Gem::Requirement
25
25
  none: false
26
26
  requirements:
27
- - - ! '>='
27
+ - - ~>
28
28
  - !ruby/object:Gem::Version
29
- version: '0'
29
+ version: '1.3'
30
30
  - !ruby/object:Gem::Dependency
31
- name: fog
31
+ name: rake
32
32
  requirement: !ruby/object:Gem::Requirement
33
33
  none: false
34
34
  requirements:
35
35
  - - ! '>='
36
36
  - !ruby/object:Gem::Version
37
37
  version: '0'
38
- type: :runtime
38
+ type: :development
39
39
  prerelease: false
40
40
  version_requirements: !ruby/object:Gem::Requirement
41
41
  none: false
@@ -91,23 +91,7 @@ dependencies:
91
91
  - - ! '>='
92
92
  - !ruby/object:Gem::Version
93
93
  version: '0'
94
- - !ruby/object:Gem::Dependency
95
- name: listen
96
- requirement: !ruby/object:Gem::Requirement
97
- none: false
98
- requirements:
99
- - - ! '>='
100
- - !ruby/object:Gem::Version
101
- version: '0'
102
- type: :runtime
103
- prerelease: false
104
- version_requirements: !ruby/object:Gem::Requirement
105
- none: false
106
- requirements:
107
- - - ! '>='
108
- - !ruby/object:Gem::Version
109
- version: '0'
110
- description: Provision, manage and monitor stuff
94
+ description: Local and remote tasks with ease
111
95
  email:
112
96
  - sebastian@hypenode.com
113
97
  executables:
@@ -116,8 +100,6 @@ extensions: []
116
100
  extra_rdoc_files: []
117
101
  files:
118
102
  - .gitignore
119
- - Botfile
120
- - CHANGELOG.md
121
103
  - Gemfile
122
104
  - LICENSE.txt
123
105
  - README.md
@@ -129,21 +111,14 @@ files:
129
111
  - lib/mybot/command.rb
130
112
  - lib/mybot/fmt.rb
131
113
  - lib/mybot/helpers.rb
132
- - lib/mybot/installer.rb
133
- - lib/mybot/lib.rb
134
- - lib/mybot/libs.rb
135
- - lib/mybot/loader.rb
136
114
  - lib/mybot/node.rb
137
115
  - lib/mybot/nodes.rb
116
+ - lib/mybot/recipes.rb
138
117
  - lib/mybot/tasks.rb
139
118
  - lib/mybot/template.rb
140
119
  - lib/mybot/templates.rb
141
120
  - lib/mybot/version.rb
142
121
  - mybot.gemspec
143
- - vendor/lib/.gitkeep
144
- - vendor/plugins/.gitkeep
145
- - vendor/tasks/.gitkeep
146
- - vendor/tpl/.gitkeep
147
122
  homepage: https://github.com/sebastiansito/mybot
148
123
  licenses:
149
124
  - MIT
@@ -168,5 +143,5 @@ rubyforge_project:
168
143
  rubygems_version: 1.8.23
169
144
  signing_key:
170
145
  specification_version: 3
171
- summary: mybot, my personal bot
146
+ summary: My personal bot
172
147
  test_files: []
data/Botfile DELETED
@@ -1,12 +0,0 @@
1
- require "mybot"
2
-
3
- namespace :tasks do
4
- task :list do
5
- puts "available tasks:"
6
- tasks.each do |t|
7
- task = t[:name]
8
- task = "#{t[:namespace]}:#{t[:name]}" if t[:namespace]
9
- puts " #{task}"
10
- end
11
- end
12
- end
@@ -1,2 +0,0 @@
1
- ### 0.1.0
2
- * gem rewritten
@@ -1,31 +0,0 @@
1
- require "fileutils"
2
-
3
- module Mybot
4
- module Installer
5
- def install(options = {})
6
- if File.exists? Mybot::MYBOT_PATH
7
- error "mybot is already installed"
8
- end
9
-
10
- info "installing mybot to #{Mybot::MYBOT_PATH}"
11
- FileUtils.mkdir Mybot::MYBOT_PATH
12
- FileUtils.cp_r Mybot::VENDOR_PATH, Mybot::MYBOT_PATH
13
- ["lib", "plugins", "tasks", "tpl"].each do |dir|
14
- FileUtils.rm File.join(Mybot::MYBOT_PATH, dir, ".gitkeep")
15
- end
16
- end
17
-
18
- def uninstall(options = {})
19
- unless File.exists? Mybot::MYBOT_PATH
20
- error "mybot is not installed"
21
- end
22
-
23
- info "uninstalling mybot"
24
- if yes? "Do you really want to delete ~/.mybot? [y/n]: "
25
- FileUtils.rm_rf Mybot::MYBOT_PATH
26
- else
27
- info "uninstallation aborted"
28
- end
29
- end
30
- end
31
- end
@@ -1,31 +0,0 @@
1
- module Mybot
2
- class Lib
3
- def initialize(lib)
4
- @lib = lib
5
- end
6
-
7
- def method_missing(name, *args, &block)
8
- unless @lib[:funcs][name]
9
- error "func '#{@lib[:name]}'.'#{name}' is not defined"
10
- end
11
-
12
- if args[0].nil? || !args[0].is_a?(Node)
13
- error "1st arg should be node in func '#{@lib[:name]}'.'#{name}'"
14
- end
15
-
16
- if args[1].nil? || !args[1].is_a?(Hash)
17
- error "2nd arg should be options in func '#{@lib[:name]}'.'#{name}'"
18
- end
19
-
20
- node = args[0]
21
- options = args[1]
22
-
23
- options[:sudo] ||= false
24
- options[:cwd] ||= ""
25
- options[:env] ||= {}
26
- options.merge!(@lib[:options])
27
-
28
- return @lib[:funcs][name][:block].call(node, options)
29
- end
30
- end
31
- end
@@ -1,44 +0,0 @@
1
- module Mybot
2
- module Libs
3
- def libs
4
- @libs ||= {}
5
- end
6
-
7
- def library(name, &block)
8
- @library = name
9
- unless libs[name]
10
- libs[name] = {
11
- :name => name,
12
- :options => {},
13
- :funcs => {}
14
- }
15
- end
16
-
17
- yield
18
- ensure
19
- @library = nil
20
- end
21
-
22
- def library_options(options)
23
- unless @library
24
- error "library_options should be used only inside library definition"
25
- end
26
-
27
- libs[@library][:options].merge!(options)
28
- end
29
-
30
- def func(name, &block)
31
- libs[@library][:funcs][name] = {
32
- :block => block
33
- }
34
- end
35
-
36
- def lib(name)
37
- unless libs[name]
38
- error "there is no lib '#{name}'"
39
- end
40
-
41
- Lib.new libs[name]
42
- end
43
- end
44
- end
@@ -1,25 +0,0 @@
1
- module Mybot
2
- module Loader
3
- def load_files
4
- ( Dir[File.join(MYBOT_PATH, "lib", "**", "*.rb")].flatten +
5
- Dir[File.join(MYBOT_PATH, "plugins", "**", "lib", "**", "*.rb")].flatten +
6
- Dir["Botfile"] +
7
- Dir[File.join(".mybot", "**", "*.rb")].flatten +
8
- Dir[File.join(MYBOT_PATH, "tasks", "**", "*.rb")].flatten +
9
- Dir[File.join(MYBOT_PATH, "plugins", "**", "tasks", "**", "*.rb")].flatten +
10
- Dir[File.join(GEM_PATH, "Botfile")]
11
- ).reject do |f|
12
- !File.exists?(f)
13
- end.each do |f|
14
- self.load_file(f)
15
- end
16
- end
17
-
18
- def load_file(f)
19
- instance_eval(File.read(f), __FILE__, __LINE__)
20
- rescue Exception => e
21
- warning "cannot load #{f}"
22
- raise(e)
23
- end
24
- end
25
- end
File without changes
File without changes
File without changes
File without changes