factor/extra/webapps/mason/mason.factor

185 lines
5.8 KiB
Factor
Raw Normal View History

2009-05-13 20:39:26 -04:00
! Copyright (C) 2009 Slava Pestov.
! See http://factorcode.org/license.txt for BSD license.
USING: accessors arrays combinators db db.tuples furnace.actions
2009-05-21 01:08:43 -04:00
http.server.responses http.server.dispatchers kernel mason.platform
mason.notify.server mason.report math.order sequences sorting
splitting xml.syntax xml.writer io.pathnames io.encodings.utf8
io.files present validators html.forms furnace.db urls ;
FROM: assocs => at keys values ;
2009-05-13 20:39:26 -04:00
IN: webapps.mason
2009-05-21 01:08:43 -04:00
TUPLE: mason-app < dispatcher ;
: link ( url label -- xml )
[XML <a href=<->><-></a> XML] ;
: download-link ( builder label -- xml )
[
2009-05-22 18:48:05 -04:00
[ URL" http://builds.factorcode.org/download" ] dip
[ os>> "os" set-query-param ]
[ cpu>> "cpu" set-query-param ] bi
] dip link ;
: download-grid-cell ( cpu os -- xml )
builder new swap >>os swap >>cpu select-tuple [
dup last-release>> dup
[ "." split1 drop 16 tail* 6 head* download-link ] [ 2drop f ] if
[XML <td class="supported"><div class="bigdiv"><-></div></td> XML]
] [
2009-05-22 18:42:05 -04:00
[XML <td class="doesnotexist" /> XML]
] if* ;
CONSTANT: oses
{
{ "winnt" "Windows" }
{ "macosx" "Mac OS X" }
{ "linux" "Linux" }
{ "freebsd" "FreeBSD" }
{ "netbsd" "NetBSD" }
{ "openbsd" "OpenBSD" }
}
CONSTANT: cpus
{
{ "x86.32" "x86" }
{ "x86.64" "x86-64" }
{ "ppc" "PowerPC" }
}
: download-grid ( -- xml )
oses
[ values [ [XML <th align='center' scope='col'><-></th> XML] ] map ]
[
keys
cpus [
[ nip second ] [ first ] 2bi [
swap download-grid-cell
] curry map
[XML <tr><th align='center' scope='row'><-></th><-></tr> XML]
] with map
] bi
2009-05-22 18:42:05 -04:00
[XML
<table id="downloads" cellspacing="0">
<tr><th class="nobg">OS/CPU</th><-></tr>
<->
</table>
XML] ;
: <download-grid-action> ( -- action )
<action>
[ download-grid xml>string "text/html" <content> ] >>display ;
2009-05-21 01:08:43 -04:00
: validate-os/cpu ( -- )
{
{ "os" [ v-one-line ] }
{ "cpu" [ v-one-line ] }
} validate-params ;
: current-builder ( -- builder )
builder new "os" value >>os "cpu" value >>cpu select-tuple ;
: <build-report-action> ( -- action )
<action>
[ validate-os/cpu ] >>init
[ current-builder last-report>> "text/html" <content> ] >>display ;
2009-05-13 20:39:26 -04:00
: building ( builder string -- xml )
swap current-git-id>> git-link
[XML <-> for <-> XML] ;
: status-string ( builder -- string )
dup status>> {
{ +dirty+ [ drop "Dirty" ] }
{ +clean+ [ drop "Clean" ] }
{ +error+ [ drop "Error" ] }
{ +starting+ [ "Starting build" building ] }
{ +make-vm+ [ "Compiling VM" building ] }
{ +boot+ [ "Bootstrapping" building ] }
{ +test+ [ "Testing" building ] }
[ 2drop "Unknown" ]
} case ;
2009-05-13 20:39:26 -04:00
: current-status ( builder -- xml )
[ status-string ]
[ current-timestamp>> present " (as of " ")" surround ] bi
2array ;
2009-05-13 20:39:26 -04:00
2009-05-21 01:08:43 -04:00
: build-status ( git-id timestamp -- xml )
over [ [ git-link ] [ present ] bi* " (built on " ")" surround 2array ] [ 2drop f ] if ;
: binaries-url ( builder -- url )
[ os>> ] [ cpu>> ] bi (platform) "http://downloads.factorcode.org/" prepend ;
: latest-binary-link ( builder -- xml )
[ binaries-url ] [ last-release>> ] bi [ "/" glue ] keep link ;
2009-05-21 01:08:43 -04:00
: binaries-link ( builder -- link )
binaries-url dup link ;
2009-05-21 01:08:43 -04:00
: clean-image-url ( builder -- url )
[ os>> ] [ cpu>> ] bi (platform) "http://factorcode.org/images/clean/" prepend ;
2009-05-13 20:39:26 -04:00
: clean-image-link ( builder -- link )
clean-image-url dup link ;
2009-05-21 01:08:43 -04:00
: report-link ( builder -- xml )
[ URL" report" ] dip
[ os>> "os" set-query-param ]
[ cpu>> "cpu" set-query-param ] bi
[XML <a href=<->>Latest build report</a> XML] ;
2009-05-13 20:39:26 -04:00
2009-05-21 01:08:43 -04:00
: requirements ( builder -- xml )
[
os>> {
2009-09-25 19:27:52 -04:00
{ "winnt" "Windows XP, Windows Vista or Windows 7" }
2009-05-21 01:08:43 -04:00
{ "macosx" "Mac OS X 10.5 Leopard" }
2009-05-22 18:48:05 -04:00
{ "linux" "Ubuntu Linux 9.04 (other distributions may also work)" }
2009-09-25 19:27:52 -04:00
{ "freebsd" "FreeBSD 7.1" }
2009-09-25 17:07:20 -04:00
{ "netbsd" "NetBSD 5.0" }
2009-05-22 18:48:05 -04:00
{ "openbsd" "OpenBSD 4.4" }
2009-05-21 01:08:43 -04:00
} at
] [
dup cpu>> "x86.32" = [
2009-05-21 01:08:43 -04:00
os>> {
2009-09-25 17:07:20 -04:00
{ [ dup { "winnt" "linux" "freebsd" "netbsd" } member? ] [ drop "Intel Pentium 4, Core Duo, or other x86 chip with SSE2 support. Note that 32-bit Athlon XP processors do not support SSE2." ] }
2009-09-25 19:27:52 -04:00
{ [ dup { "openbsd" } member? ] [ drop "Intel Pentium Pro or better" ] }
2009-05-21 01:08:43 -04:00
{ [ t ] [ drop f ] }
} cond
] [ drop f ] if
] bi
2array sift [ [XML <li><-></li> XML] ] map [XML <ul><-></ul> XML] ;
: last-build-status ( builder -- xml )
[ last-git-id>> ] [ last-timestamp>> ] bi build-status ;
: clean-build-status ( builder -- xml )
[ clean-git-id>> ] [ clean-timestamp>> ] bi build-status ;
2009-05-21 01:08:43 -04:00
: <download-binary-action> ( -- action )
<page-action>
[
validate-os/cpu
"os" value "cpu" value (platform) "platform" set-value
current-builder {
[ latest-binary-link "package" set-value ]
[ release-git-id>> git-link "git-id" set-value ]
[ requirements "requirements" set-value ]
[ host-name>> "host-name" set-value ]
[ current-status "status" set-value ]
[ last-build-status "last-build" set-value ]
[ clean-build-status "last-clean-build" set-value ]
[ binaries-link "binaries" set-value ]
[ clean-image-link "clean-images" set-value ]
[ report-link "last-report" set-value ]
} cleave
2009-05-21 01:08:43 -04:00
] >>init
{ mason-app "download" } >>template ;
: <mason-app> ( -- dispatcher )
mason-app new-dispatcher
<build-report-action> "report" add-responder
<download-binary-action> "download" add-responder
<download-grid-action> "grid" add-responder
2009-05-21 01:08:43 -04:00
mason-db <db-persistence> ;