dtask 001 → 002
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.
- data/.gemified +3 -3
- data/lib/dtask.rb +39 -27
- metadata +1 -1
data/.gemified
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
---
|
2
2
|
:summary: DTask provides easy way to deploy web application.
|
3
3
|
:email: keita.yamaguchi@gmail.com
|
4
|
-
:has_rdoc: true
|
5
4
|
:name: dtask
|
5
|
+
:has_rdoc: true
|
6
6
|
:homepage: http://rubyforge.org/projects/dtask/
|
7
|
-
:version: "
|
7
|
+
:version: "002"
|
8
|
+
:rubyforge_project: dtask
|
8
9
|
:dependencies:
|
9
10
|
- net-ssh
|
10
|
-
:rubyforge_project: dtask
|
11
11
|
:author: Keita Yamaguchi
|
data/lib/dtask.rb
CHANGED
@@ -2,58 +2,52 @@ require "net/ssh"
|
|
2
2
|
require "singleton"
|
3
3
|
|
4
4
|
class DTask
|
5
|
-
VERSION = "
|
5
|
+
VERSION = "002"
|
6
6
|
|
7
|
+
# Command error.
|
7
8
|
class Error < StandardError; end
|
8
9
|
|
10
|
+
# DTask configuration.
|
9
11
|
class Config
|
10
12
|
include Singleton
|
11
13
|
|
12
14
|
def initialize; @table = Hash.new; end
|
13
|
-
def o(table); table.each {|key, val| @table[key] = val }; end
|
14
15
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
instance.instance_eval { @table[name] }
|
21
|
-
end
|
16
|
+
def self.method_missing(name, *args)
|
17
|
+
if md = /(.+)=$/.match(name.to_s)
|
18
|
+
instance.instance_eval { @table[name] = args.first }
|
19
|
+
else
|
20
|
+
instance.instance_eval { @table[name] }
|
22
21
|
end
|
23
22
|
end
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
def o(table); table.each {|key, val| @table[key] = val }; end
|
24
27
|
end
|
25
28
|
|
26
|
-
|
27
|
-
|
28
|
-
attr_reader :err
|
29
|
+
# Remote box.
|
30
|
+
class RemoteBox
|
31
|
+
attr_reader :out, :err
|
29
32
|
|
30
33
|
def initialize
|
31
|
-
|
32
|
-
:username => Config.user,
|
33
|
-
:auth_methods => "publickey"
|
34
|
-
}
|
35
|
-
@session = Net::SSH.start(Config.server, options)
|
34
|
+
@session = Net::SSH.start(Config.server, Config.user)
|
36
35
|
@shell = @session.shell.sync
|
37
36
|
@out = []
|
38
37
|
@err = []
|
39
38
|
end
|
40
39
|
|
41
|
-
|
42
|
-
puts "OUT> #{msg}"
|
43
|
-
end
|
44
|
-
|
45
|
-
def perr(msg)
|
46
|
-
puts "ERR> #{msg}"
|
47
|
-
end
|
48
|
-
|
40
|
+
# Run the command or call the task.
|
49
41
|
def l(cmd)
|
50
42
|
cmd.kind_of?(Symbol) ? DTask.run(cmd) : sh(cmd)
|
51
43
|
end
|
52
44
|
|
45
|
+
# Ignore errors.
|
53
46
|
def l!(cmd)
|
54
47
|
begin l(cmd) rescue Error end
|
55
48
|
end
|
56
49
|
|
50
|
+
# Run the command.
|
57
51
|
def sh(cmd)
|
58
52
|
puts "% #{cmd}"
|
59
53
|
res = @shell.send_command(cmd)
|
@@ -61,21 +55,37 @@ class DTask
|
|
61
55
|
perr res.stderr if res.stderr and res.stderr.size > 0
|
62
56
|
@out << res.stdout
|
63
57
|
@err << res.stderr
|
64
|
-
res.status == 0 ? res.stdout : raise Error
|
58
|
+
res.status == 0 ? res.stdout : (raise Error)
|
65
59
|
end
|
66
60
|
|
61
|
+
# Change the current to application directory.
|
67
62
|
def cd_appdir
|
68
63
|
l "cd #{Config.appdir} && pwd"
|
69
64
|
end
|
65
|
+
|
66
|
+
private
|
67
|
+
|
68
|
+
# Print stdout.
|
69
|
+
def pout(msg)
|
70
|
+
puts "OUT> #{msg}"
|
71
|
+
end
|
72
|
+
|
73
|
+
# Print stderr.
|
74
|
+
def perr(msg)
|
75
|
+
puts "ERR> #{msg}"
|
76
|
+
end
|
70
77
|
end
|
71
78
|
|
79
|
+
# task table
|
72
80
|
TASK = Hash.new
|
73
81
|
|
82
|
+
# Load the dtask file.
|
74
83
|
def initialize(name)
|
75
84
|
load File.expand_path("~/.dtask/#{name}.dtask")
|
76
|
-
@remote =
|
85
|
+
@remote = RemoteBox.new
|
77
86
|
end
|
78
87
|
|
88
|
+
# Run the task.
|
79
89
|
def run(task)
|
80
90
|
if TASK.key?(task)
|
81
91
|
puts "#{Config.server} >>> #{task}"
|
@@ -88,10 +98,12 @@ class DTask
|
|
88
98
|
end
|
89
99
|
|
90
100
|
module Kernel
|
101
|
+
# Defines a task.
|
91
102
|
def task(name, &block)
|
92
103
|
DTask::TASK[name] = block
|
93
104
|
end
|
94
105
|
|
106
|
+
# Setup the DTask configuration.
|
95
107
|
def setup(&block)
|
96
108
|
DTask::Config.instance.instance_eval(&block)
|
97
109
|
end
|