Class: ICli::Gforge

Inherits:
AbstractHost show all
Includes:
FileUtils
Defined in:
lib/proutils/icli/gforge.rb

Overview

This is the base class for all GForge adapters. With any luck this will do for just about everything.

* release  - Upload release packages.
* publish  - Upload site files.
* announce - Post news announcement.

Direct Known Subclasses

Rubyforge

Constant Summary collapse

REPORT =

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

/<h\d><span style="color:red">(.*?)<\/span><\/h\d>/

Instance Attribute Summary collapse

Attributes inherited from AbstractHost

#uri

Instance Method Summary collapse

Methods inherited from AbstractHost

#domain

Constructor Details

#initialize(options) ⇒ Gforge

New RubyForge tasks.



27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/proutils/icli/gforge.rb', line 27

def initialize(options)
  options = super

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

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

  load_project
end

Instance Attribute Details

#group_idObject

Project’s group id number.



46
47
48
# File 'lib/proutils/icli/gforge.rb', line 46

def group_id
  @group_id
end

#projectObject

Project name.



43
44
45
# File 'lib/proutils/icli/gforge.rb', line 43

def project
  @project
end

#usernameObject

Username to use for project account.



49
50
51
# File 'lib/proutils/icli/gforge.rb', line 49

def username
  @username
end

Instance Method Details

#commandsObject

What commands does this host support.



22
23
24
# File 'lib/proutils/icli/gforge.rb', line 22

def commands
  %w{ touch release publish post }
end

#loginObject

Login to website.



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/proutils/icli/gforge.rb', line 53

def  # :yield:
  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)

  unless html[/Personal Page/]
    puts "Login failed."
    re1 = Regexp.escape(%{<h2 style="color:red">})
    re2 = Regexp.escape(%{</h2>})
    html[/#{re1}(.*?)#{re2}/]
    raise $1
  end

  if block_given?
    begin
      yield
    ensure
      logout
    end
  end
end

#logoutObject

Logout of website.



85
86
87
88
89
# File 'lib/proutils/icli/gforge.rb', line 85

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

#post(options) ⇒ Object

Submit a news item.



247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
# File 'lib/proutils/icli/gforge.rb', line 247

def post(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 "\nSUBJECT: #{subject}"
    puts "\n#{message}\n\n"
  else
    post_news(subject, message)
    puts "News item posted!"
  end
end

#publish(options) ⇒ Object

Publish document to website.



230
231
232
233
234
235
236
237
238
239
240
241
242
243
# File 'lib/proutils/icli/gforge.rb', line 230

def publish(options)
  options = options.rekey

  #domain = options[:domain] || DOMAIN
  root   = File.join(siteroot, project)
  root   = File.join(root, options[:root]) if options[:root]

  options.update(
    :host => domain,
    :root => root
  )

  UploadUtils.rsync(options)
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)
project        Project name on host (defaults to name)
package        Package to which this release belongs (default 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)


130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
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
# File 'lib/proutils/icli/gforge.rb', line 130

def release(options)
  options = options.rekey

  version   = options[:version]
  project   = options[:project]   || @project
  package   = options[:package]   || project
  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'
  changelog = options[:changelog]
  notelog   = options[:notelog]

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

  raise ArgumentError, "missing group_id" unless group_id
  raise ArgumentError, "missing project"  unless project
  raise ArgumentError, "missing package"  unless package
  raise ArgumentError, "missing release"  unless release

  if files.empty?
    files = Dir.glob(File.join(store,"#{name}-#{version}*"))
  end

  files = files.reject{ |f| File.directory?(f) }

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

  files.each do |file|
    abort "Not a file -- #{file}" unless File.exist?(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

    unless package_id = package?(package)
      #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}..."
      abort "Cannot continue in dry-run mode." if dryrun?
      create_package(package, is_public)
      unless package_id = package?(package)
        raise "Package creation failed."
      end
    end
    if release_id = release?(release, package_id)
      #unless options[:force]
        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)
          puts "Removing file #{fname}..."
          remove_file(file_id, release_id, package_id) unless dryrun?
        end
        puts "Adding file #{fname}..."
        add_file(file, release_id, package_id, processor) unless dryrun?
      end
    else
      puts "Adding release #{release}..."
      unless dryrun?
        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!"
end

#touch(options = {}) ⇒ Object

Touch base with server – login and logout.



93
94
95
96
97
98
# File 'lib/proutils/icli/gforge.rb', line 93

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