Commits

Anonymous committed cb90692

Setup the hgweb.cgi script in a /tmp/ehttp dir.

  • Participants
  • Parent commits cbea43e

Comments (0)

Files changed (1)

File src/ehttp.erl

 %%% @copyright (C) 2010, Torbjorn Tornkvist
 %%% @doc Repository browser.
 %%%
+%%% Browsing a hg repo with ehttp is pointless when there is 'hg serv'.
+%%% This code is just a reason for playing around with the inets/httpd.
+%%%
 %%% @end
 %%%-------------------------------------------------------------------
 -module(ehttp).
 inets_start() ->
     inets:start(),
     {ok, CWD} = file:get_cwd(),
+    Hgweb_cgi_path = setup_hgweb_cgi(CWD, "ehttp"),
     {ok, Pid} = 
         inets:start(httpd, 
                     [{port, ?DEFAULT_PORT},
                      {server_root, CWD},
                      {document_root, CWD},
                      {alias, {"/icons", inets_icons_dir()}},
-                     {script_alias, {"/hgweb.cgi", CWD++"/hgweb.cgi"}},
+                     {script_alias, {"/hgweb.cgi", Hgweb_cgi_path}},
                      {modules, [?MODULE, mod_cgi, mod_alias, 
                                 mod_dir, mod_get, mod_head]}
-%                     {mime_types, [{"css", "text/css"}, 
-%                                   {"js", "text/javascript"}, 
-%                                   {"html", "text/html"}]}
                     ]),
     link(Pid),
     {ok, Pid}.
 
 i2l(I) when is_integer(I) -> integer_to_list(I).
 
+setup_hgweb_cgi(Root, Name) ->
+    TmpDir = "/tmp/ehttp",
+    os:cmd("mkdir -p "++TmpDir),
+    Hgweb_cgi_path = TmpDir++"/hgweb.cgi",
+    file:write_file(Hgweb_cgi_path,
+                    list_to_binary(hgweb_cgi(Root, Name))),
+    os:cmd("chmod +x "++Hgweb_cgi_path),
+    Hgweb_cgi_path.
     
+hgweb_cgi(Root, Name) ->
+    ["#!/usr/bin/env python\n"
+     "from mercurial import demandimport; demandimport.enable()\n"
+     "from mercurial.hgweb.hgweb_mod import hgweb\n"
+     "import mercurial.hgweb.wsgicgi as wsgicgi\n"
+     "application = hgweb(\"",Root,"\", \"",Name,"\")\n"
+     "wsgicgi.launch(application)\n"].
+
+
+
+