Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 213 lines (173 sloc) 6.637 kB
437b6a6 Adding the files
cardmagic authored
1 require 'rubygems'
2 require 'rake'
3 require 'rake/testtask'
4 require 'rake/rdoctask'
5 require 'rake/gempackagetask'
6 require 'rake/contrib/rubyforgepublisher'
7 require File.dirname(__FILE__) + '/lib/simple-rss'
8
9 PKG_VERSION = SimpleRSS::VERSION
10 PKG_NAME = "simple-rss"
11 PKG_FILE_NAME = "#{PKG_NAME}-#{PKG_VERSION}"
12 RUBY_FORGE_PROJECT = "simple-rss"
13 RUBY_FORGE_USER = ENV['RUBY_FORGE_USER'] || "cardmagic"
14 RELEASE_NAME = "#{PKG_NAME}-#{PKG_VERSION}"
15
16 PKG_FILES = FileList[
17 "lib/*", "bin/*", "test/**/*", "[A-Z]*", "Rakefile", "html/**/*"
18 ]
19
20 desc "Default Task"
21 task :default => [ :test ]
22
23 # Run the unit tests
24 desc "Run all unit tests"
25 Rake::TestTask.new("test") { |t|
26 t.libs << "lib"
27 t.pattern = 'test/*/*_test.rb'
28 t.verbose = true
29 }
30
31 # Make a console, useful when working on tests
32 desc "Generate a test console"
33 task :console do
34 verbose( false ) { sh "irb -I lib/ -r 'simple-rss'" }
35 end
36
37 # Genereate the RDoc documentation
38 desc "Create documentation"
39 Rake::RDocTask.new("doc") { |rdoc|
40 rdoc.title = "Simple RSS - A Flexible RSS and Atom reader for Ruby"
41 rdoc.rdoc_dir = 'html'
42 rdoc.rdoc_files.include('README')
43 rdoc.rdoc_files.include('lib/*.rb')
44 }
45
46 # Genereate the package
47 spec = Gem::Specification.new do |s|
48
49 #### Basic information.
50
51 s.name = 'simple-rss'
52 s.version = PKG_VERSION
53 s.summary = <<-EOF
54 A simple, flexible, extensible, and liberal RSS and Atom reader for Ruby. It is designed to be backwards compatible with the standard RSS parser, but will never do RSS generation.
55 EOF
56 s.description = <<-EOF
57 A simple, flexible, extensible, and liberal RSS and Atom reader for Ruby. It is designed to be backwards compatible with the standard RSS parser, but will never do RSS generation.
58 EOF
59
60 #### Which files are to be included in this gem? Everything! (Except CVS directories.)
61
62 s.files = PKG_FILES
63
64 #### Load-time details: library and application (you will need one or both).
65
66 s.require_path = 'lib'
67
68 #### Documentation and testing.
69
70 s.has_rdoc = true
71
72 #### Author and project details.
73
74 s.author = "Lucas Carlson"
75 s.email = "lucas@rufy.com"
76 s.homepage = "http://simple-rss.rubyforge.org/"
77 end
78
79 Rake::GemPackageTask.new(spec) do |pkg|
80 pkg.need_zip = true
81 pkg.need_tar = true
82 end
83
84 desc "Report code statistics (KLOCs, etc) from the application"
85 task :stats do
86 require 'code_statistics'
87 CodeStatistics.new(
88 ["Library", "lib"],
89 ["Units", "test"]
90 ).to_s
91 end
92
93 desc "Publish new documentation"
94 task :publish do
95 Rake::RubyForgePublisher.new('simple-rss', 'cardmagic').upload
96 end
97
98
99 desc "Publish the release files to RubyForge."
100 task :upload => [:package] do
101 files = ["gem", "tar.gz", "zip"].map { |ext| "pkg/#{PKG_FILE_NAME}.#{ext}" }
102
103 if RUBY_FORGE_PROJECT then
104 require 'net/http'
105 require 'open-uri'
106
107 project_uri = "http://rubyforge.org/projects/#{RUBY_FORGE_PROJECT}/"
108 project_data = open(project_uri) { |data| data.read }
109 group_id = project_data[/[?&]group_id=(\d+)/, 1]
110 raise "Couldn't get group id" unless group_id
111
112 # This echos password to shell which is a bit sucky
113 if ENV["RUBY_FORGE_PASSWORD"]
114 password = ENV["RUBY_FORGE_PASSWORD"]
115 else
116 print "#{RUBY_FORGE_USER}@rubyforge.org's password: "
117 password = STDIN.gets.chomp
118 end
119
120 login_response = Net::HTTP.start("rubyforge.org", 80) do |http|
121 data = [
122 "login=1",
123 "form_loginname=#{RUBY_FORGE_USER}",
124 "form_pw=#{password}"
125 ].join("&")
126 http.post("/account/login.php", data)
127 end
128
129 cookie = login_response["set-cookie"]
130 raise "Login failed" unless cookie
131 headers = { "Cookie" => cookie }
132
133 release_uri = "http://rubyforge.org/frs/admin/?group_id=#{group_id}"
134 release_data = open(release_uri, headers) { |data| data.read }
135 package_id = release_data[/[?&]package_id=(\d+)/, 1]
136 raise "Couldn't get package id" unless package_id
137
138 first_file = true
139 release_id = ""
140
141 files.each do |filename|
142 basename = File.basename(filename)
143 file_ext = File.extname(filename)
144 file_data = File.open(filename, "rb") { |file| file.read }
145
146 puts "Releasing #{basename}..."
147
148 release_response = Net::HTTP.start("rubyforge.org", 80) do |http|
149 release_date = Time.now.strftime("%Y-%m-%d %H:%M")
150 type_map = {
151 ".zip" => "3000",
152 ".tgz" => "3110",
153 ".gz" => "3110",
154 ".gem" => "1400"
155 }; type_map.default = "9999"
156 type = type_map[file_ext]
157 boundary = "rubyqMY6QN9bp6e4kS21H4y0zxcvoor"
158
159 query_hash = if first_file then
160 {
161 "group_id" => group_id,
162 "package_id" => package_id,
163 "release_name" => RELEASE_NAME,
164 "release_date" => release_date,
165 "type_id" => type,
166 "processor_id" => "8000", # Any
167 "release_notes" => "",
168 "release_changes" => "",
169 "preformatted" => "1",
170 "submit" => "1"
171 }
172 else
173 {
174 "group_id" => group_id,
175 "release_id" => release_id,
176 "package_id" => package_id,
177 "step2" => "1",
178 "type_id" => type,
179 "processor_id" => "8000", # Any
180 "submit" => "Add This File"
181 }
182 end
183
184 query = "?" + query_hash.map do |(name, value)|
185 [name, URI.encode(value)].join("=")
186 end.join("&")
187
188 data = [
189 "--" + boundary,
190 "Content-Disposition: form-data; name=\"userfile\"; filename=\"#{basename}\"",
191 "Content-Type: application/octet-stream",
192 "Content-Transfer-Encoding: binary",
193 "", file_data, ""
194 ].join("\x0D\x0A")
195
196 release_headers = headers.merge(
197 "Content-Type" => "multipart/form-data; boundary=#{boundary}"
198 )
199
200 target = first_file ? "/frs/admin/qrs.php" : "/frs/admin/editrelease.php"
201 http.post(target + query, data, release_headers)
202 end
203
204 if first_file then
205 release_id = release_response.body[/release_id=(\d+)/, 1]
206 raise("Couldn't get release id") unless release_id
207 end
208
209 first_file = false
210 end
211 end
212 end
Something went wrong with that request. Please try again.