rscm 0.1.0.999 → 0.1.0.1337

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -108,9 +108,27 @@ else
108
108
  end
109
109
 
110
110
  task :publish do
111
- publisher = Rake::CompositePublisher.new
112
- # publisher.add Rake::RubyForgePublisher.new('rscm', 'aslak_hellesoy')
113
- publisher.add Rake::RubyForgeFilePublisher.new('rscm', 490, 'aslak_hellesoy', ENV['RUBYFORGE_PASSWORD'], "pkg/#{PKG_FILE_NAME}")
111
+ # publisher = Rake::CompositePublisher.new
112
+ # publisher.add Rake::RubyForgePublisher.new('rscm', 'aslak_hellesoy')
113
+
114
+ RUBYFORGE_GROUP_ID = 490
115
+ RUBYFORGE_PACKAGE_ID = 552
116
+ RUBYFORGE_RELEASE_NAME = "rakedrelease"
117
+
118
+ Rake::RubyForgeFilePublisher.new(
119
+ RUBYFORGE_GROUP_ID,
120
+ "aslak_hellesoy",
121
+ "README",
122
+ #"pkg/#{PKG_FILE_NAME}.gem",
123
+ RUBYFORGE_PACKAGE_ID,
124
+ RUBYFORGE_RELEASE_NAME
125
+ ) do |p|
126
+ p.type_id = 8100
127
+ p.processor_id = 2000
128
+ p.preformatted = 1
129
+ p.release_name = "come on"
130
+ p.release_changes = "now"
131
+ p.release_date = Time.utc(2005, 2, 19, 23, 42, 0)
132
+ end
114
133
 
115
- publisher.upload
116
134
  end
@@ -2,6 +2,9 @@ require 'open-uri'
2
2
  require 'net/http'
3
3
  require 'cgi'
4
4
 
5
+ # Adds multipart support to Net::HTTP
6
+ # based on Code from Patrick May
7
+ # http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/113774
5
8
  module Net
6
9
  class Param
7
10
  def initialize(k, v)
@@ -15,39 +18,78 @@ module Net
15
18
  end
16
19
 
17
20
  class FileParam
18
- def initialize(k, file)
21
+ def initialize(k, file, mime_type)
19
22
  @k = k
20
23
  @file = file
24
+ @mime_type = mime_type
21
25
  end
22
26
 
23
27
  def to_multipart
24
- content = @file.open.read
25
- "Content-Disposition: form-data; name=\"#{CGI::escape(@k)}\"; filename=\"#{File.basename(@file.name)}\"\r\n" +
26
- "Content-Transfer-Encoding: binary\r\n" +
27
- "Content-Type: #{@file.mime_type}\r\n\r\n" + content + "\r\n"
28
+ content = File.open(@file).read
29
+ "Content-Disposition: form-data; name=\"#{CGI::escape(@k)}\"; filename=\"#{File.basename(@file)}\"\r\n" +
30
+ "Content-Type: #{@mime_type}\r\n\r\n" + content + "\r\n"
28
31
  end
29
32
  end
30
33
 
31
34
  class HTTP
32
- def post_multipart(path, data, header=nil, dest=nil, boundary="7d21f962d00c4") # :yield: self
33
- params = []
34
- data.each do |k, v|
35
- param = nil
36
- if(v.is_a?(File))
37
- param = FileParam.new(k,v)
38
- else
39
- param = Param.new(k,v)
40
- end
41
- params << param
42
- end
43
-
44
- query = params.collect { |p|
35
+
36
+ def post_multipart(path, params, header={}, dest=nil, boundary="----------ThIs_Is_tHe_bouNdaRY_$") # :yield: self
37
+ body = params.collect { |p|
45
38
  "--" + boundary + "\r\n" + p.to_multipart
46
- }.join("") + "--" + boundary + "--"
47
-
48
- header["Content-type" => "multipart/form-data, boundary=" + boundary + " "]
49
- puts "HEADER: #{header.inspect}"
50
- post(data, query, header, dest)
39
+ }.join("") + "--" + boundary + "--" + "\r\n"
40
+
41
+ header["Content-Type"] = "multipart/form-data; boundary=" + boundary
42
+ header["Content-Length"] = "#{body.length}"
43
+
44
+ post(path, body, header, dest)
45
+ end
46
+
47
+ alias :old_post :post
48
+ def post(path, data, initheader = nil, dest = nil)
49
+ puts "----POST----"
50
+ puts path
51
+ puts "------------"
52
+ if(initheader)
53
+ initheader.each {|k,v|
54
+ puts "#{k}: #{v}"
55
+ }
56
+ end
57
+ puts
58
+ puts data
59
+
60
+ response, data = old_post(path, data, initheader, dest)
61
+
62
+ puts "----POST RESP----"
63
+ puts response.class.name
64
+ puts "------------"
65
+ response.each {|k,v|
66
+ puts "#{k}: #{v}"
67
+ }
68
+
69
+ return response, data
70
+ end
71
+
72
+ alias :old_get :get
73
+ def get(path, initheader = nil, dest = nil)
74
+ puts "----GET-----"
75
+ puts path
76
+ puts "------------"
77
+ if(initheader)
78
+ initheader.each {|k,v|
79
+ puts "#{k}: #{v}"
80
+ }
81
+ end
82
+
83
+ response, data = old_get(path, initheader, dest)
84
+
85
+ puts "----GET RESP----"
86
+ puts response.class.name
87
+ puts "------------"
88
+ response.each {|k,v|
89
+ puts "#{k}: #{v}"
90
+ }
91
+
92
+ return response, data
51
93
  end
52
94
  end
53
95
  end
@@ -34,15 +34,17 @@ module Rake
34
34
  )
35
35
 
36
36
  # Returns an array of 2 elements where 1st is mime-type and 2nd is rubyforge-type
37
- def types(filename, source=false)
37
+ def types(filename, source)
38
+ extension = nil
38
39
  if(filename =~ /.*(\.[a-zA-Z]*)/)
39
40
  extension = $1
40
- types = FILE_TYPES[extension]
41
- if(types.length == 3 && source)
42
- [types[0], types[2]]
43
- else
44
- types
45
- end
41
+ end
42
+
43
+ types = FILE_TYPES[extension]
44
+ if(types.length == 3 && source)
45
+ [types[0], types[2]]
46
+ else
47
+ types
46
48
  end
47
49
  end
48
50
 
@@ -57,93 +59,118 @@ module Rake
57
59
  ULTRA_SPARC = 5000
58
60
  OTHER_PLATFORM = 9999
59
61
 
60
- # Create a publisher for a RubyForge project with +package_id+.
61
- # For security reasons, don't give the +password+ parameter a hard-coded
62
- # value, but use an environment variable instead: PASSWORD=mooky
62
+ # Create a publisher for a RubyForge project with id +group_id+.
63
+ # The RubyForge +user+'s password must be specified in the environment
64
+ # variable RUBYFORGE_PASSWORD.
63
65
  #
66
+ # This publisher will upload/release a +file+ for a RubyForge project
67
+ # with id +group_id+, under the release package +package_id+ and
68
+ # name the release +release_name+.
69
+ #
70
+ # The package_id can be found by viewing the source of the HTML page
71
+ # http://rubyforge.org/frs/admin/qrs.php?package=&group_id=YOUR_GROUP_ID
72
+ # Look for a select tag named package_id and see what the alternatives are.
73
+ #
64
74
  # The optional argument +source+ can be set to true if the file
65
- # pointed to be +filename+ is a source file of some sort. This is
75
+ # pointed to by +filename+ is a source file of some sort. This is
66
76
  # to make sure RubyForge lists the file as the appropriate type.
77
+ # (This task will figure out the correct mime-type and rubyforge type
78
+ # based on the file's extension and the source parameter).
67
79
  #
68
80
  # If called with a block, the file will be uploaded at the end of the
69
81
  # construction of this object. Otherwise, the +upload+ method will
70
82
  # have to be called explicitly.
71
83
  #
72
84
  # The following attributes (which represent form data) have default
73
- # values, but can be set explicitly:
85
+ # values, but can be set/overridden explicitly:
74
86
  #
75
- # * type_id
76
87
  # * processor_id
77
88
  # * release_date
78
89
  # * release_notes
79
90
  # * change_log
80
91
  #
81
- def initialize(package_id, release_name, user, password, file, source=false) # :yield: self
82
- @form_data = {}
92
+ def initialize(group_id, user, file, package_id, release_name, source=false) # :yield: self
93
+
94
+ @group_id = group_id
83
95
  @user = user
84
- @password = password
85
96
  @file = file
86
97
 
87
- types = types(file, source)
88
- self.type_id = types[1]
98
+ @form_data = {"preformatted" => "1", "submit" => "Release File" }
99
+
100
+ self.package_id = package_id
101
+ self.release_name = release_name
102
+
103
+ @types = types(file, source)
104
+ self.type_id = @types[1]
89
105
  self.processor_id = ANY
90
106
  self.release_date = Time.now.utc
91
107
  self.release_notes = "Uploaded by Rake::RubyforgeFilePublisher"
92
- self.change_log = ""
108
+ self.release_changes = "This is a change log"
93
109
 
94
- self.package_id = package_id
95
- self.release_name = release_name
96
-
97
110
  yield self if block_given?
98
111
  upload if block_given?
99
112
  end
100
113
 
101
- # fills in the upload form
102
- def method_missing(name, args)
103
- @form_data[name.to_s] = args
114
+ def package_id=(s)
115
+ @form_data["package_id"] = s
116
+ end
117
+ def package_id
118
+ @form_data["package_id"]
119
+ end
120
+ def release_name=(s)
121
+ @form_data["release_name"] = s
122
+ end
123
+ def type_id=(s)
124
+ @form_data["type_id"] = s
125
+ end
126
+ def processor_id=(s)
127
+ @form_data["processor_id"] = s
128
+ end
129
+ def release_date=(t)
130
+ @form_data["release_date"] = t.strftime("%Y-%m-%d %H:%M")
131
+ end
132
+ def release_notes=(s)
133
+ @form_data["release_notes"] = s
134
+ end
135
+ def release_changes=(s)
136
+ @form_data["release_changes"] = s
137
+ end
138
+ def preformatted=(b)
139
+ @form_data["preformatted"] = b ? "1" : "0"
104
140
  end
105
141
 
106
142
  def upload
107
143
  Net::HTTP.start('rubyforge.org', 80) do |http|
108
- http.set_debug_output $stderr
109
144
 
110
145
  # log in so we get a cookie. we need it to post the upload form.
111
146
  password = ENV['RUBYFORGE_PASSWORD']
112
147
  raise "The RUBYFORGE_PASSWORD environment variable is not set.\n" +
113
148
  "It can be passed on the Rake command line with RUBYFORGE_PASSWORD=<your password>" if password.nil?
114
149
 
115
- response, data = http.post('/account/login.php', "form_loginname=#{@user}&form_pw=#{@password}&login=Login")
116
- cookie = CGI::Cookie.parse(response['set-cookie'])['session_ser']
117
- header = {"Cookie" => "session_ser=#{cookie}"}
150
+ response, data = http.post("/account/login.php", "form_loginname=#{@user}&form_pw=#{password}&login=Login")
151
+ cookie = CGI::Cookie.parse(response['set-cookie'])['session_ser'].to_s
152
+ header = {"Cookie" => cookie, "Host" => "rubyforge.org"}
118
153
 
119
- puts "LOCATION: #{response['location']}"
120
154
  response, data = http.get(response['location'], header)
121
- puts "DATA: #{data}"
122
- puts response.class.name
123
155
 
124
- response, data = http.post_multipart('/frs/admin/qrs.php?group_id=#{@group_id}', @form_data, header)
125
- puts "2 LOCATION: #{response['location']}"
126
- response, data = http.get(response['location'], header)
127
- puts "2 DATA: #{data}"
128
- puts response.class.name
129
- end
130
- end
131
-
132
- private
133
-
134
- def fetch( uri_str, limit = 10 )
135
- # You should choose better exception.
136
- raise ArgumentError, 'HTTP redirect too deep' if limit == 0
156
+ upload_form = "/frs/admin/qrs.php?package=#{package_id}&group_id=#{@group_id}"
157
+ response, data = http.get(upload_form, header)
137
158
 
138
- response, data = Net::HTTP.get_response(URI.parse(uri_str))
139
- case response
140
- when Net::HTTPSuccess then response
141
- when Net::HTTPRedirection then fetch(response['location'], limit - 1)
142
- else
143
- response.error!
159
+ params = []
160
+ @form_data.each do |k, v|
161
+ params << Net::Param.new(k,v)
162
+ end
163
+ params << Net::FileParam.new("userfile", @file, @types[0])
164
+ header["Referer"] = "http://rubyforge.org#{upload_form}"
165
+ response, data = http.post_multipart(upload_form, params, header)
166
+
167
+ File.open("rf.html", "w") { |io|
168
+ io.write data
169
+ }
170
+ # upload_redirect = response['location']
171
+ # response, data = http.get(upload_redirect, header)
144
172
  end
145
173
  end
146
174
 
147
-
148
175
  end
149
176
  end
metadata CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.8.4
3
3
  specification_version: 1
4
4
  name: rscm
5
5
  version: !ruby/object:Gem::Version
6
- version: 0.1.0.999
7
- date: 2005-02-19
6
+ version: 0.1.0.1337
7
+ date: 2005-02-20
8
8
  summary: "RSCM - Ruby Source Control Management"
9
9
  require_paths:
10
10
  - lib