diff options
| author | hallgren <hallgren@chalmers.se> | 2010-12-17 16:29:22 +0000 |
|---|---|---|
| committer | hallgren <hallgren@chalmers.se> | 2010-12-17 16:29:22 +0000 |
| commit | c51d1f983383763355410fb05732b6632f05117b (patch) | |
| tree | 1e47ad7848a379a666e662d5555462a918dde3cb /src/server/Setup.hs | |
| parent | 71e0ec4d417dab88a7abf33dd23d7197c453450d (diff) | |
Install minibar and some example grammars along with pgf-http
Together with the changes to pgf-http, this should make it much easier to run
the PGF service and minibar locally.
Diffstat (limited to 'src/server/Setup.hs')
| -rw-r--r-- | src/server/Setup.hs | 87 |
1 files changed, 85 insertions, 2 deletions
diff --git a/src/server/Setup.hs b/src/server/Setup.hs index c46cb0330..290fa3b8b 100644 --- a/src/server/Setup.hs +++ b/src/server/Setup.hs @@ -1,6 +1,89 @@ -module Main where +{-# OPTIONS_GHC -fwarn-unused-imports #-} + +import Control.Monad(when) +import System.Directory(createDirectoryIfMissing,doesFileExist, + getDirectoryContents,copyFile,removeFile) +import System.FilePath((</>)) +import System.Cmd(system) +import System.Exit(ExitCode(..)) import Distribution.Simple +import Distribution.Simple.Setup +import Distribution.Simple.LocalBuildInfo(datadir,buildDir,absoluteInstallDirs) main :: IO () -main = defaultMainWithHooks simpleUserHooks +main = defaultMainWithHooks simpleUserHooks{ postInst = instWWW + , postCopy = copyWWW + } +-------------------------------------------------------------------------------- +-- To test the GF web service and minibar, use "cabal install" (or +-- "runhaskell Setup.hs install") to install the program pgf-http, the +-- example grammars listed below, and the minibar. Then start the server with +-- the command "pgf-http" and open http://localhost:41296/minibar/minibar.html +-- in your web browser (Firefox, Safari, Opera or Chrome). + +example_grammars = + -- (pgf, tmp, src) + [("Foods.pgf","foods", + ".."</>".."</>"contrib"</>"summerschool"</>"foods"</>"Foods???.gf"), + ("Letter.pgf","letter", + ".."</>".."</>"examples"</>"letter"</>"Letter???.gf")] + +minibar_src = ".."</>"runtime"</>"javascript"</>"minibar" + +-------------------------------------------------------------------------------- +instWWW args flags pki lbi = setupWWW args dest pki lbi + where + dest = NoCopyDest + +copyWWW args flags pki lbi = setupWWW args dest pki lbi + where + dest = case copyDest flags of + NoFlag -> NoCopyDest + Flag d -> d + +setupWWW args dest pkg lbi = + do mapM_ (createDirectoryIfMissing True) [grammars_dir,minibar_dir] + mapM_ build_pgf example_grammars + copy_minibar + create_root_index + where + grammars_dir = www_dir </> "grammars" + minibar_dir = www_dir </> "minibar" + www_dir = datadir (absoluteInstallDirs pkg lbi dest) </> "www" + gfo_dir = buildDir lbi </> "gfo" + + build_pgf (pgf,tmp,src) = + do createDirectoryIfMissing True tmp_dir + execute cmd + copyFile pgf (grammars_dir</>pgf) + removeFile pgf + where + tmp_dir = gfo_dir</>tmp + cmd = "gf -make -s -optimize-pgf --gfo-dir="++tmp_dir++ + -- " --output-dir="++grammars_dir++ -- has no effect?! + " "++src + + copy_minibar = + do files <- getDirectoryContents minibar_src + mapM_ copy files + where + copy file = + do isFile <- doesFileExist src + when isFile $ copyFile src (minibar_dir</>file) + where + src = minibar_src</>file + + create_root_index = writeFile (www_dir</>"index.html") index_html + + index_html = "<h2>Available demos</h2>\n" + ++"<ul><li><a href=\"minibar/minibar.html\">Minibar</a></ul>" + ++"Additional grammars can be installed in" + ++"<blockquote><code>"++grammars_dir++"</code></blockquote>" +execute command = + do putStrLn command + e <- system command + case e of + ExitSuccess -> return () + _ -> fail "Command failed" + return () |
