Class: Reap::Hosts::Rubyforge

Inherits:
Host
  • Object
show all
Defined in:
lib/reap/hosts/rubyforge.rb

Overview

Rubyforge

Interface with the RubyForge hosting service. Supports the following tasks:

  • release - Upload release packages.

  • announce - Post news announcement.

  • touch - Test connection.

TODO: Handle publish tasks to upload website files (currently this is handled separately)

Constant Summary collapse

DOMAIN =

HOME = ENV || ENV || File.expand_path(“~”)

"rubyforge.org"
COOKIEJAR =
File::join(Dir.tmpdir, 'reap', 'cookie.dat')
REPORT =
/<h\d><span style="color:red">(.*?)<\/span><\/h\d>/

Instance Attribute Summary collapse

Attributes inherited from Tool

#project

Instance Method Summary collapse

Methods inherited from Host

#announce_confirm?, factory, inherited, #inspect, register, registry, #release_confirm?

Methods inherited from Tool

#debug?, #dryrun?, #force?, from_project, #metadata, #trace?, #verbose?

Methods included from Utilities

#ask, #bin?, #cd, #command_paths, #compress, #dir!, #dir?, directory!, directory?, #email, exist!, exist?, #exists!, #exists?, #file!, #fileutils, #glob, #list_option, #multiglob, #multiglob_r, #out_of_date?, path!, path?, #read, #rm_r, #safe?, #sh, #stage, #stage_manifest, #status, #write, #ziputils

Constructor Details

#initialize(project, options = {}) ⇒ Rubyforge

New RubyForge object.



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/reap/hosts/rubyforge.rb', line 51

def initialize(project, options={})
  options = options.rekey

  super(project, options)

  @domain   = options[:domain] || DOMAIN
  @uri      = URI.parse("http://" + domain)

  @username = options[:username] || ENV['RUBYFORGE_USERNAME']
  @password = options[:password] || ENV['RUBYFORGE_PASSWORD']
  @unixname = options[:project]  || project..unixname
  @version  = project..version

  @group_id = options[:group] || options[:group_id] || options[:groupid]

  @package_ids = {}
  @release_ids = {}
  @file_ids    = {}

  project.mkdir_p(File.dirname(COOKIEJAR))

  #load_project
end

Instance Attribute Details

#domainObject (readonly)

Returns the value of attribute domain.



47
48
49
# File 'lib/reap/hosts/rubyforge.rb', line 47

def domain
  @domain
end

#group_idObject

Project’s group id number.



101
102
103
# File 'lib/reap/hosts/rubyforge.rb', line 101

def group_id
  @group_id
end

#unixnameObject

Project unixname.



95
96
97
# File 'lib/reap/hosts/rubyforge.rb', line 95

def unixname
  @unixname
end

#uriObject (readonly)

URI = http:// + domain name TODO Deal with https, and possible other protocols too.



41
42
43
# File 'lib/reap/hosts/rubyforge.rb', line 41

def uri
  @uri
end

#usernameObject

Username to use for project account.



45
46
47
# File 'lib/reap/hosts/rubyforge.rb', line 45

def username
  @username
end

#versionObject

Project name.



98
99
100
# File 'lib/reap/hosts/rubyforge.rb', line 98

def version
  @version
end

Instance Method Details

#announce(options) ⇒ Object

Submit a news item.



331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
# File 'lib/reap/hosts/rubyforge.rb', line 331

def announce(options)
  options = options.rekey

  if file = options[:file]
    text = File.read(file).strip
    i = text.index("\n")
    subject = text[0...i].strip
    message = text[i..-1].strip
  else
    subject = options[:subject]
    message = options[:message] || options[:body]
  end

  if dryrun?
    puts "announce-rubyforge: #{subject}"
  else
    post_news(subject, message)
    puts "News item posted!"
  end
end

#commandsObject

What commands does this host support.



90
91
92
# File 'lib/reap/hosts/rubyforge.rb', line 90

def commands
  %w{ touch release publish post }
end


77
78
79
# File 'lib/reap/hosts/rubyforge.rb', line 77

def cookie_jar
  COOKIEJAR
end

#loginObject

Login to website.



108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
# File 'lib/reap/hosts/rubyforge.rb', line 108

def  # :yield:
  load_project_cached

  page = @uri + "/account/login.php"
  page.scheme = 'https'
  page = URI.parse(page.to_s) # set SSL port correctly

  form = {
    "return_to"      => "",
    "form_loginname" => username,
    "form_pw"        => password,
    "login"          => "Login with SSL"
  }
  html = http_post(page, form)

  if not html[/Personal Page/]
    puts "Login failed."
    re1 = Regexp.escape(%{<h2 style="color:red">})
    re2 = Regexp.escape(%{</h2>})
    html[/#{re1}(.*?)#{re2}/]
    raise $1
  else
    @printed_project_name ||= (puts "Project: #{unixname}"; true)
  end

  if block_given?
    begin
      yield
    ensure
      logout
    end
  end
end

#logoutObject

Logout of website.



144
145
146
147
148
# File 'lib/reap/hosts/rubyforge.rb', line 144

def logout
  page = "/account/logout.php"
  form = {}
  http_post(page, form)
end

#release(options) ⇒ Object

Upload release packages to hosting service.

This task releases files to RubyForge –it should work with other GForge instaces or SourceForge clones too.

While defaults are nice, you may want a little more control. You can specify additional attributes:

files          package files to release.
exclude        Package formats to exclude from files.
               (from those created by pack)
unixname       Project name on host.
package        Package to which this release belongs (defaults to project)
release        Release name (default is version number)
version        Version of release
date           Date of release (defaults to Time.now)
processor      Processor/Architecture (any, i386, PPC, etc.)
is_public      Public release? (defualts to true)
changelog      Change log file
notelog        Release notes file

The release option can be a template by using %s in the string. The version number of your project will be sub’d in for the %s. This saves you from having to update the release name before every release.

– What about releasing a pacman PKGBUILD? ++

Raises:

  • (ArgumentError)


189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
# File 'lib/reap/hosts/rubyforge.rb', line 189

def release(options)
  options = options.rekey

  version   = options[:version]   || .version
  changelog = options[:changelog]
  notelog   = options[:notelog]

  unixname  = options[:unixname]  || unixname()
  package   = options[:package]   || unixname()
  release   = options[:release]   || version()
  name      = options[:name]      || package
  files     = options[:file]      || []
  date      = options[:date]      || Time::now.strftime('%Y-%m-%d %H:%M')
  processor = options[:processor] || 'Any'
  store     = options[:store]     || 'pkg'

  is_public = options[:is_public].nil? ? true : options[:is_public]

  raise ArgumentError, "missing unixname" unless unixname
  raise ArgumentError, "missing package"  unless package
  raise ArgumentError, "missing release"  unless release

  if files.empty?
    files = Dir[File.join(store, '*')].select do |file|
      /#{version}[.]/ =~ file
    end
    #files = Dir.glob(File.join(store,"#{name}-#{version}*"))
  end

  files = files.select{ |f| File.file?(f) }

  abort "No package files." if files.empty?

  files.each do |file|
    abort "Not a file -- #{file}" unless File.exist?(file)
    puts "Release file: #{file}"
  end

  # which package types
  #rtypes = [ 'tgz', 'tbz', 'tar.gz', 'tar.bz2', 'deb', 'gem', 'ebuild', 'zip' ]
  #rtypes -= exclude
  #rtypes = rtypes.collect{ |rt| Regexp.escape( rt ) }
  #re_rtypes = Regexp.new('[.](' << rtypes.join('|') << ')$')

  puts "Releasing #{package} #{release}..." #unless options['quiet']

   do

    raise ArgumentError, "missing group_id" unless group_id

    unless package_id = package?(package)
      if dryrun?
        puts "Package '#{package}' does not exist."
        puts "Create package #{package}."
        abort "Cannot continue in dryrun mode."
      else
        #unless options['force']
        q = "Package '#{package}' does not exist. Create?"
        a = ask(q, 'yN')
        abort "Task canceled." unless ['y', 'yes', 'okay'].include?(a.downcase)
        #end
        puts "Creating package #{package}..."
        create_package(package, is_public)
        unless package_id = package?(package)
          raise "Package creation failed."
        end
      end
    end
    if release_id = release?(release, package_id)
      #unless options[:force]
      if dryrun?
        puts "Release #{release} already exists."
      else
        q = "Release #{release} already exists. Re-release?"
        a = ask(q, 'yN')
        abort "Task canceled." unless ['y', 'yes', 'okay'].include?(a.downcase)
        #puts "Use -f option to force re-release."
        #return
      end
      files.each do |file|
        fname = File.basename(file)
        if file_id = file?(fname, package)
          if dryrun?
            puts "Remove file #{fname}."
          else
            puts "Removing file #{fname}..."
            remove_file(file_id, release_id, package_id)
          end
        end
        if dryrun?
          puts "Add file #{fname}."
        else
          puts "Adding file #{fname}..."
          add_file(file, release_id, package_id, processor)
        end
      end
    else
      if dryrun?
        puts "Add release #{release}."
      else
        puts "Adding release #{release}..."
        add_release(release, package_id, files,
          :processor       => processor,
          :release_date    => date,
          :release_changes => changelog,
          :release_notes   => notelog,
          :preformatted    => '1'
        )
        unless release_id = release?(release, package_id)
          raise "Release creation failed."
        end
      end
      #files.each do |file|
      #  puts "Added file #{File.basename(file)}."
      #end
    end
  end
  puts "Release complete!" unless dryrun?
end

#siterootObject

Website location on server.



84
85
86
# File 'lib/reap/hosts/rubyforge.rb', line 84

def siteroot
  "/var/www/gforge-projects"
end

#touch(options = {}) ⇒ Object

Touch base with server – login and logout.



152
153
154
155
156
157
# File 'lib/reap/hosts/rubyforge.rb', line 152

def touch(options={})
  
  puts "Group ID: #{group_id}"
  puts "Login/Logout successful."
  logout
end