source: trunk/dports/ruby/rb-gnome/files/port-upd-rb-gnome.rb @ 54809

Last change on this file since 54809 was 54809, checked in by kimuraw@…, 11 years ago

ruby/rb-gnome: add README for this port and maintenance script

  • Property svn:executable set to *
  • Property svn:keywords set to Id
File size: 2.7 KB
Line 
1#!/usr/bin/env ruby
2# $Id: port-upd-rb-gnome.rb 54809 2009-08-02 12:03:11Z kimuraw@macports.org $
3# upgrade all Portfiles of Ruby-GNOME2 modules; rb-glib2, rb-gtk2, ..
4# [usage] port-upd-rb-gnome.rb tarball-path
5#
6
7require 'openssl'
8
9# target Portfiles of Ruby/Gnome2 modules
10PORTFILES =
11        %w[rb-glib2 rb-atk rb-pango rb-gtk2 rb-rsvg rb-poppler
12           rb-gconf rb-gnomecanvas rb-libgnome rb-libart rb-gnomeprint
13           rb-gnomeprintui rb-gnomevfs rb-gtkhtml rb-libglade2
14           rb-gstreamer rb-vte rb-gtkglext rb-gtksourceview2
15           rb-gnome]
16# TODO: GtkMozeEmbed[add]
17
18class App
19
20  attr_accessor :version, :sums
21
22  def initialize(version, tarball)
23    self.version = version
24    self.sums = checksums(tarball)
25    puts <<EOS
26######
27input file: #{tarball}
28ruby-gnome: #{self.version}
29checksums md5: #{self.sums.md5}
30          sha1: #{self.sums.sha1}
31          rmd160: #{self.sums.rmd160}
32######
33EOS
34  end
35
36  def run
37    PORTFILES.each do |port|
38      update(port)
39      puts "update #{port}"
40    end
41  end
42
43  Checksums = Struct.new(:md5, :sha1, :rmd160)
44
45  private
46
47  def checksums(path)
48    bytes = File.read(path)
49    sums = Checksums.new
50    sums.md5 = OpenSSL::Digest::MD5.new(bytes).hexdigest
51    sums.sha1 = OpenSSL::Digest::SHA1.new(bytes).hexdigest
52    sums.rmd160 = OpenSSL::Digest::RIPEMD160.new(bytes).hexdigest
53    return sums
54  end
55
56  def update(port)
57    path = File.join('ruby', port, 'Portfile')
58    text = File.read(path)
59    # update version at ruby.setup
60    text[/ruby.setup\s+\{.*\}\s+(\S+)\s+(extconf\.rb|fetch)/m, 1] = self.version
61    # update checksums {md5/sha1/rmd160}
62    self.sums.each_pair do |type, sum|
63      text[/\s+#{type}\s+([0-9a-f]+)/, 1] = sum
64    end
65
66    ## add fetch from svn trunk
67    svn_tag = self.version[/\.r(\d+)/, 1]
68    if svn_tag
69      update_svn(text, svn_tag)
70    else
71      remove_svn_cmds(text)
72    end
73    File.open(path, 'w') {|f| f.write(text)}
74  end
75
76  FETCH_RE = /^(fetch\s+\{.*\}\s*\n)/m
77  WORKSRCDIR_RE = /^worksrcdir\s+(\S+)\n/m
78
79  def update_svn(text, svn_tag)
80    fetch_cmd = <<FETCH_CMD
81fetch {
82  if {[file isfile \${distpath}/\${distname}\${extract.suffix}]} {return 0}
83  curl fetch "http://ruby-gnome2.svn.sourceforge.net/viewvc/ruby-gnome2/ruby-gnome2/trunk.tar.gz?view=tar&pathrev=#{svn_tag}" \${distpath}/\${distname}\${extract.suffix}
84}
85FETCH_CMD
86    begin
87      text[FETCH_RE, 1] = fetch_cmd
88    rescue IndexError
89      text << fetch_cmd
90    end
91    worksrcdir = 'trunk'
92    begin
93      text[WORKSRCDIR_RE, 1] = worksrcdir
94    rescue IndexError
95      text << "worksrcdir #{worksrcdir}\n"
96    end
97  end
98
99  def remove_svn_cmds(text)
100    text.sub!(FETCH_RE, '')
101    text.sub!(WORKSRCDIR_RE, '')
102  end
103end
104
105if ARGV.size != 1
106  $stderr.puts "[usage] port-upd-rb-gnome.rb tarball-file"
107  exit 1
108end
109
110tarball = ARGV.shift
111vers = tarball.slice(/ruby-gnome2-(?:all-)?(\S+).tar.gz/, 1)
112
113App.new(vers, tarball).run
114
Note: See TracBrowser for help on using the repository browser.