reap 4.3.4 → 4.4.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,6 +1,14 @@
1
1
 
2
2
  module Reap
3
3
 
4
+ # = Doap task
5
+ #
6
+ # This task simply generates an XML DOAP project file.
7
+ # This file can be useful for RSS and Atom feeds to
8
+ # project tracking sites. The task utilizes as much
9
+ # information as it can from the ProjectInfo file.
10
+ #
11
+
4
12
  class Doap < Task
5
13
 
6
14
  task_desc %{Generate DOAP project file.}
@@ -16,17 +24,10 @@ module Reap
16
24
 
17
25
  }
18
26
 
19
- task_attr :prj
20
-
21
- # Setup doap data
22
-
23
- def init
24
-
25
- end
26
-
27
- # Generate doap file
27
+ alias_method :prj, :task
28
28
 
29
29
  def run
30
+
30
31
  puts "Generating doap.xml file..."
31
32
 
32
33
  x = ''
@@ -60,8 +61,10 @@ module Reap
60
61
  }.margin
61
62
 
62
63
  File.open( "doap.xml", 'w' ) { |f| f << x }
64
+
63
65
  end
64
66
 
65
67
  end
66
68
 
67
69
  end
70
+
@@ -3,6 +3,8 @@
3
3
  require 'reap/task'
4
4
  require 'facet/string/margin'
5
5
 
6
+ require 'facet/progressbar'
7
+
6
8
  # _____ _ ___ _ _____ _
7
9
  # |_ _|__ __| |_ | __|_ _| |_ |_ _|_ _ __| |__
8
10
  # | |/ -_|_-< _| | _|\ \ / _|_ | |/ _` (_-< / /
@@ -12,65 +14,69 @@ require 'facet/string/margin'
12
14
  # = Test Extraction Task
13
15
  #
14
16
  # The Reap extract test task scans every package script
15
- # looking for =begin testing ... =end sections.
17
+ # looking for =begin test... =end sections.
16
18
  # With appropriat headers, it copies these sections
17
19
  # to files in the test dir, which then can be run
18
- # using the Reap test taks.
20
+ # using the Reap test task.
19
21
  #
20
- class Reap::TestExt < Reap::Task
22
+ class Reap::ExTest < Reap::Task
21
23
 
22
- task_desc "Extract unit-tests from lib scripts."
24
+ task_desc "Extract embedded unit tests from scripts."
23
25
 
24
26
  task_help %{
25
27
 
26
- reap testext
28
+ reap extest
27
29
 
28
30
  Extracts embedded tests from program files and places them
29
31
  in the test directory. The exact layout of files is reflected
30
32
  in the test directory. You can then use Reap's test task to
31
33
  run the tests.
32
34
 
33
- dir Specify the test directory.
34
- Default is 'test'.
35
-
36
- files Specify files to extract.
37
- Default is 'lib/**/*.rb'.
35
+ dir Specify the test directory. Default is 'test'.
36
+ files Specify files to extract. Default is 'lib/**/*.rb'.
38
37
 
39
38
  }
40
39
 
41
- #attr_accessor :dir, :files, :options
40
+ alias_method :tst, :task
41
+
42
+ def run
42
43
 
43
- task_attr :tst
44
+ # setup
44
45
 
45
- def init
46
46
  tst.dir ||= 'test'
47
47
  tst.files ||= [ 'lib/**/*.rb' ]
48
- #tst.options
49
- end
48
+ tst.files = [ tst.files ].flatten
49
+ #tst.options ?
50
+
51
+ # text extract
50
52
 
51
- def run
52
53
  #test_libs = tst.libs.join(':')
53
54
  files = FileList.new
54
55
  files.include(*tst.files)
55
56
  if files.empty?
56
- puts "No script files found."
57
+ tell "No script files found."
57
58
  return
58
59
  end
59
- print "Reap is scanning and copying embedded tests..."
60
+
61
+ tell "Reap is scanning and copying embedded tests..."
60
62
 
61
63
  if tst.dir.strip.empty?
62
- puts "Test directory must be specified."
64
+ tell "Test directory must be specified."
63
65
  return
64
66
  end
65
67
 
66
68
  unless File.directory?(tst.dir)
67
- puts "Test directory doesn't exist: #{File.expand_path( tst.dir )}"
69
+ tell "Test directory doesn't exist: #{File.expand_path( tst.dir )}"
68
70
  return
69
71
  end
70
72
 
73
+ pbar = Console::ProgressBar.new( 'Extracting', files.size )
74
+
71
75
  files.each { |file|
72
- $stdout << '.'; $stdout.flush
76
+ pbar.inc
77
+
73
78
  testing = extract( file )
79
+
74
80
  unless testing.strip.empty?
75
81
  complete_test = create( testing, file )
76
82
  libpath = File.dirname( file )
@@ -82,7 +88,9 @@ class Reap::TestExt < Reap::Task
82
88
  File.open( fp, "w" ) { |fw| fw << complete_test }
83
89
  end
84
90
  }
85
- puts "done."
91
+
92
+ pbar.finish
93
+
86
94
  end
87
95
 
88
96
  private
@@ -1,4 +1,9 @@
1
1
 
2
+ # NOTE This task needs work!
3
+ # It needs to generalize more to give greater control
4
+ # over which files get what permissions.
5
+ # It also might be extended to do copyright tagging.
6
+
2
7
  require 'reap/task'
3
8
 
4
9
  # ___ _ _ _____ _
@@ -13,7 +18,7 @@ class Reap::Perm < Reap::Task
13
18
 
14
19
  section_required true
15
20
 
16
- task_desc "Normalize ownership and permissions of package files."
21
+ task_desc "Normalize ownership and permissions of files."
17
22
 
18
23
  task_help %{
19
24
 
@@ -26,17 +31,14 @@ class Reap::Perm < Reap::Task
26
31
 
27
32
  }
28
33
 
29
- #attr_accessor :user, :group, :filemod, :dirmod
34
+ alias_method :perm, :task
30
35
 
31
- task_attr :perm
36
+ def run
32
37
 
33
- def init
34
38
  perm.group ||= perm.user
35
39
  perm.filemod ||= 644
36
40
  perm.dirmod ||= 755
37
- end
38
41
 
39
- def run
40
42
  puts "Reap is shelling out work to chmod..."
41
43
 
42
44
  # misc
@@ -23,10 +23,6 @@ class Reap::Info < Reap::Task
23
23
 
24
24
  }
25
25
 
26
- def init
27
- # no initialization
28
- end
29
-
30
26
  def run
31
27
  puts $PROJECT_INFO.info_stream
32
28
  end
@@ -14,12 +14,19 @@ class Reap::Install < Reap::Task
14
14
 
15
15
  task_desc "Locally install package using built-in setup.rb."
16
16
 
17
- def init
18
- task.options ||= []
19
- #@sudo ||= true
20
- end
17
+ task_help %{
18
+
19
+ reap install
20
+
21
+ This task manually installs a project using setup.rb.
22
+ If setup.rb doesn't exist it will be created.
23
+
24
+ }
21
25
 
22
26
  def run
27
+
28
+ task.options ||= []
29
+
23
30
  #exe = %w{ setup.rb install.rb }.find{ |f| File.exists?(f) }
24
31
  #raise "setup.rb or install.rb not found" if exe == nil
25
32
 
@@ -0,0 +1,59 @@
1
+
2
+ require 'reap/task'
3
+ require 'digest/md5'
4
+
5
+ # __ __ _ __ _ _____ _
6
+ # | \/ |__ _ _ _ (_)/ _|___ __| |_ |_ _|_ _ __| |__
7
+ # | |\/| / _` | ' \| | _/ -_|_-< _| | |/ _` (_-< / /
8
+ # |_| |_\__,_|_||_|_|_| \___/__/\__| |_|\__,_/__/_\_\
9
+ #
10
+
11
+ # = Manifest Task
12
+
13
+ class Reap::Manifest < Reap::Task
14
+
15
+ MUST_EXCLUDE = [ 'InstalledFiles', '**/CVS/**/*', '**/*~', 'dist', 'pkg' ]
16
+
17
+ #section_required true
18
+
19
+ task_desc "Create a MANIFEST file for this package."
20
+
21
+ task_help %{
22
+
23
+ reap manifest
24
+
25
+ Creates a manifest file for the package.
26
+
27
+ include user name to use
28
+ exclude group name to use
29
+
30
+ }
31
+
32
+ alias_method :man, :task
33
+
34
+ def run
35
+
36
+ man.include ||= ['**/*']
37
+
38
+ man.exclude ||= []
39
+ man.exclude |= MUST_EXCLUDE
40
+
41
+ package_files = FileList.new
42
+ package_files.include(*man.include)
43
+ package_files.exclude(*man.exclude) if man.exclude and not man.exclude.empty?
44
+
45
+ File.open('MANIFEST', 'w+') do |f|
46
+ package_files.each do |pf|
47
+ f << "#{salt(pf)} #{pf}\n" if File.file?(pf)
48
+ end
49
+ end
50
+
51
+ end
52
+
53
+ # support functions
54
+ def salt( file )
55
+ Digest::MD5.new( File.read( file ) ).hexdigest
56
+ end
57
+
58
+ end
59
+
@@ -15,10 +15,9 @@ class Reap::Noop < Reap::Task
15
15
 
16
16
  task_desc "A no-op task to help debug reap itself."
17
17
 
18
- def init( msg )
19
- end
18
+ alias_method :msg, :task
20
19
 
21
- def run( msg )
20
+ def run
22
21
  puts ( msg.message || 'No message field in noop section.' )
23
22
  end
24
23
 
@@ -22,18 +22,18 @@ end
22
22
  class Reap::Package < Reap::Task
23
23
 
24
24
  MUST_EXCLUDE = [ 'InstalledFiles', '**/CVS/**/*', '**/*~', 'dist', 'pkg' ]
25
- LOCATIONS = [ '../leaf', '../dist', '../pkg', 'dist', 'pkg' ]
25
+ LOCATIONS = [ 'dist', 'pkg', '../packages', '../dist', '../pkg' ]
26
26
 
27
27
  # Task line description
28
28
 
29
- task_desc do
30
- if master.package
31
- disttypes = master.package.distribute || master.distribute || [ 'gem', 'tar.bz2', 'zip' ]
32
- else
33
- disttypes = master.distribute || [ 'gem', 'tar.bz2', 'zip' ]
34
- end
35
- "Build distribution packages (#{disttypes.join(', ')})."
36
- end
29
+ task_desc "Create distribution packages."
30
+ # if master.package
31
+ # disttypes = master.package.distribute || master.distribute || [ 'gem', 'tar.bz2', 'zip' ]
32
+ # else
33
+ # disttypes = master.distribute || [ 'gem', 'tar.bz2', 'zip' ]
34
+ # end
35
+ # "Build distribution packages (#{disttypes.join(', ')})."
36
+ # end
37
37
 
38
38
  # Help information
39
39
 
@@ -78,18 +78,15 @@ class Reap::Package < Reap::Task
78
78
 
79
79
  # Alternate for task properties accessor.
80
80
 
81
- task_attr :pkg
81
+ alias_method :pkg, :task
82
82
 
83
- # Setup package task.
83
+ def run
84
84
 
85
- def init
85
+ # setup package defaults
86
86
 
87
87
  # Do not look in master information for this
88
-
89
88
  pkg.dir = section.dir || LOCATIONS.find { |f| File.directory?(f) } || 'dist'
90
89
 
91
- # Set defaults
92
-
93
90
  pkg.status ||= 'beta/stable'
94
91
  pkg.date ||= Time.now.strftime("%Y-%m-%d")
95
92
  pkg.series ||= '1'
@@ -145,11 +142,7 @@ class Reap::Package < Reap::Task
145
142
  #@autorequire
146
143
  end
147
144
 
148
- end
149
-
150
- # Run package task.
151
-
152
- def run
145
+ # package it up
153
146
 
154
147
  group_dir_path = File.join( pkg.dir, pkg.package_name )
155
148
  package_dir_path = File.join( pkg.dir, pkg.package_name, pkg.package_name )
@@ -217,7 +210,7 @@ class Reap::Package < Reap::Task
217
210
  if defined?(::Gem)
218
211
  run_gem
219
212
  else
220
- puts "Package .gem requested, but rubygems not found (skipped)."
213
+ tell "Package .gem requested, but rubygems not found (skipped)."
221
214
  end
222
215
  end
223
216
 
@@ -227,7 +220,7 @@ class Reap::Package < Reap::Task
227
220
  if true # TODO ensure required debian tools here
228
221
  run_deb
229
222
  else
230
- puts "Package .deb requested, but debian tools not found (skipped)."
223
+ tell "Package .deb requested, but debian tools not found (skipped)."
231
224
  end
232
225
  end
233
226
 
@@ -237,7 +230,7 @@ class Reap::Package < Reap::Task
237
230
  if true # TODO ensure required tools here
238
231
  run_pacman
239
232
  else
240
- puts "Pacman package requested, but required tools not found (skipped)."
233
+ tell "Pacman package requested, but required tools not found (skipped)."
241
234
  end
242
235
  end
243
236
 
@@ -291,14 +284,14 @@ private
291
284
  s.has_rdoc = true
292
285
  }
293
286
 
294
- puts "Reap is shelling out work to the Gem Package Manager..."
287
+ tell "Reap is shelling out work to the Gem Package Manager..."
295
288
  Gem.manage_gems
296
289
  Gem::Builder.new(spec).build
297
290
  gems = Dir.glob( './*.gem' )
298
291
  gems.each{ |f|
299
292
  FileUtils.mv( f, File.join( pkg.dir, pkg.package_name ) )
300
293
  }
301
- #sh %{mv ./*.gem #{@dir}/}
294
+ puts
302
295
  end
303
296
 
304
297
 
@@ -372,6 +365,7 @@ private
372
365
  File.open( File.join(debdir, 'DEBIAN', 'control'), 'w') { |f| f << ctrl }
373
366
 
374
367
  sh %{dpkg-deb -b #{debdir} #{debfile}}
368
+ puts
375
369
  end
376
370
 
377
371
  # This builds a pacman (archlinux) PKGBUILD script.
@@ -381,7 +375,7 @@ private
381
375
  use_subsection :pacman
382
376
 
383
377
  unless @source
384
- puts "URL 'source' is require for proto package."
378
+ tell "URL 'source' is require for proto package."
385
379
  return nil
386
380
  end
387
381
 
@@ -430,13 +424,10 @@ private
430
424
  pacpacdir = File.join( pacdir, 'PACMAN' )
431
425
  pacfile = File.join( pacdir, 'PKGBUILD' )
432
426
 
433
- puts "Reap is shelling out work to the pacman..."
427
+ tell "Reap is shelling out work to the pacman..."
434
428
  FileUtils.mkdir_p(pacdir)
435
- #sh %{ruby setup.rb all --prefix=#{debdir}}
436
- #FileUtils.mkdir_p(pacpacdir)
437
429
  File.open( pacfile, 'w') { |f| f << proto }
438
- #sh %{}
439
-
430
+ puts
440
431
  end
441
432
 
442
433
  end
@@ -1,6 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  require 'reap/task'
4
+ require 'shellwords'
4
5
 
5
6
  # ___ _ _ _ _ _____ _
6
7
  # | _ \_ _| |__| (_)__| |_ |_ _|_ _ __| |__
@@ -14,60 +15,144 @@ class Reap::Publish < Reap::Task
14
15
 
15
16
  section_required true
16
17
 
17
- task_desc "Publish documents to the web."
18
+ task_desc "Publish documents to the web or host."
18
19
 
19
20
  task_help %{
20
21
 
21
22
  reap publish
22
23
 
23
- Publish documents to hosting service.
24
- Currently only supports web publishing to Rubyforge.
25
- Working on generalizing this more in future.
24
+ Publish documents to hosting service. Three means of
25
+ publishing are current supported, ftp uploading, scp,
26
+ and web convenience option that recognizes particular
27
+ hosts (only RubyForge is currently supported).
26
28
 
27
- dir Directory of files to publish.
28
- exclude Files not to include from directory.
29
- project Project name.
29
+ type Type of publishing, 'web', 'scp' or 'ftp'.
30
+ host Host server, default is 'rubyforge.org'
30
31
  username Username for host.
32
+ dir Directory of files to publish. Or,
33
+ copy Files to publish using from and to.
34
+ project Project name (used for Rubyforge)
35
+
36
+ If the type is 'scp' or 'ftp' you will also need to provide
37
+ the root directory parameter.
38
+
39
+ root Document root directory at host.
40
+
41
+ The dir parameter allows you to simply specify a local
42
+ directory, the contents of which will be published to
43
+ host's document root location (directory tree intact).
44
+
45
+ If you need more control over which files to publish
46
+ where, you can use the copy parameter instead. Provide
47
+ an array of pattern strings in the form of "{from} {to}".
48
+ If the desitination is the host's document root you do
49
+ not need to specify the {to} part. For example:
50
+
51
+ copy: [ 'web/*', 'doc/api/* doc/api' ]
52
+
53
+ The first copies the files under your project's web directory
54
+ to the host's document root. The second copies your projects
55
+ doc/api files to the doc/api location on the host.
56
+
57
+ When using the 'scp' type the internal template used for
58
+ the outbound destination is 'username@host:root/'.
31
59
 
32
60
  }
33
61
 
34
62
  #attr_accessor :host, :type, :dir, :project, :username
35
63
  #attr_accessor :exclude # not using yet
36
64
 
37
- task_attr :pub
65
+ alias_method :pub, :task
38
66
 
39
- # Setup the publishing task.
67
+ # Run the publishing task.
40
68
 
41
- def init
42
- pub.type ||= 'www'
69
+ def run( target=nil, copy_from=nil, copy_to=nil )
70
+
71
+ return nil if target and target != pub.target
72
+
73
+ # setup
74
+
75
+ pub.type ||= 'web'
43
76
  pub.host ||= 'rubyforge.org'
77
+ pub.root ||= 'var/www/gforge-projects/'
44
78
  pub.project ||= master.rubyforge.project || master.name
45
79
  pub.username ||= master.rubyforge.username
46
- pub.exclude ||= []
47
- end
80
+ pub.copy ||= [ "#{pub.dir}/*" ]
48
81
 
49
- # Run the publishing task.
82
+ if copy_from
83
+ pub.copy = [ "#{copy_from} #{copy_to}".strip ]
84
+ end
50
85
 
51
- def run
52
- cmd = ''; skip = false
86
+ # validate
53
87
 
54
- case pub.host
55
- when 'rubyforge', 'rubyforge.org'
56
- case pub.type
57
- when 'www', 'web'
58
- cmd = %{scp -r #{pub.dir}/* #{pub.username}@rubyforge.org:/var/www/gforge-projects/#{pub.project}/}
88
+ unless pub.project
89
+ puts "Project not specified." ; return nil
90
+ end
91
+
92
+ unless pub.username
93
+ puts "Username not specified." ; return nil
94
+ end
95
+
96
+ # publish
97
+
98
+ puts "Reap is shelling out publishing work..."
99
+
100
+ case pub.type
101
+
102
+ when 'web', 'www'
103
+ case pub.host
104
+ when 'rubyforge', 'rubyforge.org'
105
+ pub.host = "rubyforge.org"
106
+ pub.root = "/var/www/gforge-projects/#{pub.project}"
107
+ run_scp
59
108
  else
60
- puts %{Unrecognized publishing kind '#{pub.type}' for host '#{pub.host}'. Skipped.}
61
- skip = true
109
+ puts %{Unrecognized publishing host '#{pub.host}'. Skipped.}
110
+ return nil
62
111
  end
112
+
113
+ when 'scp'
114
+ run_scp
115
+
116
+ when 'ftp'
117
+ run_ftp
118
+
63
119
  else
64
- puts %{Unrecognized publishing host '#{pub.host}'. Skipped.}
65
- skip = true
120
+ puts %{Unrecognized publishing type '#{pub.type}'. Skipped.}
121
+ return nil
66
122
  end
67
123
 
68
- unless skip
69
- puts "Reap is shelling out publishing work..."
70
- sh(cmd) unless $PRETEND
124
+ end
125
+
126
+ private
127
+
128
+ def run_scp
129
+ pub.copy.each { |c|
130
+ from, to = *Shellwords.shellwords(c)
131
+ to = '' if to.nil?
132
+ to = to[1..-1] if to[0,1] == '/'
133
+ cmd = "scp -r #{from} #{pub.username}@#{pub.host}:#{pub.root}/#{to}"
134
+ sh( cmd )
135
+ }
136
+ end
137
+
138
+ def run_ftp
139
+ require 'net/ftp'
140
+ return if $PRETEND
141
+ Net::FTP.open( pub.host ) do |ftp|
142
+ ftp.login( pub.username )
143
+ ftp.chdir( pub.root )
144
+
145
+ pub.copy.each { |c|
146
+ from, to = *Shellwords.shellwords(c)
147
+ to = '' if to.nil?
148
+ to = to[1..-1] if to[0,1] == '/'
149
+ from.sub('*', '**/*') unless from =~ /\*\*/
150
+ files = FileList.new( from )
151
+ files.each { |f|
152
+ t = File.join( to, f.basename )
153
+ ftp.putbinaryfile( f, t, 1024 )
154
+ }
155
+ }
71
156
  end
72
157
  end
73
158