Christian Williams & Phil Goodwin | 7ce366c | 2010-11-03 10:31:04 -0700 | [diff] [blame] | 1 | #!/usr/bin/env ruby |
| 2 | |
| 3 | DOWNLOADS_FILE = 'pages/download.html.md' |
| 4 | |
| 5 | def need_pages_submodule |
| 6 | unless File.exists?(DOWNLOADS_FILE) |
Phil Goodwin | ec5935c | 2010-11-05 16:39:47 -0700 | [diff] [blame^] | 7 | raise "Robolectric pages submodule isn't present. Run git submodule update --init" |
Christian Williams & Phil Goodwin | 7ce366c | 2010-11-03 10:31:04 -0700 | [diff] [blame] | 8 | end |
| 9 | end |
| 10 | |
Christian Williams & Phil Goodwin | 7ce366c | 2010-11-03 10:31:04 -0700 | [diff] [blame] | 11 | def 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 Goodwin | d9b4b5f | 2010-11-05 15:13:27 -0700 | [diff] [blame] | 19 | match = /robolectric(-all)?-([0-9].*)?.jar/.match(f) |
Christian Williams & Phil Goodwin | 7ce366c | 2010-11-03 10:31:04 -0700 | [diff] [blame] | 20 | version = "SNAPSHOT" |
Phil Goodwin | d9b4b5f | 2010-11-05 15:13:27 -0700 | [diff] [blame] | 21 | version = match[2] if match |
Christian Williams & Phil Goodwin | 7ce366c | 2010-11-03 10:31:04 -0700 | [diff] [blame] | 22 | 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" |
| 38 | end |
| 39 | |
| 40 | fill_index_downloads |