blob: 37f0442067b38e4c9a513664ffc053cda2d7fd6c [file] [log] [blame]
Christian Williams & Phil Goodwin7ce366c2010-11-03 10:31:04 -07001#!/usr/bin/env ruby
2
3DOWNLOADS_FILE = 'pages/download.html.md'
4
5def need_pages_submodule
6 unless File.exists?(DOWNLOADS_FILE)
Phil Goodwinec5935c2010-11-05 16:39:47 -07007 raise "Robolectric pages submodule isn't present. Run git submodule update --init"
Christian Williams & Phil Goodwin7ce366c2010-11-03 10:31:04 -07008 end
9end
10
Christian Williams & Phil Goodwin7ce366c2010-11-03 10:31:04 -070011def fill_index_downloads
12 require 'digest/sha1'
13
14 download_html = "<!-- START_DOWNLOADS -->\n"
15 Dir.glob('pages/downloads/*.jar').sort.reverse.each do |f|
16 sha1 = Digest::SHA1.hexdigest File.read(f)
17
18 fn = f.sub(/^pages\//, '')
Phil Goodwind9b4b5f2010-11-05 15:13:27 -070019 match = /robolectric(-all)?-([0-9].*)?.jar/.match(f)
Christian Williams & Phil Goodwin7ce366c2010-11-03 10:31:04 -070020 version = "SNAPSHOT"
Phil Goodwind9b4b5f2010-11-05 15:13:27 -070021 version = match[2] if match
Christian Williams & Phil Goodwin7ce366c2010-11-03 10:31:04 -070022 prerelease = /\.rc/.match(f)
23 download_html += prerelease ? "<tr class=\"rc\">\n" : "<tr>\n"
24 download_html += " <td class=\"link\"><a href=\"#{fn}\">#{fn.sub(/downloads\//, '')}</a></td>\n"
25 download_html += " <td class=\"version\">#{version}</td>\n"
26 download_html += " <td class=\"size\">#{File.size(f) / 1024}k</td>\n"
27 download_html += " <td class=\"date\">#{File.mtime(f).strftime("%Y/%m/%d %H:%M:%S %Z")}</td>\n"
28 download_html += " <td class=\"sha\">#{sha1}</td>\n"
29 download_html += "</tr>\n"
30 end
31 download_html += "<!-- END_DOWNLOADS -->"
32
33 downloads_page = File.read(DOWNLOADS_FILE)
34 matcher = /<!-- START_DOWNLOADS -->.*<!-- END_DOWNLOADS -->/m
35 downloads_page = downloads_page.sub(matcher, download_html)
36 File.open(DOWNLOADS_FILE, 'w') {|f| f.write(downloads_page)}
37 puts "rewrote that file"
38end
39
40fill_index_downloads