spawner 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +4 -0
- data/Manifest.txt +17 -0
- data/README.rdoc +62 -0
- data/Rakefile +29 -0
- data/bin/spawner +8 -0
- data/lib/spawner.rb +344 -0
- data/lib/spawner/main.rb +89 -0
- data/tasks/ann.rake +81 -0
- data/tasks/bones.rake +21 -0
- data/tasks/gem.rake +126 -0
- data/tasks/git.rake +41 -0
- data/tasks/manifest.rake +49 -0
- data/tasks/notes.rake +28 -0
- data/tasks/post_load.rake +39 -0
- data/tasks/rdoc.rake +51 -0
- data/tasks/rubyforge.rake +57 -0
- data/tasks/setup.rb +268 -0
- metadata +72 -0
data/lib/spawner/main.rb
ADDED
@@ -0,0 +1,89 @@
|
|
1
|
+
|
2
|
+
require 'optparse'
|
3
|
+
require File.expand_path(
|
4
|
+
File.join(File.dirname(__FILE__), %w[.. spawner]))
|
5
|
+
|
6
|
+
# The main application for the "spawner" command line tool.
|
7
|
+
#
|
8
|
+
class Spawner::Main
|
9
|
+
|
10
|
+
# Convenience method for creating and running.
|
11
|
+
#
|
12
|
+
def self.run( args )
|
13
|
+
new.run( args )
|
14
|
+
end
|
15
|
+
|
16
|
+
# The configuration options parsed from the command line arguments
|
17
|
+
attr_reader :config
|
18
|
+
|
19
|
+
# Initializes a new main object.
|
20
|
+
#
|
21
|
+
def initialize
|
22
|
+
@config = {}
|
23
|
+
end
|
24
|
+
|
25
|
+
# Parse the given command line _args_ and run the command according to
|
26
|
+
# the arguments passed in.
|
27
|
+
#
|
28
|
+
def run( args )
|
29
|
+
parse(args)
|
30
|
+
args << config
|
31
|
+
|
32
|
+
spawner = ::Spawner.new(*args)
|
33
|
+
Signal.trap('INT') { spawner.stop }
|
34
|
+
|
35
|
+
count = config[:spawn] || 1
|
36
|
+
puts "starting #{count} child processes (Ctrl-C to quit)"
|
37
|
+
|
38
|
+
spawner.start
|
39
|
+
spawner.join
|
40
|
+
|
41
|
+
puts 'sleeping for 7 seconds'
|
42
|
+
sleep 7
|
43
|
+
|
44
|
+
puts 'finished'
|
45
|
+
end
|
46
|
+
|
47
|
+
# Parse the given array of command line _args_ and return the command to
|
48
|
+
# run.
|
49
|
+
#
|
50
|
+
def parse( args )
|
51
|
+
opts = OptionParser.new
|
52
|
+
opts.banner = 'Usage: spawner [options] command'
|
53
|
+
|
54
|
+
opts.separator ''
|
55
|
+
opts.on('-s', '--spawn NUMBER', Integer,
|
56
|
+
'number of child processes to spawn') {|s| config[:spawn] = s}
|
57
|
+
opts.on('-p', '--pause SECONDS', Float,
|
58
|
+
'time to wait before re-spawning') {|p| config[:pause] = p}
|
59
|
+
|
60
|
+
opts.separator ''
|
61
|
+
opts.on('--stdin FILENAME', String,
|
62
|
+
'child process reads input from here') {|fn| config[:stdin] = fn}
|
63
|
+
opts.on('--stdout FILENAME', String,
|
64
|
+
'child process writes output to here') {|fn| config[:stdout] = fn}
|
65
|
+
opts.on('--stderr FILENAME', String,
|
66
|
+
'child process writes errors to here') {|fn| config[:stderr] = fn}
|
67
|
+
|
68
|
+
opts.separator ''
|
69
|
+
opts.separator 'common options:'
|
70
|
+
|
71
|
+
opts.on_tail( '-h', '--help', 'show this message' ) do
|
72
|
+
puts opts
|
73
|
+
exit
|
74
|
+
end
|
75
|
+
opts.on_tail( '--version', 'show version' ) do
|
76
|
+
puts "spawner #{::Spawner::VERSION}"
|
77
|
+
exit
|
78
|
+
end
|
79
|
+
|
80
|
+
opts.parse! args
|
81
|
+
if args.empty?
|
82
|
+
puts opts
|
83
|
+
abort "missing command"
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
end # class Spawner::Main
|
88
|
+
|
89
|
+
# EOF
|
data/tasks/ann.rake
ADDED
@@ -0,0 +1,81 @@
|
|
1
|
+
# $Id$
|
2
|
+
|
3
|
+
begin
|
4
|
+
require 'bones/smtp_tls'
|
5
|
+
rescue LoadError
|
6
|
+
require 'net/smtp'
|
7
|
+
end
|
8
|
+
require 'time'
|
9
|
+
|
10
|
+
namespace :ann do
|
11
|
+
|
12
|
+
# A prerequisites task that all other tasks depend upon
|
13
|
+
task :prereqs
|
14
|
+
|
15
|
+
file PROJ.ann.file do
|
16
|
+
ann = PROJ.ann
|
17
|
+
puts "Generating #{ann.file}"
|
18
|
+
File.open(ann.file,'w') do |fd|
|
19
|
+
fd.puts("#{PROJ.name} version #{PROJ.version}")
|
20
|
+
fd.puts(" by #{Array(PROJ.authors).first}") if PROJ.authors
|
21
|
+
fd.puts(" #{PROJ.url}") if PROJ.url.valid?
|
22
|
+
fd.puts(" (the \"#{PROJ.release_name}\" release)") if PROJ.release_name
|
23
|
+
fd.puts
|
24
|
+
fd.puts("== DESCRIPTION")
|
25
|
+
fd.puts
|
26
|
+
fd.puts(PROJ.description)
|
27
|
+
fd.puts
|
28
|
+
fd.puts(PROJ.changes.sub(%r/^.*$/, '== CHANGES'))
|
29
|
+
fd.puts
|
30
|
+
ann.paragraphs.each do |p|
|
31
|
+
fd.puts "== #{p.upcase}"
|
32
|
+
fd.puts
|
33
|
+
fd.puts paragraphs_of(PROJ.readme_file, p).join("\n\n")
|
34
|
+
fd.puts
|
35
|
+
end
|
36
|
+
fd.puts ann.text if ann.text
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
desc "Create an announcement file"
|
41
|
+
task :announcement => ['ann:prereqs', PROJ.ann.file]
|
42
|
+
|
43
|
+
desc "Send an email announcement"
|
44
|
+
task :email => ['ann:prereqs', PROJ.ann.file] do
|
45
|
+
ann = PROJ.ann
|
46
|
+
from = ann.email[:from] || PROJ.email
|
47
|
+
to = Array(ann.email[:to])
|
48
|
+
|
49
|
+
### build a mail header for RFC 822
|
50
|
+
rfc822msg = "From: #{from}\n"
|
51
|
+
rfc822msg << "To: #{to.join(',')}\n"
|
52
|
+
rfc822msg << "Subject: [ANN] #{PROJ.name} #{PROJ.version}"
|
53
|
+
rfc822msg << " (#{PROJ.release_name})" if PROJ.release_name
|
54
|
+
rfc822msg << "\n"
|
55
|
+
rfc822msg << "Date: #{Time.new.rfc822}\n"
|
56
|
+
rfc822msg << "Message-Id: "
|
57
|
+
rfc822msg << "<#{"%.8f" % Time.now.to_f}@#{ann.email[:domain]}>\n\n"
|
58
|
+
rfc822msg << File.read(ann.file)
|
59
|
+
|
60
|
+
params = [:server, :port, :domain, :acct, :passwd, :authtype].map do |key|
|
61
|
+
ann.email[key]
|
62
|
+
end
|
63
|
+
|
64
|
+
params[3] = PROJ.email if params[3].nil?
|
65
|
+
|
66
|
+
if params[4].nil?
|
67
|
+
STDOUT.write "Please enter your e-mail password (#{params[3]}): "
|
68
|
+
params[4] = STDIN.gets.chomp
|
69
|
+
end
|
70
|
+
|
71
|
+
### send email
|
72
|
+
Net::SMTP.start(*params) {|smtp| smtp.sendmail(rfc822msg, from, to)}
|
73
|
+
end
|
74
|
+
end # namespace :ann
|
75
|
+
|
76
|
+
desc 'Alias to ann:announcement'
|
77
|
+
task :ann => 'ann:announcement'
|
78
|
+
|
79
|
+
CLOBBER << PROJ.ann.file
|
80
|
+
|
81
|
+
# EOF
|
data/tasks/bones.rake
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
# $Id$
|
2
|
+
|
3
|
+
if HAVE_BONES
|
4
|
+
|
5
|
+
namespace :bones do
|
6
|
+
|
7
|
+
desc 'Show the PROJ open struct'
|
8
|
+
task :debug do |t|
|
9
|
+
atr = if t.application.top_level_tasks.length == 2
|
10
|
+
t.application.top_level_tasks.pop
|
11
|
+
end
|
12
|
+
|
13
|
+
if atr then Bones::Debug.show_attr(PROJ, atr)
|
14
|
+
else Bones::Debug.show PROJ end
|
15
|
+
end
|
16
|
+
|
17
|
+
end # namespace :bones
|
18
|
+
|
19
|
+
end # HAVE_BONES
|
20
|
+
|
21
|
+
# EOF
|
data/tasks/gem.rake
ADDED
@@ -0,0 +1,126 @@
|
|
1
|
+
# $Id$
|
2
|
+
|
3
|
+
require 'rake/gempackagetask'
|
4
|
+
|
5
|
+
namespace :gem do
|
6
|
+
|
7
|
+
PROJ.gem._spec = Gem::Specification.new do |s|
|
8
|
+
s.name = PROJ.name
|
9
|
+
s.version = PROJ.version
|
10
|
+
s.summary = PROJ.summary
|
11
|
+
s.authors = Array(PROJ.authors)
|
12
|
+
s.email = PROJ.email
|
13
|
+
s.homepage = Array(PROJ.url).first
|
14
|
+
s.rubyforge_project = PROJ.rubyforge.name
|
15
|
+
|
16
|
+
s.description = PROJ.description
|
17
|
+
|
18
|
+
PROJ.gem.dependencies.each do |dep|
|
19
|
+
s.add_dependency(*dep)
|
20
|
+
end
|
21
|
+
|
22
|
+
s.files = PROJ.gem.files
|
23
|
+
s.executables = PROJ.gem.executables.map {|fn| File.basename(fn)}
|
24
|
+
s.extensions = PROJ.gem.files.grep %r/extconf\.rb$/
|
25
|
+
|
26
|
+
s.bindir = 'bin'
|
27
|
+
dirs = Dir["{#{PROJ.libs.join(',')}}"]
|
28
|
+
s.require_paths = dirs unless dirs.empty?
|
29
|
+
|
30
|
+
incl = Regexp.new(PROJ.rdoc.include.join('|'))
|
31
|
+
excl = PROJ.rdoc.exclude.dup.concat %w[\.rb$ ^(\.\/|\/)?ext]
|
32
|
+
excl = Regexp.new(excl.join('|'))
|
33
|
+
rdoc_files = PROJ.gem.files.find_all do |fn|
|
34
|
+
case fn
|
35
|
+
when excl; false
|
36
|
+
when incl; true
|
37
|
+
else false end
|
38
|
+
end
|
39
|
+
s.rdoc_options = PROJ.rdoc.opts + ['--main', PROJ.rdoc.main]
|
40
|
+
s.extra_rdoc_files = rdoc_files
|
41
|
+
s.has_rdoc = true
|
42
|
+
|
43
|
+
if test ?f, PROJ.test.file
|
44
|
+
s.test_file = PROJ.test.file
|
45
|
+
else
|
46
|
+
s.test_files = PROJ.test.files.to_a
|
47
|
+
end
|
48
|
+
|
49
|
+
# Do any extra stuff the user wants
|
50
|
+
PROJ.gem.extras.each do |msg, val|
|
51
|
+
case val
|
52
|
+
when Proc
|
53
|
+
val.call(s.send(msg))
|
54
|
+
else
|
55
|
+
s.send "#{msg}=", val
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end # Gem::Specification.new
|
59
|
+
|
60
|
+
# A prerequisites task that all other tasks depend upon
|
61
|
+
task :prereqs
|
62
|
+
|
63
|
+
desc 'Show information about the gem'
|
64
|
+
task :debug => 'gem:prereqs' do
|
65
|
+
puts PROJ.gem._spec.to_ruby
|
66
|
+
end
|
67
|
+
|
68
|
+
pkg = Rake::PackageTask.new(PROJ.name, PROJ.version) do |pkg|
|
69
|
+
pkg.need_tar = PROJ.gem.need_tar
|
70
|
+
pkg.need_zip = PROJ.gem.need_zip
|
71
|
+
pkg.package_files += PROJ.gem._spec.files
|
72
|
+
end
|
73
|
+
Rake::Task['gem:package'].instance_variable_set(:@full_comment, nil)
|
74
|
+
|
75
|
+
gem_file = if PROJ.gem._spec.platform == Gem::Platform::RUBY
|
76
|
+
"#{pkg.package_name}.gem"
|
77
|
+
else
|
78
|
+
"#{pkg.package_name}-#{PROJ.gem._spec.platform}.gem"
|
79
|
+
end
|
80
|
+
|
81
|
+
desc "Build the gem file #{gem_file}"
|
82
|
+
task :package => ['gem:prereqs', "#{pkg.package_dir}/#{gem_file}"]
|
83
|
+
|
84
|
+
file "#{pkg.package_dir}/#{gem_file}" => [pkg.package_dir] + PROJ.gem._spec.files do
|
85
|
+
when_writing("Creating GEM") {
|
86
|
+
Gem::Builder.new(PROJ.gem._spec).build
|
87
|
+
verbose(true) {
|
88
|
+
mv gem_file, "#{pkg.package_dir}/#{gem_file}"
|
89
|
+
}
|
90
|
+
}
|
91
|
+
end
|
92
|
+
|
93
|
+
desc 'Install the gem'
|
94
|
+
task :install => [:clobber, 'gem:package'] do
|
95
|
+
sh "#{SUDO} #{GEM} install --local pkg/#{PROJ.gem._spec.full_name}"
|
96
|
+
|
97
|
+
# use this version of the command for rubygems > 1.0.0
|
98
|
+
#sh "#{SUDO} #{GEM} install --no-update-sources pkg/#{PROJ.gem._spec.full_name}"
|
99
|
+
end
|
100
|
+
|
101
|
+
desc 'Uninstall the gem'
|
102
|
+
task :uninstall do
|
103
|
+
installed_list = Gem.source_index.find_name(PROJ.name)
|
104
|
+
if installed_list and installed_list.collect { |s| s.version.to_s}.include?(PROJ.version) then
|
105
|
+
sh "#{SUDO} #{GEM} uninstall --version '#{PROJ.version}' --ignore-dependencies --executables #{PROJ.name}"
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
desc 'Reinstall the gem'
|
110
|
+
task :reinstall => [:uninstall, :install]
|
111
|
+
|
112
|
+
desc 'Cleanup the gem'
|
113
|
+
task :cleanup do
|
114
|
+
sh "#{SUDO} #{GEM} cleanup #{PROJ.gem._spec.name}"
|
115
|
+
end
|
116
|
+
|
117
|
+
end # namespace :gem
|
118
|
+
|
119
|
+
desc 'Alias to gem:package'
|
120
|
+
task :gem => 'gem:package'
|
121
|
+
|
122
|
+
task :clobber => 'gem:clobber_package'
|
123
|
+
|
124
|
+
remove_desc_for_task %w(gem:clobber_package)
|
125
|
+
|
126
|
+
# EOF
|
data/tasks/git.rake
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
# $Id$
|
2
|
+
|
3
|
+
if HAVE_GIT
|
4
|
+
|
5
|
+
namespace :git do
|
6
|
+
|
7
|
+
# A prerequisites task that all other tasks depend upon
|
8
|
+
task :prereqs
|
9
|
+
|
10
|
+
desc 'Show tags from the Git repository'
|
11
|
+
task :show_tags => 'git:prereqs' do |t|
|
12
|
+
puts %x/git tag/
|
13
|
+
end
|
14
|
+
|
15
|
+
desc 'Create a new tag in the Git repository'
|
16
|
+
task :create_tag => 'git:prereqs' do |t|
|
17
|
+
v = ENV['VERSION'] or abort 'Must supply VERSION=x.y.z'
|
18
|
+
abort "Versions don't match #{v} vs #{PROJ.version}" if v != PROJ.version
|
19
|
+
|
20
|
+
tag = "%s-%s" % [PROJ.name, PROJ.version]
|
21
|
+
msg = "Creating tag for #{PROJ.name} version #{PROJ.version}"
|
22
|
+
|
23
|
+
puts "Creating Git tag '#{tag}'"
|
24
|
+
unless system "git tag -a -m '#{msg}' #{tag}"
|
25
|
+
abort "Tag creation failed"
|
26
|
+
end
|
27
|
+
|
28
|
+
if %x/git remote/ =~ %r/^origin\s*$/
|
29
|
+
unless system "git push origin #{tag}"
|
30
|
+
abort "Could not push tag to remote Git repository"
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
end # namespace :git
|
36
|
+
|
37
|
+
task 'gem:release' => 'git:create_tag'
|
38
|
+
|
39
|
+
end # if HAVE_GIT
|
40
|
+
|
41
|
+
# EOF
|
data/tasks/manifest.rake
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
# $Id$
|
2
|
+
|
3
|
+
require 'find'
|
4
|
+
|
5
|
+
namespace :manifest do
|
6
|
+
|
7
|
+
desc 'Verify the manifest'
|
8
|
+
task :check do
|
9
|
+
fn = PROJ.manifest_file + '.tmp'
|
10
|
+
files = manifest_files
|
11
|
+
|
12
|
+
File.open(fn, 'w') {|fp| fp.puts files}
|
13
|
+
lines = %x(#{DIFF} -du #{PROJ.manifest_file} #{fn}).split("\n")
|
14
|
+
if HAVE_FACETS_ANSICODE and ENV.has_key?('TERM')
|
15
|
+
lines.map! do |line|
|
16
|
+
case line
|
17
|
+
when %r/^(-{3}|\+{3})/; nil
|
18
|
+
when %r/^@/; Console::ANSICode.blue line
|
19
|
+
when %r/^\+/; Console::ANSICode.green line
|
20
|
+
when %r/^\-/; Console::ANSICode.red line
|
21
|
+
else line end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
puts lines.compact
|
25
|
+
rm fn rescue nil
|
26
|
+
end
|
27
|
+
|
28
|
+
desc 'Create a new manifest'
|
29
|
+
task :create do
|
30
|
+
files = manifest_files
|
31
|
+
unless test(?f, PROJ.manifest_file)
|
32
|
+
files << PROJ.manifest_file
|
33
|
+
files.sort!
|
34
|
+
end
|
35
|
+
File.open(PROJ.manifest_file, 'w') {|fp| fp.puts files}
|
36
|
+
end
|
37
|
+
|
38
|
+
task :assert do
|
39
|
+
files = manifest_files
|
40
|
+
manifest = File.read(PROJ.manifest_file).split($/)
|
41
|
+
raise "ERROR: #{PROJ.manifest_file} is out of date" unless files == manifest
|
42
|
+
end
|
43
|
+
|
44
|
+
end # namespace :manifest
|
45
|
+
|
46
|
+
desc 'Alias to manifest:check'
|
47
|
+
task :manifest => 'manifest:check'
|
48
|
+
|
49
|
+
# EOF
|
data/tasks/notes.rake
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
# $Id$
|
2
|
+
|
3
|
+
if HAVE_BONES
|
4
|
+
|
5
|
+
desc "Enumerate all annotations"
|
6
|
+
task :notes do |t|
|
7
|
+
id = if t.application.top_level_tasks.length > 1
|
8
|
+
t.application.top_level_tasks.slice!(1..-1).join(' ')
|
9
|
+
end
|
10
|
+
Bones::AnnotationExtractor.enumerate(
|
11
|
+
PROJ, PROJ.notes.tags.join('|'), id, :tag => true)
|
12
|
+
end
|
13
|
+
|
14
|
+
namespace :notes do
|
15
|
+
PROJ.notes.tags.each do |tag|
|
16
|
+
desc "Enumerate all #{tag} annotations"
|
17
|
+
task tag.downcase.to_sym do |t|
|
18
|
+
id = if t.application.top_level_tasks.length > 1
|
19
|
+
t.application.top_level_tasks.slice!(1..-1).join(' ')
|
20
|
+
end
|
21
|
+
Bones::AnnotationExtractor.enumerate(PROJ, tag, id)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
end # if HAVE_BONES
|
27
|
+
|
28
|
+
# EOF
|
@@ -0,0 +1,39 @@
|
|
1
|
+
# $Id$
|
2
|
+
|
3
|
+
# This file does not define any rake tasks. It is used to load some project
|
4
|
+
# settings if they are not defined by the user.
|
5
|
+
|
6
|
+
PROJ.rdoc.exclude << "^#{Regexp.escape(PROJ.manifest_file)}$"
|
7
|
+
PROJ.exclude << ["^#{Regexp.escape(PROJ.ann.file)}$",
|
8
|
+
"^#{Regexp.escape(PROJ.rdoc.dir)}/",
|
9
|
+
"^#{Regexp.escape(PROJ.rcov.dir)}/"]
|
10
|
+
|
11
|
+
flatten_arrays = lambda do |this,os|
|
12
|
+
os.instance_variable_get(:@table).each do |key,val|
|
13
|
+
next if key == :dependencies
|
14
|
+
case val
|
15
|
+
when Array; val.flatten!
|
16
|
+
when OpenStruct; this.call(this,val)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
flatten_arrays.call(flatten_arrays,PROJ)
|
21
|
+
|
22
|
+
PROJ.changes ||= paragraphs_of(PROJ.history_file, 0..1).join("\n\n")
|
23
|
+
|
24
|
+
PROJ.description ||= paragraphs_of(PROJ.readme_file, 'description').join("\n\n")
|
25
|
+
|
26
|
+
PROJ.summary ||= PROJ.description.split('.').first
|
27
|
+
|
28
|
+
PROJ.gem.files ||=
|
29
|
+
if test(?f, PROJ.manifest_file)
|
30
|
+
files = File.readlines(PROJ.manifest_file).map {|fn| fn.chomp.strip}
|
31
|
+
files.delete ''
|
32
|
+
files
|
33
|
+
else [] end
|
34
|
+
|
35
|
+
PROJ.gem.executables ||= PROJ.gem.files.find_all {|fn| fn =~ %r/^bin/}
|
36
|
+
|
37
|
+
PROJ.rdoc.main ||= PROJ.readme_file
|
38
|
+
|
39
|
+
# EOF
|