io-reactor 0.05 → 1.0.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,112 @@
1
+ #
2
+ # Packaging Rake Tasks
3
+ # $Id: packaging.rb 21 2008-08-07 23:45:52Z deveiant $
4
+ #
5
+
6
+ require 'rbconfig'
7
+ require 'rake/packagetask'
8
+ require 'rake/gempackagetask'
9
+
10
+ include Config
11
+
12
+ ### Task: gem
13
+ ### Task: package
14
+ Rake::PackageTask.new( PKG_NAME, PKG_VERSION ) do |task|
15
+ task.need_tar_gz = true
16
+ task.need_tar_bz2 = true
17
+ task.need_zip = true
18
+ task.package_dir = PKGDIR.to_s
19
+ task.package_files = RELEASE_FILES.
20
+ collect {|f| f.relative_path_from(BASEDIR).to_s }
21
+ end
22
+ task :package => [:gem]
23
+
24
+
25
+ ### Task: gem
26
+ gempath = PKGDIR + GEM_FILE_NAME
27
+
28
+ desc "Build a RubyGem package (#{GEM_FILE_NAME})"
29
+ task :gem => gempath.to_s
30
+ file gempath.to_s => [PKGDIR.to_s] + GEMSPEC.files do
31
+ when_writing( "Creating GEM" ) do
32
+ Gem::Builder.new( GEMSPEC ).build
33
+ verbose( true ) do
34
+ mv GEM_FILE_NAME, gempath
35
+ end
36
+ end
37
+ end
38
+
39
+ ### Task: install
40
+ desc "Install #{PKG_NAME} as a conventional library"
41
+ task :install do
42
+ log "Installing #{PKG_NAME} as a conventional library"
43
+ sitelib = Pathname.new( CONFIG['sitelibdir'] )
44
+ sitearch = Pathname.new( CONFIG['sitearchdir'] )
45
+ Dir.chdir( LIBDIR ) do
46
+ LIB_FILES.each do |libfile|
47
+ relpath = libfile.relative_path_from( LIBDIR )
48
+ target = sitelib + relpath
49
+ FileUtils.mkpath target.dirname,
50
+ :mode => 0755, :verbose => true, :noop => $dryrun unless target.dirname.directory?
51
+ FileUtils.install relpath, target,
52
+ :mode => 0644, :verbose => true, :noop => $dryrun
53
+ end
54
+ end
55
+ if EXTDIR.exist?
56
+ Dir.chdir( EXTDIR ) do
57
+ Pathname.glob( EXTDIR + Config::CONFIG['DLEXT'] ) do |dl|
58
+ target = sitearch + dl.basename
59
+ FileUtils.install dl, target,
60
+ :mode => 0755, :verbose => true, :noop => $dryrun
61
+ end
62
+ end
63
+ end
64
+ end
65
+
66
+
67
+
68
+ ### Task: install_gem
69
+ desc "Install #{PKG_NAME} from a locally-built gem"
70
+ task :install_gem => [:package] do
71
+ $stderr.puts
72
+ installer = Gem::Installer.new( %{pkg/#{PKG_FILE_NAME}.gem} )
73
+ installer.install
74
+ end
75
+
76
+
77
+ ### Task: uninstall
78
+ desc "Uninstall #{PKG_NAME} if it's been installed as a conventional library"
79
+ task :uninstall do
80
+ log "Uninstalling conventionally-installed #{PKG_NAME} library files"
81
+ sitelib = Pathname.new( CONFIG['sitelibdir'] )
82
+ sitearch = Pathname.new( CONFIG['sitearchdir'] )
83
+
84
+ Dir.chdir( LIBDIR ) do
85
+ LIB_FILES.each do |libfile|
86
+ relpath = libfile.relative_path_from( LIBDIR )
87
+ target = sitelib + relpath
88
+ FileUtils.rm_f target, :verbose => true, :noop => $dryrun
89
+ FileUtils.rm_rf( target.dirname, :verbose => true, :noop => $dryrun ) if
90
+ target.dirname.entries.empty?
91
+ end
92
+ end
93
+ if EXTDIR.exist?
94
+ Dir.chdir( EXTDIR ) do
95
+ Pathname.glob( EXTDIR + Config::CONFIG['DLEXT'] ) do |dl|
96
+ target = sitearch + dl.basename
97
+ FileUtils.rm target, :verbose => true, :noop => $dryrun
98
+ end
99
+ end
100
+ end
101
+ end
102
+
103
+
104
+ ### Task: uninstall_gem
105
+ desc "Install the #{PKG_NAME} gem"
106
+ task :uninstall_gem => [:clean] do
107
+ uninstaller = Gem::Uninstaller.new( PKG_FILE_NAME )
108
+ uninstaller.uninstall
109
+ end
110
+
111
+
112
+
@@ -0,0 +1,302 @@
1
+ #####################################################################
2
+ ### P U B L I C A T I O N T A S K S
3
+ #####################################################################
4
+
5
+ RELEASE_NOTES_FILE = 'release.notes'
6
+ RELEASE_ANNOUNCE_FILE = 'release.ann'
7
+
8
+ require 'net/smtp'
9
+ require 'net/protocol'
10
+ require 'openssl'
11
+
12
+ $publish_privately = false
13
+
14
+ ### Add SSL to Net::SMTP
15
+ class Net::SMTP
16
+ def ssl_start( helo='localhost.localdomain', user=nil, secret=nil, authtype=nil )
17
+ if block_given?
18
+ begin
19
+ do_ssl_start( helo, user, secret, authtype )
20
+ return yield( self )
21
+ ensure
22
+ do_finish
23
+ end
24
+ else
25
+ do_ssl_start( helo, user, secret, authtype )
26
+ return self
27
+ end
28
+ end
29
+
30
+
31
+ #######
32
+ private
33
+ #######
34
+
35
+ def do_ssl_start( helodomain, user, secret, authtype )
36
+ raise IOError, 'SMTP session already started' if @started
37
+ check_auth_args user, secret, authtype if user or secret
38
+
39
+ # Open the connection
40
+ @debug_output << "opening connection to #{@address}...\n" if @debug_output
41
+ sock = timeout( @open_timeout ) { TCPsocket.new(@address, @port) }
42
+
43
+ # Wrap it in the SSL layer
44
+ ssl_context = OpenSSL::SSL::SSLContext.new
45
+ ssl_context.verify_mode = OpenSSL::SSL::VERIFY_NONE
46
+ ssl_sock = OpenSSL::SSL::SSLSocket.new( sock, ssl_context )
47
+ ssl_sock.sync_close = true
48
+ ssl_sock.connect
49
+
50
+ # Wrap it in the message-oriented IO layer
51
+ sslmsgio = Net::InternetMessageIO.new( ssl_sock )
52
+ sslmsgio.read_timeout = @read_timeout
53
+ sslmsgio.debug_output = @debug_output
54
+
55
+ @socket = sslmsgio
56
+
57
+ check_response(critical { recv_response() })
58
+ begin
59
+ if @esmtp
60
+ ehlo helodomain
61
+ else
62
+ helo helodomain
63
+ end
64
+ rescue ProtocolError
65
+ if @esmtp
66
+ @esmtp = false
67
+ @error_occured = false
68
+ retry
69
+ end
70
+ raise
71
+ end
72
+ authenticate user, secret, authtype if user
73
+ @started = true
74
+ ensure
75
+ @socket.close if not @started and @socket and not @socket.closed?
76
+ end
77
+ end
78
+
79
+
80
+ begin
81
+ gem 'text-format'
82
+
83
+ require 'time'
84
+ require 'rake/tasklib'
85
+ require 'tmail'
86
+ require 'net/smtp'
87
+ require 'etc'
88
+ require 'rubyforge'
89
+ require 'socket'
90
+ require 'text/format'
91
+
92
+ ### Generate a valid RFC822 message-id
93
+ def gen_message_id
94
+ return "<%s.%s@%s>" % [
95
+ (Time.now.to_f * 10000).to_i.to_s( 36 ),
96
+ (rand( 2 ** 64 - 1 )).to_s( 36 ),
97
+ Socket.gethostname
98
+ ]
99
+ end
100
+
101
+
102
+ namespace :release do
103
+ task :default => [ 'svn:release', :publish, :announce, :project ]
104
+
105
+ desc "Re-publish the release with the current version number"
106
+ task :rerelease => [ :publish, :announce, :project ]
107
+
108
+ task :test do
109
+ $publish_privately = true
110
+ end
111
+ task :test => [ :rerelease ]
112
+
113
+
114
+ desc "Generate the release notes"
115
+ task :notes => [RELEASE_NOTES_FILE]
116
+ file RELEASE_NOTES_FILE do |task|
117
+ last_rel_tag = get_latest_release_tag() or
118
+ fail ">>> No releases tagged! Try running 'rake svn:release' first"
119
+ trace "Last release tag is: %p" % [ last_rel_tag ]
120
+ start = get_last_changed_rev( last_rel_tag ) || 1
121
+ trace "Starting rev is: %p" % [ start ]
122
+ log_output = make_svn_log( '.', start, 'HEAD' )
123
+
124
+ File.open( task.name, File::WRONLY|File::TRUNC|File::CREAT ) do |fh|
125
+ fh.print( log_output )
126
+ end
127
+
128
+ edit task.name
129
+ end
130
+ CLEAN.include( RELEASE_NOTES_FILE )
131
+
132
+
133
+ task :project => [ :rdoc ] do
134
+ when_writing( "Publishing docs to #{PROJECT_SCPDOCURL}" ) do
135
+ run 'ssh', PROJECT_HOST, "rm -rf #{PROJECT_SCPDOCURL}"
136
+ run 'scp', '-qCr', 'docs/html', PROJECT_SCPDOCURL
137
+ end
138
+ when_writing( "Uploading packages") do
139
+ pkgs = Pathname.glob( PKGDIR + "#{PKG_FILE_NAME}.{gem,tar.gz,tar.bz2,zip}" )
140
+ log "Uploading %d packages to #{PROJECT_SCPPUBURL}" % [ pkgs.length ]
141
+ pkgs.each do |pkgfile|
142
+ run 'scp', '-qC', pkgfile, PROJECT_SCPPUBURL
143
+ end
144
+ end
145
+ end
146
+
147
+
148
+ file RELEASE_ANNOUNCE_FILE => [RELEASE_NOTES_FILE] do |task|
149
+ relnotes = File.read( RELEASE_NOTES_FILE )
150
+ announce_body = %{
151
+
152
+ Version #{PKG_VERSION} of #{PKG_NAME} has been released.
153
+
154
+ #{Text::Format.new(:first_indent => 0).format_one_paragraph(GEMSPEC.description)}
155
+
156
+ == Project Page
157
+
158
+ #{GEMSPEC.homepage}
159
+
160
+ == Installation
161
+
162
+ Via gems:
163
+
164
+ $ sudo gem install #{GEMSPEC.name}
165
+
166
+ or from source:
167
+
168
+ $ wget http://deveiate.org/code/#{PKG_FILE_NAME}.tar.gz
169
+ $ tar -xzvf #{PKG_FILE_NAME}.tar.gz
170
+ $ cd #{PKG_FILE_NAME}
171
+ $ sudo rake install
172
+
173
+ == Changes
174
+ #{relnotes}
175
+ }.gsub( /^\t+/, '' )
176
+
177
+ File.open( task.name, File::WRONLY|File::TRUNC|File::CREAT ) do |fh|
178
+ fh.print( announce_body )
179
+ end
180
+
181
+ edit task.name
182
+ end
183
+ CLEAN.include( RELEASE_ANNOUNCE_FILE )
184
+
185
+
186
+ desc 'Send out a release announcement'
187
+ task :announce => [RELEASE_ANNOUNCE_FILE] do
188
+ email = TMail::Mail.new
189
+ if $publish_privately
190
+ trace "Sending private announce mail"
191
+ email.to = 'rubymage@gmail.com'
192
+ else
193
+ trace "Sending public announce mail"
194
+ email.to = 'Ruby-Talk List <ruby-talk@ruby-lang.org>'
195
+ email.bcc = 'rubymage@gmail.com'
196
+ end
197
+ email.from = GEMSPEC.email
198
+ email.subject = "[ANN] #{PKG_NAME} #{PKG_VERSION}"
199
+ email.body = File.read( RELEASE_ANNOUNCE_FILE )
200
+ email.date = Time.new
201
+
202
+ email.message_id = gen_message_id()
203
+
204
+ log "About to send the following email:"
205
+ puts '---',
206
+ email.to_s,
207
+ '---'
208
+
209
+ ask_for_confirmation( "Will send via #{SMTP_HOST}." ) do
210
+ pwent = Etc.getpwuid( Process.euid )
211
+ curuser = pwent ? pwent.name : 'unknown'
212
+ username = prompt_with_default( "SMTP user", curuser )
213
+ password = prompt_for_password()
214
+
215
+ trace "Creating SMTP connection to #{SMTP_HOST}:#{SMTP_PORT}"
216
+ smtp = Net::SMTP.new( SMTP_HOST, SMTP_PORT )
217
+ smtp.set_debug_output( $stdout )
218
+ smtp.esmtp = true
219
+
220
+ trace "connecting..."
221
+ smtp.ssl_start( Socket.gethostname, username, password, :plain ) do |smtp|
222
+ trace "sending message..."
223
+ smtp.send_message( email.to_s, email.from, email.to )
224
+ end
225
+ trace "done."
226
+ end
227
+ end
228
+
229
+
230
+ desc 'Publish the new release to RubyForge'
231
+ task :publish => [:clobber, :package, :notes] do |task|
232
+ project = GEMSPEC.rubyforge_project
233
+
234
+ rf = RubyForge.new
235
+ log "Loading RubyForge config"
236
+ rf.configure
237
+
238
+ group_id = rf.autoconfig['group_ids'][RUBYFORGE_GROUP] or
239
+ fail "Your configuration doesn't have a group id for '#{RUBYFORGE_GROUP}'"
240
+
241
+ # If this project doesn't yet exist, create it
242
+ unless rf.autoconfig['package_ids'].key?( project )
243
+ ask_for_confirmation( "Package '#{project}' doesn't exist on RubyForge. Create it?" ) do
244
+ log "Creating new package '#{project}'"
245
+ rf.create_package( group_id, project )
246
+ end
247
+ end
248
+
249
+ package_id = rf.autoconfig['package_ids'][ project ]
250
+
251
+ # Make sure this release doesn't already exist
252
+ releases = rf.autoconfig['release_ids']
253
+ if releases.key?( GEMSPEC.name ) && releases[ GEMSPEC.name ].key?( PKG_VERSION )
254
+ log "Rubyforge seems to already have #{ PKG_FILE_NAME }"
255
+ else
256
+ config = rf.userconfig or
257
+ fail "You apparently haven't set up your RubyForge credentials on this machine."
258
+ config['release_notes'] = GEMSPEC.description
259
+ config['release_changes'] = File.read( RELEASE_NOTES_FILE )
260
+
261
+ files = FileList[ PKGDIR + GEM_FILE_NAME ]
262
+ files.include PKGDIR + "#{PKG_FILE_NAME}.tar.gz"
263
+ files.include PKGDIR + "#{PKG_FILE_NAME}.tar.bz2"
264
+ files.include PKGDIR + "#{PKG_FILE_NAME}.zip"
265
+
266
+ log "Releasing #{PKG_FILE_NAME}"
267
+ when_writing do
268
+ log "Publishing to RubyForge: \n",
269
+ "\tproject: #{RUBYFORGE_GROUP}\n",
270
+ "\tpackage: #{PKG_NAME.downcase}\n",
271
+ "\tpackage version: #{PKG_VERSION}\n",
272
+ "\tfiles: " + files.collect {|f| f.to_s }.join(', ') + "\n"
273
+
274
+ ask_for_confirmation( "Publish to RubyForge?" ) do
275
+ log 'Logging in...'
276
+ rf.login
277
+ log "Adding the new release to the '#{project}' project"
278
+ rf.add_release( group_id, package_id, PKG_VERSION, *files )
279
+ end
280
+ end
281
+ end
282
+ end
283
+ end
284
+
285
+ rescue LoadError => err
286
+ if !Object.const_defined?( :Gem )
287
+ require 'rubygems'
288
+ retry
289
+ end
290
+
291
+ task :no_release_tasks do
292
+ fail "Release tasks not defined: #{err.message}"
293
+ end
294
+
295
+ task :release => :no_release_tasks
296
+ task "release:announce" => :no_release_tasks
297
+ task "release:publish" => :no_release_tasks
298
+ task "release:notes" => :no_release_tasks
299
+ end
300
+
301
+ task :release => 'release:default'
302
+
@@ -0,0 +1,31 @@
1
+ #
2
+ # RDoc Rake tasks for ThingFish
3
+ # $Id: rdoc.rb 35 2008-08-19 01:10:27Z deveiant $
4
+ #
5
+
6
+ require 'rake/rdoctask'
7
+ $have_darkfish = false
8
+
9
+ begin
10
+ require 'darkfish-rdoc'
11
+ $have_darkfish = true
12
+ rescue LoadError => err
13
+ unless Object.const_defined?( :Gem )
14
+ require 'rubygems'
15
+ gem 'darkfish-rdoc'
16
+ retry
17
+ end
18
+
19
+ log "No DarkFish: %s: %s" % [ err.class.name, err.message ]
20
+ trace "Backtrace:\n %s" % [ err.backtrace.join("\n ") ]
21
+ end
22
+
23
+ Rake::RDocTask.new do |rdoc|
24
+ rdoc.rdoc_dir = 'docs/html'
25
+ rdoc.title = "#{PKG_NAME} - #{PKG_SUMMARY}"
26
+ rdoc.options += RDOC_OPTIONS + [ '-f', 'darkfish' ] if $have_darkfish
27
+
28
+ rdoc.rdoc_files.include 'README'
29
+ rdoc.rdoc_files.include LIB_FILES.collect {|f| f.to_s }
30
+ rdoc.rdoc_files.include EXT_FILES.collect {|f| f.to_s }
31
+ end
@@ -0,0 +1,62 @@
1
+ #
2
+ # Style Fixup Rake Tasks
3
+ # $Id: style.rb 10 2008-07-18 15:52:48Z deveiant $
4
+ #
5
+ # Authors:
6
+ # * Michael Granger <ged@FaerieMUD.org>
7
+ #
8
+
9
+
10
+ ### Coding style checks and fixes
11
+ namespace :style do
12
+
13
+ BLANK_LINE = /^\s*$/
14
+ GOOD_INDENT = /^(\t\s*)?\S/
15
+
16
+ # A list of the files that have legitimate leading whitespace, etc.
17
+ PROBLEM_FILES = [ SPECDIR + 'config_spec.rb' ]
18
+
19
+ desc "Check source files for inconsistent indent and fix them"
20
+ task :fix_indent do
21
+ files = LIB_FILES + SPEC_FILES
22
+
23
+ badfiles = Hash.new {|h,k| h[k] = [] }
24
+
25
+ trace "Checking files for indentation"
26
+ files.each do |file|
27
+ if PROBLEM_FILES.include?( file )
28
+ trace " skipping problem file #{file}..."
29
+ next
30
+ end
31
+
32
+ trace " #{file}"
33
+ linecount = 0
34
+ file.each_line do |line|
35
+ linecount += 1
36
+
37
+ # Skip blank lines
38
+ next if line =~ BLANK_LINE
39
+
40
+ # If there's a line with incorrect indent, note it and skip to the
41
+ # next file
42
+ if line !~ GOOD_INDENT
43
+ trace " Bad line %d: %p" % [ linecount, line ]
44
+ badfiles[file] << [ linecount, line ]
45
+ end
46
+ end
47
+ end
48
+
49
+ if badfiles.empty?
50
+ log "No indentation problems found."
51
+ else
52
+ log "Found incorrect indent in #{badfiles.length} files:\n "
53
+ badfiles.each do |file, badlines|
54
+ log " #{file}:\n" +
55
+ " " + badlines.collect {|badline| "%5d: %p" % badline }.join( "\n " )
56
+ end
57
+ end
58
+ end
59
+
60
+ end
61
+
62
+