reap 4.3.1 → 4.3.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,5 +1,7 @@
1
+ #!/usr/bin/env ruby
1
2
 
2
3
  require 'reap/task'
4
+ require 'reap/setup'
3
5
 
4
6
  #
5
7
  # Install Task
@@ -8,24 +10,39 @@ class Reap::Install < Reap::Task
8
10
 
9
11
  task_desc "Locally install package using setup.rb or install.rb."
10
12
 
11
- attr_accessor :options, :quiet #, :sudo
13
+ attr_accessor :options #, :sudo
12
14
 
13
15
  def init
14
- @quiet ||= !$VERBOSE
15
16
  @options ||= []
16
17
  #@sudo ||= true
17
18
  end
18
19
 
19
20
  def run
20
- exe = %w{ setup.rb install.rb }.find{ |f| File.exists?(f) }
21
- raise "setup.rb or install.rb not found" if exe == nil
21
+ #exe = %w{ setup.rb install.rb }.find{ |f| File.exists?(f) }
22
+ #raise "setup.rb or install.rb not found" if exe == nil
22
23
 
23
- puts "Reap is shelling out work to #{exe}..."
24
+ puts "Reap is shelling out work to setup.rb..."
24
25
 
25
- options << '-q' if @quiet
26
+ # prepare for using internalized setup.rb
26
27
 
27
- c = "sudo ruby #{exe} #{options.join(' ')}"
28
- sh c
28
+ ARGV.delete('install')
29
+ ARGV << '-q' unless $VERBOSE
30
+ ARGV.concat(options)
31
+
32
+ $setup_pwd = $PROJECT_INFO.info_dir #Dir.pwd
33
+
34
+ # invoke setup.rb
35
+
36
+ begin
37
+ ToplevelInstaller.invoke
38
+ rescue SetupError
39
+ raise if $DEBUG
40
+ $stderr.puts $!.message
41
+ $stderr.puts "Try 'reap --help' for detailed usage."
42
+ exit 1
43
+ end
44
+
45
+ puts "Setup complete!"
29
46
  end
30
47
 
31
48
  end
@@ -1,3 +1,4 @@
1
+ #!/usr/bin/env ruby
1
2
 
2
3
  require 'reap/task'
3
4
 
@@ -10,6 +11,8 @@ require 'reap/task'
10
11
  #
11
12
  class Reap::Noop < Reap::Task
12
13
 
14
+ section_required true
15
+
13
16
  task_desc "A no-op task to help debug reap itself."
14
17
 
15
18
  attr_accessor :message
@@ -1,3 +1,4 @@
1
+ #!/usr/bin/env ruby
1
2
 
2
3
  require 'reap/task'
3
4
 
@@ -6,10 +7,10 @@ require 'reap/task'
6
7
  #
7
8
  class Reap::Publish < Reap::Task
8
9
 
9
- task_desc "Publish documents to the web."
10
-
11
10
  section_required true
12
11
 
12
+ task_desc "Publish documents to the web."
13
+
13
14
  attr_accessor :host, :type, :dir, :project, :username
14
15
  attr_accessor :exclude # not using yet
15
16
 
@@ -1,3 +1,4 @@
1
+ #!/usr/bin/env ruby
1
2
 
2
3
  require 'reap/task'
3
4
 
@@ -7,7 +8,7 @@ require 'facet/string/tabto'
7
8
 
8
9
  Test::Unit.run = true # don't run auto tests
9
10
 
10
- #
11
+
11
12
  # Test Task
12
13
  #
13
14
  # The Reap test task runs each test in
@@ -15,23 +16,41 @@ Test::Unit.run = true # don't run auto tests
15
16
  # test facility.
16
17
  #
17
18
  # NOTE: This works well enough but it is a bit of
18
- # hack. It actually marshals test results across
19
- # a stdout->stdin shell pipe. One consequence of
19
+ # a hack. It actually marshals test results across
20
+ # stdout->stdin shell pipe. One consequence of
20
21
  # this is that you can't send debug info to stdout
21
22
  # (including #p and #puts). This, hopefully can be
22
23
  # remedied in the future.
23
- #
24
+
24
25
  class Reap::Test < Reap::Task
25
26
 
26
27
  task_desc "Run unit-tests (each in a separate process)."
27
28
 
28
- attr_accessor :libs, :files, :fixture, :against_installed
29
+ task_help %{
30
+
31
+ Attributes
32
+
33
+ files Test files (eg. test/tc_**/*.rb)
34
+ Defaults to typcial selection.
35
+
36
+ requires List of any files to pre-require.
37
+
38
+ libs List of lookup directories to include in
39
+ load path. './lib' is always included.
40
+
41
+ live Flag to quickly deactive use of local libs.
42
+ Test against installed files instead.
43
+
44
+ }
45
+
46
+ attr_accessor :files, :requires, :live, :libs
29
47
 
30
48
  def init
31
- @libs ||= ['lib']
32
49
  @files ||= [ 'test/*/**/*.rb', 'test/**/tc*.rb', 'test/**/test*.rb', 'test/**/*test.rb' ]
33
- @fixture ||= []
34
- @against_installed ||= false
50
+ @requires ||= []
51
+
52
+ @live ||= false
53
+ @libs ||= [] #['./lib']
35
54
 
36
55
  # interal use
37
56
  @results = TestResults.new
@@ -48,9 +67,9 @@ class Reap::Test < Reap::Task
48
67
  puts "No test files found."
49
68
  return
50
69
  end
51
- print "Reap is shelling out work to Ruby's Test Suite..."
70
+ print "Reap is shelling out work to Ruby's Test Suite...\n"
52
71
 
53
- test_files.each { |f|
72
+ test_files.uniq.each { |f|
54
73
  $stdout << '.'; $stdout.flush
55
74
  dotest( f )
56
75
  #ruby %{-r"test/unit" "#{f}"}
@@ -102,6 +121,8 @@ class Reap::Test < Reap::Task
102
121
  #ruby %{-e0 -r"test/unit" \\\n#{test_reqs}#{test_opts}}
103
122
  end
104
123
 
124
+ # Runs a test.
125
+
105
126
  def dotest( test_file )
106
127
  if ! File.file?( test_file )
107
128
  r = nil
@@ -117,20 +138,31 @@ class Reap::Test < Reap::Task
117
138
 
118
139
  # Currently send program output to null device.
119
140
  # Could send to a logger in future version.
141
+
120
142
  def fork_test( testfile )
121
143
  src = ''
122
- src << %{$:.unshift('lib')} unless against_installed
144
+
145
+ unless live
146
+ l = File.join( Dir.pwd, 'lib' )
147
+ if File.directory?( l )
148
+ src << %{$:.unshift('#{l}')\n}
149
+ end
150
+ libs.each { |r| src << %{$:.unshift('#{r}')\n} }
151
+ end
152
+
123
153
  src << %{
124
154
  #require 'test/unit'
125
155
  require 'test/unit/collector'
126
156
  require 'test/unit/collector/objectspace'
127
157
  require 'test/unit/ui/testrunnermediator'
128
158
  }
129
- fixture.each do |fix|
159
+
160
+ requires.each do |fix|
130
161
  src << %Q{
131
162
  require '#{fix}'
132
163
  }
133
164
  end
165
+
134
166
  src << %{
135
167
  output = STDOUT.dup
136
168
  STDOUT.reopen( PLATFORM =~ /mswin/ ? "NUL" : "/dev/null" )
@@ -146,46 +178,55 @@ class Reap::Test < Reap::Task
146
178
  $stderr << "MARSHAL ERROR\n"
147
179
  $stderr << "TEST: #{testfile}\n"
148
180
  $stderr << "DATA:" << result.inspect
149
- exit 1
181
+ exit -1
150
182
  end
151
183
  output << marshalled
152
-
184
+
153
185
  STDOUT.reopen(output)
154
186
  output.close
155
187
  }
188
+
156
189
  result = IO.popen("ruby","w+") do |ruby|
157
190
  ruby.puts src
158
191
  ruby.close_write
159
192
  ruby.read
160
193
  end
194
+
161
195
  p testfile if $VERBOSE
196
+
162
197
  begin
163
198
  marsh = Marshal.load(result)
164
199
  rescue ArgumentError
165
- $stderr << "\nCannot load marshalled test data."
200
+ $stderr << "\nCannot load marshalled test data.\n"
166
201
  $stderr << result << "\n"
167
- exit 0
202
+ exit -1
168
203
  end
204
+
169
205
  return marsh
170
206
  end
171
207
 
172
208
  #
173
- # Support class for collecting test results
209
+ # Support class for collecting test results.
174
210
  #
211
+
175
212
  class TestResults
213
+
176
214
  attr_reader :assertion_count, :run_count, :failure_count, :error_count
215
+
177
216
  def initialize
178
217
  @assertion_count = 0
179
218
  @run_count = 0
180
219
  @failure_count = 0
181
220
  @error_count = 0
182
221
  end
222
+
183
223
  def <<( result )
184
224
  @assertion_count += result.assertion_count
185
225
  @run_count += result.run_count
186
226
  @failure_count += result.failure_count
187
227
  @error_count += result.error_count
188
228
  end
229
+
189
230
  def to_s
190
231
  s = %{SUMMARY:\n\n}
191
232
  s << %{ tests : #{@run_count}\n}
@@ -194,7 +235,7 @@ class Reap::Test < Reap::Task
194
235
  s << %{ errors : #{@error_count}\n}
195
236
  s
196
237
  end
238
+
197
239
  end
198
240
 
199
241
  end
200
-
@@ -1,3 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
1
3
  require 'reap/task'
2
4
  require 'facet/string/margin'
3
5
 
data/lib/reap/task.rb CHANGED
@@ -7,7 +7,7 @@ require 'facet/string/tabto'
7
7
  require 'facet/module/basename'
8
8
  require 'facet/module/attr_setter'
9
9
 
10
- require 'calibre/filelist'
10
+ require 'facet/filelist'
11
11
 
12
12
 
13
13
  # Base class for reap tasks.
@@ -59,6 +59,7 @@ module Reap
59
59
 
60
60
  def self.register
61
61
  $PROJECT_INFO = ProjectInfo.new( $PROJECT_FILE )
62
+
62
63
  #@registry ||= {}
63
64
  #ObjectSpace.each_object(Class) { |klass|
64
65
  # if klass < ::Reap::Task
@@ -77,7 +78,6 @@ module Reap
77
78
  # end
78
79
 
79
80
 
80
-
81
81
  class Task
82
82
 
83
83
  include ::Config
@@ -97,13 +97,22 @@ module Reap
97
97
  end
98
98
  end
99
99
 
100
+ def task_help( text=nil, &block )
101
+ if text
102
+ @task_help = proc { text }
103
+ elsif block_given?
104
+ @task_help = block
105
+ else
106
+ @task_help.call
107
+ end
108
+ end
109
+
100
110
  #def task_desc ; '(no desciption given)' ; end
101
111
  def task_name ; basename.downcase ; end
102
112
 
103
113
  def section_required( val ) ; @section_required = val ;end
104
114
  def section_required? ; @section_required ; end
105
115
 
106
- #
107
116
  def verify?
108
117
  if section_required?
109
118
  return $PROJECT_INFO.info.key?(task_name)
data/note/Rakefile ADDED
@@ -0,0 +1,60 @@
1
+ # Rakefile for rubypants -*-ruby-*-
2
+ require 'rake/rdoctask'
3
+
4
+
5
+ desc "Run all the tests"
6
+ task :default => [:test]
7
+
8
+ desc "Do predistribution stuff"
9
+ task :predist => [:changelog, :doc]
10
+
11
+
12
+ desc "Run all the tests"
13
+ task :test do
14
+ ruby 'rand.rb'
15
+ end
16
+
17
+ desc "Make an archive as .tar.gz"
18
+ task :dist => :test do
19
+ system "export DARCS_REPO=#{File.expand_path "."}; " +
20
+ "darcs dist -d rand#{get_darcs_tree_version}"
21
+ end
22
+
23
+ desc "Generate a ChangeLog"
24
+ task :changelog do
25
+ system "darcs changes --repo=#{ENV["DARCS_REPO"] || "."} >ChangeLog"
26
+ end
27
+
28
+ desc "Generate RDoc documentation"
29
+ Rake::RDocTask.new(:doc) do |rdoc|
30
+ rdoc.options << '--line-numbers --inline-source --all'
31
+ rdoc.rdoc_files.include 'README'
32
+ rdoc.rdoc_files.include 'rand.rb'
33
+ end
34
+
35
+
36
+ # Helper to retrieve the "revision number" of the darcs tree.
37
+ def get_darcs_tree_version
38
+ return "" unless File.directory? "_darcs"
39
+
40
+ changes = `darcs changes`
41
+ count = 0
42
+ tag = "0.0"
43
+
44
+ changes.each("\n\n") { |change|
45
+ head, title, desc = change.split("\n", 3)
46
+
47
+ if title =~ /^ \*/
48
+ # Normal change.
49
+ count += 1
50
+ elsif title =~ /tagged (.*)/
51
+ # Tag. We look for these.
52
+ tag = $1
53
+ break
54
+ else
55
+ warn "Unparsable change: #{change}"
56
+ end
57
+ }
58
+
59
+ "-" + tag + "." + count.to_s
60
+ end
@@ -0,0 +1,27 @@
1
+
2
+ require 'reap/reap'
3
+ require 'reap/task'
4
+
5
+ class Reap::CompositeTask < Reap::Task
6
+
7
+ register "composite"
8
+
9
+ #def default_name ; "" ; end
10
+ def default_desc
11
+ "run tasks #{subtasks.join(',')} [reap]"
12
+ end
13
+
14
+ #attr_accessor :subtasks
15
+
16
+ def init
17
+ #@subtasks = section['subtasks']
18
+ end
19
+
20
+ private
21
+
22
+ def run
23
+ #@subtasks.each do |st|
24
+ #end
25
+ end
26
+
27
+ end
@@ -0,0 +1,24 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ module Rake
4
+
5
+ # Manage several publishers as a single entity.
6
+ class CompositePublisher
7
+ def initialize
8
+ @publishers = []
9
+ end
10
+
11
+ # Add a publisher to the composite.
12
+ def add(pub)
13
+ @publishers << pub
14
+ end
15
+
16
+ # Upload all the individual publishers.
17
+ def upload
18
+ @publishers.each { |p| p.upload }
19
+ end
20
+ end
21
+
22
+ end
23
+
24
+
data/note/ftptools.rb ADDED
@@ -0,0 +1,139 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # = Tools for FTP uploading.
4
+ #
5
+ # This file is still under development and is not released for general
6
+ # use.
7
+
8
+ require 'date'
9
+ require 'parsedate'
10
+ require 'net/ftp'
11
+
12
+ module Rake # :nodoc:
13
+
14
+ ####################################################################
15
+ # <b>Note:</b> <em> Not released for general use.</em>
16
+ class FtpFile
17
+ attr_reader :name, :size, :owner, :group, :time
18
+
19
+ def self.date
20
+ @date_class ||= Date
21
+ end
22
+
23
+ def initialize(path, entry)
24
+ @path = path
25
+ @mode, line, @owner, @group, size, d1, d2, d3, @name = entry.split(' ')
26
+ @size = size.to_i
27
+ @time = determine_time(d1, d2, d3)
28
+ end
29
+
30
+ def path
31
+ File.join(@path, @name)
32
+ end
33
+
34
+ def directory?
35
+ @mode[0] == ?d
36
+ end
37
+
38
+ def mode
39
+ parse_mode(@mode)
40
+ end
41
+
42
+ def symlink?
43
+ @mode[0] == ?l
44
+ end
45
+
46
+ private # --------------------------------------------------------
47
+
48
+ def parse_mode(m)
49
+ result = 0
50
+ (1..9).each do |i|
51
+ result = 2*result + ((m[i]==?-) ? 0 : 1)
52
+ end
53
+ result
54
+ end
55
+
56
+ def determine_time(d1, d2, d3)
57
+ elements = ParseDate.parsedate("#{d1} #{d2} #{d3}")
58
+ if elements[0].nil?
59
+ today = self.class.date.today
60
+ if elements[1] > today.month
61
+ elements[0] = today.year - 1
62
+ else
63
+ elements[0] = today.year
64
+ end
65
+ end
66
+ elements = elements.collect { |el| el.nil? ? 0 : el }
67
+ Time.mktime(*elements[0,7])
68
+ end
69
+ end
70
+
71
+ ####################################################################
72
+ # Manage the uploading of files to an FTP account.
73
+ class FtpUploader
74
+
75
+ # Log uploads to standard output when true.
76
+ attr_accessor :verbose
77
+
78
+ class << FtpUploader
79
+ # Create an uploader and pass it to the given block as +up+.
80
+ # When the block is complete, close the uploader.
81
+ def connect(path, host, account, password)
82
+ up = self.new(path, host, account, password)
83
+ begin
84
+ yield(up)
85
+ ensure
86
+ up.close
87
+ end
88
+ end
89
+ end
90
+
91
+ # Create an FTP uploader targetting the directory +path+ on +host+
92
+ # using the given account and password. +path+ will be the root
93
+ # path of the uploader.
94
+ def initialize(path, host, account, password)
95
+ @created = Hash.new
96
+ @path = path
97
+ @ftp = Net::FTP.new(host, account, password)
98
+ makedirs(@path)
99
+ @ftp.chdir(@path)
100
+ end
101
+
102
+ # Create the directory +path+ in the uploader root path.
103
+ def makedirs(path)
104
+ route = []
105
+ File.split(path).each do |dir|
106
+ route << dir
107
+ current_dir = File.join(route)
108
+ if @created[current_dir].nil?
109
+ @created[current_dir] = true
110
+ puts "Creating Directory #{current_dir}" if @verbose
111
+ @ftp.mkdir(current_dir) rescue nil
112
+ end
113
+ end
114
+ end
115
+
116
+ # Upload all files matching +wildcard+ to the uploader's root
117
+ # path.
118
+ def upload_files(wildcard)
119
+ Dir[wildcard].each do |fn|
120
+ upload(fn)
121
+ end
122
+ end
123
+
124
+ # Close the uploader.
125
+ def close
126
+ @ftp.close
127
+ end
128
+
129
+ private # --------------------------------------------------------
130
+
131
+ # Upload a single file to the uploader's root path.
132
+ def upload(file)
133
+ puts "Uploading #{file}" if @verbose
134
+ dir = File.dirname(file)
135
+ makedirs(dir)
136
+ @ftp.putbinaryfile(file, file) unless File.directory?(file)
137
+ end
138
+ end
139
+ end
@@ -0,0 +1,85 @@
1
+ # Ruby Treasures 0.4
2
+ # Copyright (C) 2002 Paul Brannan <paul@atdesk.com>
3
+ #
4
+ # You may distribute this software under the same terms as Ruby (see the file
5
+ # COPYING that was distributed with this library).
6
+ #
7
+ # Ruby Treasures 0.2
8
+ # Copyright (C) 2002 Paul Brannan <paul@atdesk.com>
9
+ #
10
+ # You may distribute this software under the same terms as Ruby (see the file
11
+ # COPYING that was distributed with this library).
12
+ #
13
+ # Run this Ruby script to prepare the RubyTreasures distribution for
14
+ # publication.
15
+
16
+ require 'find'
17
+ require 'ftools'
18
+
19
+
20
+ # Add licences to the top of every file and remove unnecessary files
21
+
22
+ license = IO.readlines('LICENSE')
23
+ ruby_license_comment = license.map { |i| i.sub(/^/, '# ') }
24
+ c_license_comment = ["/*\n"] + license.map { |i| i.sub(/^/, ' * ') } + [" */\n"]
25
+
26
+ def rm_rf(dir)
27
+ Dir.foreach(dir) do |f|
28
+ if not f =~ /\.?\.$/ then
29
+ filename = File.join(dir, f)
30
+ if File.directory?(filename) then
31
+ rm_rf(filename)
32
+ else
33
+ puts "Removing file #{filename}"
34
+ File.rm_f(filename)
35
+ end
36
+ end
37
+ end
38
+ puts "Removing directory #{dir}"
39
+ Dir.rmdir(dir)
40
+ end
41
+
42
+ Find.find('.') do |file|
43
+ if File.directory?(file) then
44
+ case file
45
+ when /\/CVS$/
46
+ # Remove CVS directories
47
+ rm_rf(file)
48
+ else
49
+ # Remove empty directories
50
+ entries = Dir.entries(file)
51
+ entries.delete('.')
52
+ entries.delete('..')
53
+ entries.delete('CVS')
54
+ if entries.length == 0 then
55
+ rm_rf(file)
56
+ end
57
+ end
58
+ else
59
+ case file
60
+ when /\.rb$/
61
+ # Add LICENSE to ruby sources
62
+ puts "Adding license to #{file}"
63
+ lines = ruby_license_comment + IO.readlines(file)
64
+ File.open(file, 'w') do |out|
65
+ lines.each do |line|
66
+ out.puts line
67
+ end
68
+ end
69
+ when /\.c$/
70
+ # Add LICENSE to C sources
71
+ puts "Adding license to #{file}"
72
+ lines = c_license_comment + IO.readlines(file)
73
+ File.open(file, 'w') do |out|
74
+ lines.each do |line|
75
+ out.puts line
76
+ end
77
+ end
78
+ when /~$/
79
+ # Remove temporary files
80
+ puts "Removing file #{file}"
81
+ File.rm_f(file)
82
+ end
83
+ end
84
+ end
85
+