ratch 1.1.0 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.ruby +99 -0
- data/COPYING +203 -21
- data/History.rdoc +35 -0
- data/License.txt +204 -0
- data/README.rdoc +113 -0
- data/Version +1 -0
- data/bin/ludo +16 -0
- data/bin/ratch +1 -8
- data/lib/ratch.rb +28 -0
- data/lib/ratch.yml +99 -0
- data/lib/ratch/batch.rb +500 -0
- data/lib/ratch/console.rb +199 -0
- data/lib/ratch/core_ext.rb +1 -4
- data/lib/ratch/core_ext/facets.rb +15 -1
- data/lib/ratch/core_ext/filetest.rb +29 -0
- data/lib/ratch/core_ext/{string.rb → to_actual_filename.rb} +0 -23
- data/lib/ratch/core_ext/to_console.rb +30 -12
- data/lib/ratch/core_ext/{object.rb → to_yamlfrag.rb} +1 -0
- data/lib/ratch/core_ext/unfold_paragraphs.rb +27 -0
- data/lib/ratch/file_list.rb +411 -0
- data/lib/ratch/script.rb +99 -5
- data/lib/ratch/script/help.rb +84 -0
- data/lib/ratch/shell.rb +783 -0
- data/lib/ratch/system.rb +15 -0
- data/lib/ratch/utils/cli.rb +49 -0
- data/lib/ratch/utils/config.rb +52 -0
- data/lib/ratch/{emailer.rb → utils/email.rb} +43 -6
- data/lib/ratch/utils/ftp.rb +134 -0
- data/lib/ratch/utils/pom.rb +22 -0
- data/lib/ratch/utils/rdoc.rb +48 -0
- data/lib/ratch/utils/tar.rb +88 -0
- data/lib/ratch/utils/xdg.rb +39 -0
- data/lib/ratch/utils/zlib.rb +54 -0
- data/spec/01_shell.rdoc +198 -0
- data/spec/02_script.rdoc +34 -0
- data/spec/03_batch.rdoc +71 -0
- data/spec/04_system.rdoc +3 -0
- data/spec/applique/array.rb +8 -0
- data/spec/applique/setup.rb +20 -0
- data/test/case_batch.rb +63 -0
- data/test/case_shell.rb +46 -0
- data/test/core_ext/case_pathname.rb +361 -0
- data/test/helper.rb +4 -0
- data/test/utils/case_cli.rb +6 -0
- data/test/utils/case_config.rb +12 -0
- data/test/utils/case_email.rb +10 -0
- data/test/utils/case_ftp.rb +6 -0
- data/test/utils/case_pom.rb +17 -0
- data/test/utils/case_rdoc.rb +23 -0
- data/test/utils/case_tar.rb +6 -0
- data/test/utils/case_zlib.rb +11 -0
- data/test/utils/fixtures/pom_sample/Profile +4 -0
- data/test/utils/fixtures/rdoc_sample/README.rdoc +4 -0
- data/test/utils/fixtures/rdoc_sample/lib/rdoc_sample/rdoc_sample.rb +9 -0
- metadata +139 -82
- data/HISTORY +0 -6
- data/MANIFEST +0 -53
- data/NEWS +0 -12
- data/README +0 -87
- data/VERSION +0 -1
- data/demo/tryme-task.ratch +0 -12
- data/demo/tryme1.ratch +0 -6
- data/doc/log/basic_stats/index.html +0 -39
- data/doc/log/notes.xml +0 -18
- data/doc/log/stats.log +0 -14
- data/doc/log/syntax.log +0 -0
- data/doc/log/testunit.log +0 -156
- data/lib/ratch/commandline.rb +0 -16
- data/lib/ratch/core_ext/pathname.rb +0 -38
- data/lib/ratch/dsl.rb +0 -420
- data/lib/ratch/index.rb +0 -4
- data/lib/ratch/io.rb +0 -116
- data/lib/ratch/plugin.rb +0 -65
- data/lib/ratch/service.rb +0 -33
- data/lib/ratch/task.rb +0 -249
- data/lib/ratch/task2.rb +0 -298
- data/meta/abstract +0 -4
- data/meta/author +0 -1
- data/meta/contact +0 -1
- data/meta/homepage +0 -1
- data/meta/name +0 -1
- data/meta/requires +0 -4
- data/meta/summary +0 -1
- data/test/README +0 -1
- data/test/test_helper.rb +0 -4
- data/test/test_task.rb +0 -46
data/lib/ratch/task2.rb
DELETED
@@ -1,298 +0,0 @@
|
|
1
|
-
module Taskable
|
2
|
-
|
3
|
-
def self.define_task(base, target_and_requisite, &function)
|
4
|
-
case base
|
5
|
-
when Class, Module
|
6
|
-
|
7
|
-
else #Object
|
8
|
-
|
9
|
-
end
|
10
|
-
end
|
11
|
-
|
12
|
-
|
13
|
-
module ClassDSL
|
14
|
-
# Without an argument, returns list of tasks defined for this class.
|
15
|
-
#
|
16
|
-
# If a task's target name is given, will return the first
|
17
|
-
# task mathing the name found in the class' inheritance chain.
|
18
|
-
# This is important ot ensure task are inherited in the same manner
|
19
|
-
# that methods are.
|
20
|
-
def tasks(target=nil)
|
21
|
-
if target
|
22
|
-
target = target.to_sym
|
23
|
-
anc = ancestors.select{|a| a < DSL}
|
24
|
-
t = nil; anc.find{|a| t = a.tasks[target]}
|
25
|
-
return t
|
26
|
-
else
|
27
|
-
@tasks ||= {}
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
# Set a description to be used by then next defined task in this class.
|
32
|
-
def desc(description)
|
33
|
-
@desc = description
|
34
|
-
end
|
35
|
-
|
36
|
-
# Define a task.
|
37
|
-
def task(target_and_requisite, &function)
|
38
|
-
target, requisite, function = *Task.parse_arguments(target_and_requisite, &function)
|
39
|
-
task = tasks[target.to_sym] ||= (
|
40
|
-
tdesc = @desc
|
41
|
-
@desc = nil
|
42
|
-
Task.new(self, target, tdesc) #, reqs, actions)
|
43
|
-
)
|
44
|
-
task.update(requisite, &function)
|
45
|
-
|
46
|
-
define_method("#{target}Trigger"){ task.run(self) }
|
47
|
-
define_method("#{target}:task", &function)
|
48
|
-
end
|
49
|
-
|
50
|
-
end
|
51
|
-
|
52
|
-
#
|
53
|
-
module ObjectDSL
|
54
|
-
|
55
|
-
# Without an argument, returns list of tasks defined for this class.
|
56
|
-
#
|
57
|
-
# If a task's target name is given, will return the first
|
58
|
-
# task mathing the name found in the class' inheritance chain.
|
59
|
-
# This is important ot ensure task are inherited in the same manner
|
60
|
-
# that methods are.
|
61
|
-
def tasks(target=nil)
|
62
|
-
if target
|
63
|
-
target = target.to_sym
|
64
|
-
anc = ancestors.select{|a| a < DSL}
|
65
|
-
t = nil; anc.find{|a| t = a.tasks[target]}
|
66
|
-
return t
|
67
|
-
else
|
68
|
-
@tasks ||= {}
|
69
|
-
end
|
70
|
-
end
|
71
|
-
|
72
|
-
# Set a description to be used by then next defined task in this class.
|
73
|
-
def desc(description)
|
74
|
-
@desc = description
|
75
|
-
end
|
76
|
-
|
77
|
-
# Define a task.
|
78
|
-
def task(target_and_requisite, &function)
|
79
|
-
target, requisite, function = *Task.parse_arguments(target_and_requisite, &function)
|
80
|
-
task = tasks[target.to_sym] ||= (
|
81
|
-
tdesc = @desc
|
82
|
-
@desc = nil
|
83
|
-
Task.new(self, target, tdesc) #, reqs, actions)
|
84
|
-
)
|
85
|
-
task.update(requisite, &function)
|
86
|
-
|
87
|
-
define_method("#{target}Trigger"){ task.run(self) }
|
88
|
-
define_method("#{target}:task", &function)
|
89
|
-
end
|
90
|
-
|
91
|
-
end
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
# Run a task.
|
96
|
-
#def run(target)
|
97
|
-
# t = self.class.tasks(target)
|
98
|
-
# t.run(self)
|
99
|
-
#end
|
100
|
-
|
101
|
-
# = Task Class
|
102
|
-
#
|
103
|
-
class Task
|
104
|
-
attr :base
|
105
|
-
attr :target
|
106
|
-
attr :requisite
|
107
|
-
attr :function
|
108
|
-
attr :description
|
109
|
-
|
110
|
-
def initialize(base, target, description=nil, requisite=nil, &function)
|
111
|
-
@base = base
|
112
|
-
@target = target.to_sym
|
113
|
-
@description = description
|
114
|
-
@requisite = requisite || []
|
115
|
-
@function = function
|
116
|
-
end
|
117
|
-
|
118
|
-
#
|
119
|
-
def update(requisite, &function)
|
120
|
-
@requisite.concat(requisite).uniq!
|
121
|
-
@function = function if function
|
122
|
-
end
|
123
|
-
|
124
|
-
#
|
125
|
-
def prerequisite
|
126
|
-
base.ancestors.select{ |a| a < DSL }.collect{ |a|
|
127
|
-
a.tasks[target].requisite
|
128
|
-
}.flatten.uniq
|
129
|
-
end
|
130
|
-
|
131
|
-
# invoke target
|
132
|
-
def run(object)
|
133
|
-
rd = rule_dag
|
134
|
-
rd.each do |t|
|
135
|
-
object.send("#{t}:task")
|
136
|
-
end
|
137
|
-
end
|
138
|
-
|
139
|
-
#
|
140
|
-
def call(object)
|
141
|
-
object.instance_eval(&function)
|
142
|
-
end
|
143
|
-
|
144
|
-
# Collect task dependencies for running.
|
145
|
-
def rule_dag(cache=[])
|
146
|
-
prerequisite.each do |r|
|
147
|
-
next if cache.include?(r)
|
148
|
-
t = base.tasks[r]
|
149
|
-
t.rule_dag(cache)
|
150
|
-
#cache << dep
|
151
|
-
end
|
152
|
-
cache << target.to_s
|
153
|
-
cache
|
154
|
-
end
|
155
|
-
|
156
|
-
#
|
157
|
-
def self.parse_arguments(name_and_reqs, &action)
|
158
|
-
if Hash===name_and_reqs
|
159
|
-
target = name_and_reqs.keys.first.to_s
|
160
|
-
reqs = [name_and_reqs.values.first].flatten
|
161
|
-
else
|
162
|
-
target = name_and_reqs.to_s
|
163
|
-
reqs = []
|
164
|
-
end
|
165
|
-
return target, reqs, action
|
166
|
-
end
|
167
|
-
end
|
168
|
-
|
169
|
-
# = File Task Class
|
170
|
-
#
|
171
|
-
class FileTask < Task
|
172
|
-
|
173
|
-
def needed?
|
174
|
-
if prerequisite.empty?
|
175
|
-
dated = true
|
176
|
-
elsif File.exist?(target)
|
177
|
-
mtime = File.mtime(target)
|
178
|
-
dated = prerequisite.find do |file|
|
179
|
-
!File.exist?(file) || File.mtime(file) > mtime
|
180
|
-
end
|
181
|
-
else
|
182
|
-
dated = true
|
183
|
-
end
|
184
|
-
return dated
|
185
|
-
end
|
186
|
-
|
187
|
-
#
|
188
|
-
def call(object)
|
189
|
-
object.instance_eval(&function) if needed?
|
190
|
-
end
|
191
|
-
end
|
192
|
-
|
193
|
-
end
|
194
|
-
|
195
|
-
|
196
|
-
=begin
|
197
|
-
# turn yaml file into tasks
|
198
|
-
def parse(file)
|
199
|
-
script = YAML.load(File.new(file.to_s))
|
200
|
-
|
201
|
-
imports = script.delete('import') || []
|
202
|
-
#plugins = script.delete('plugin') || []
|
203
|
-
srvs = script.delete('services') || {}
|
204
|
-
tgts = script.delete('targets') || {}
|
205
|
-
|
206
|
-
imports.each do |import|
|
207
|
-
path = Reap::Domain::LIB_DIRECTORY + 'systems' + (import + '.reap').to_s
|
208
|
-
parse(path)
|
209
|
-
end
|
210
|
-
|
211
|
-
srvs.each do |label, options|
|
212
|
-
type = options.delete('type')
|
213
|
-
@services[label] = domain.send("#{type}_service") # FIXME
|
214
|
-
end
|
215
|
-
|
216
|
-
tgts.each do |target, options|
|
217
|
-
@targets[target] = Task.new(self, target, options)
|
218
|
-
end
|
219
|
-
end
|
220
|
-
=end
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
=begin
|
228
|
-
# Collect task dependencies for running.
|
229
|
-
def self.rule_dag(target, cache=[])
|
230
|
-
t = tasks[target.to_sym]
|
231
|
-
d = t.prerequisite
|
232
|
-
d.each do |r|
|
233
|
-
next if cache.include?(r)
|
234
|
-
rule_dag(r, cache)
|
235
|
-
#cache << dep
|
236
|
-
end
|
237
|
-
|
238
|
-
# file requirements
|
239
|
-
#q = self.class.ann(name, :reqs) || []
|
240
|
-
#q.each do |req|
|
241
|
-
# path = Pathname.new(req)
|
242
|
-
# next if r.include?(path)
|
243
|
-
# mat = annotations.select{ |n, a| File.fnmatch?(a[:file].first, req) if a[:file] }.compact
|
244
|
-
# mat.each do |n, a|
|
245
|
-
# rule_dag(n, r)
|
246
|
-
# end
|
247
|
-
# r << path
|
248
|
-
#end
|
249
|
-
|
250
|
-
cache << target.to_s
|
251
|
-
return cache
|
252
|
-
end
|
253
|
-
|
254
|
-
# invoke target
|
255
|
-
def run(target)
|
256
|
-
target = target.to_sym
|
257
|
-
rd = self.class.rule_dag(target)
|
258
|
-
rd.each do |t|
|
259
|
-
send("#{t}:task")
|
260
|
-
end
|
261
|
-
end
|
262
|
-
=end
|
263
|
-
|
264
|
-
=begin
|
265
|
-
if target == name.to_s
|
266
|
-
tasks[target].call
|
267
|
-
else
|
268
|
-
case action
|
269
|
-
when Pathname
|
270
|
-
raise unless action.exist?
|
271
|
-
else
|
272
|
-
run_rec(action)
|
273
|
-
end
|
274
|
-
end
|
275
|
-
end
|
276
|
-
end
|
277
|
-
|
278
|
-
def run_rec(action)
|
279
|
-
# creates a file?
|
280
|
-
dated = true
|
281
|
-
if creates = self.class.ann(action, :file)
|
282
|
-
if self.class.ann(name, :reqs).empty?
|
283
|
-
dated = true
|
284
|
-
elsif File.exist?(creates)
|
285
|
-
mtime = File.mtime(creates)
|
286
|
-
dated = self.class.ann(name, :reqs).find do |file|
|
287
|
-
!File.exist?(file) || File.mtime(file) > mtime
|
288
|
-
end
|
289
|
-
else
|
290
|
-
dated = true
|
291
|
-
end
|
292
|
-
end
|
293
|
-
return unless dated
|
294
|
-
send(action)
|
295
|
-
end
|
296
|
-
=end
|
297
|
-
|
298
|
-
|
data/meta/abstract
DELETED
data/meta/author
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
trans <transfire@gmail.com>
|
data/meta/contact
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
trans <transfire@gmail.com>
|
data/meta/homepage
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
http://ratch.rubyforge.org
|
data/meta/name
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
ratch
|
data/meta/requires
DELETED
data/meta/summary
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
Ruby-based Batch Scripting
|
data/test/README
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
Yea. I needs to write test very badly.
|
data/test/test_helper.rb
DELETED
data/test/test_task.rb
DELETED
@@ -1,46 +0,0 @@
|
|
1
|
-
require File.dirname(__FILE__) + '/test_helper'
|
2
|
-
|
3
|
-
require 'ratch/task'
|
4
|
-
|
5
|
-
class TestTaskable < Test::Unit::TestCase
|
6
|
-
|
7
|
-
RESULT_CACHE = []
|
8
|
-
|
9
|
-
class Example #< Ratch::DSL
|
10
|
-
|
11
|
-
include Taskable
|
12
|
-
|
13
|
-
task :task_with_no_requisites do
|
14
|
-
RESULT_CACHE << "task_with_no_requisites"
|
15
|
-
end
|
16
|
-
|
17
|
-
task :task_with_one_requisite => [:task_with_no_requisites] do
|
18
|
-
RESULT_CACHE << "task_with_one_requisite"
|
19
|
-
end
|
20
|
-
|
21
|
-
end
|
22
|
-
|
23
|
-
|
24
|
-
def setup
|
25
|
-
RESULT_CACHE.replace([])
|
26
|
-
@example = Example.new
|
27
|
-
end
|
28
|
-
|
29
|
-
def teardown
|
30
|
-
end
|
31
|
-
|
32
|
-
# Replace this with your real tests.
|
33
|
-
def test_task_with_no_requisite
|
34
|
-
@example.run :task_with_no_requisites
|
35
|
-
#@example.task_with_no_requisites_trigger
|
36
|
-
assert_equal(["task_with_no_requisites"], RESULT_CACHE)
|
37
|
-
end
|
38
|
-
|
39
|
-
def test_task_with_one_requisite
|
40
|
-
@example.run :task_with_one_requisite
|
41
|
-
#@example.task_with_one_requisite_trigger
|
42
|
-
assert_equal(["task_with_no_requisites", "task_with_one_requisite"], RESULT_CACHE)
|
43
|
-
end
|
44
|
-
|
45
|
-
end
|
46
|
-
|