Skip to content

Commit

Permalink
Require --config option on command-line. Add --wiki-root option and d…
Browse files Browse the repository at this point in the history
…erive dirs from it. Rename git-repository-root to git-main-repository-root.
  • Loading branch information
cgay committed Dec 24, 2012
1 parent 2443dfc commit c2717a8
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 42 deletions.
4 changes: 2 additions & 2 deletions README.rst
Expand Up @@ -21,15 +21,15 @@ Configuration

You will need to tweak these values in the config file:

* **koala.wiki.git-repository-root** -- Make it point to the root
* **koala.wiki.git-main-repository-root** -- Make it point to the root
directory of your wiki git repository. Example::

$ cd
$ mkdir wiki-data
$ cd wiki-data
$ git init

<wiki git-repository-root = "/home/you/wiki-data" ...>
<wiki git-main-repository-root = "/home/you/wiki-data" ...>

* **koala.wiki.git-user-repository-root** -- Make this point to the
root directory of the user data repository. This is separate from
Expand Down
8 changes: 4 additions & 4 deletions config.xml
Expand Up @@ -26,7 +26,7 @@
Directory where the wiki should look for its static files.
This should point to the wiki project directory; the one
containing the www, dylan, and dsp subdirectories.
git-repository-root (required)
git-main-repository-root (required)
Full path of main git repository. This is where wiki page
and group data is stored.
git-user-repository-root (required)
Expand All @@ -45,9 +45,9 @@
<wiki site-name="Wiki"
site-url="http://localhost"
url-prefix="/wiki"
static-directory="/wiki-source-dir/www"
git-repository-root="/wiki-main-data"
git-user-repository-root="/wiki-user-data"
wiki-root=".../dylan/src/wiki"
git-main-repository-root=".../wiki/main-data"
git-user-repository-root=".../wiki/user-data"
git-executable="/usr/bin/git"
python-executable="/usr/bin/python"
rst2html="/usr/bin/rst2html"
Expand Down
14 changes: 7 additions & 7 deletions dylan/git-storage.dylan
Expand Up @@ -51,7 +51,7 @@ define variable *groups-directory* :: false-or(<directory-locator>) = #f;
define class <git-storage> (<storage>)

// The root directory of the wiki data repository, as a string.
constant slot git-repository-root :: <directory-locator>,
constant slot git-main-repository-root :: <directory-locator>,
required-init-keyword: repository-root:;

// User data is stored in a separate repository so that it can
Expand Down Expand Up @@ -90,7 +90,7 @@ end;
///
define method initialize-storage-for-reads
(storage :: <git-storage>) => ()
ensure-directories-exist(storage.git-repository-root);
ensure-directories-exist(storage.git-main-repository-root);
ensure-directories-exist(storage.git-user-repository-root);

// It is supposed to be safe to call "git init" on an already
Expand All @@ -100,11 +100,11 @@ define method initialize-storage-for-reads
call-git(storage, "init", working-directory: storage.git-user-repository-root);

*pages-directory*
:= subdirectory-locator(storage.git-repository-root, $pages-directory-name);
:= subdirectory-locator(storage.git-main-repository-root, $pages-directory-name);
*users-directory*
:= subdirectory-locator(storage.git-user-repository-root, $users-directory-name);
*groups-directory*
:= subdirectory-locator(storage.git-repository-root, $groups-directory-name);
:= subdirectory-locator(storage.git-main-repository-root, $groups-directory-name);

ensure-directories-exist(*pages-directory*);
ensure-directories-exist(subdirectory-locator(*pages-directory*,
Expand Down Expand Up @@ -175,7 +175,7 @@ define method load-all
(storage :: <storage>, class == <wiki-page>)
=> (pages :: <sequence>)
log-info("Loading all pages from storage (%s)...",
as(<string>, storage.git-repository-root));
as(<string>, storage.git-main-repository-root));
let pages :: <stretchy-vector> = make(<stretchy-vector>);
local method load-page (page-directory :: <directory-locator>)
let title = git-decode-title(locator-name(page-directory));
Expand Down Expand Up @@ -629,7 +629,7 @@ define function call-git
iff(format-args,
apply(sformat, command-fmt, format-args),
command-fmt));
let cwd = working-directory | storage.git-repository-root;
let cwd = working-directory | storage.git-main-repository-root;

if (debug?)
log-debug("Running command in cwd = %s: %s", as(<string>, cwd), command);
Expand Down Expand Up @@ -807,7 +807,7 @@ define function git-commit
#key extra-path :: false-or(<string>))
=> (revision :: <string>)
%git-commit(storage, path, author, comment, meta-data,
storage.git-repository-root,
storage.git-main-repository-root,
extra-path)
end;

Expand Down
33 changes: 14 additions & 19 deletions dylan/main.dylan
Expand Up @@ -16,11 +16,15 @@ define constant $administrator-user-name :: <string> = "administrator";
/// processed.
define sideways method process-config-element
(server :: <http-server>, node :: xml/<element>, name == #"wiki")

// TODO(cgay): error out if any of the files configured here don't exist,
// including executables.
let git-exe = get-attr(node, #"git-executable")
| "git";
let main-root = get-attr(node, #"git-repository-root")
| error("The git-repository-root setting is required.");
let wiki-root = get-attr(node, #"wiki-root")
| error("The wiki-root setting is required.");
let wiki-root-directory = as(<directory-locator>, wiki-root);
let main-root = get-attr(node, #"git-main-repository-root")
| error("The git-main-repository-root setting is required.");
let user-root = get-attr(node, #"git-user-repository-root")
| error("The git-user-repository-root setting is required.");
*storage* := make(<git-storage>,
Expand Down Expand Up @@ -62,9 +66,7 @@ define sideways method process-config-element
*wiki-url-prefix* := get-attr(node, #"url-prefix") | *wiki-url-prefix*;
log-info("Wiki URL prefix: %s", *wiki-url-prefix*);

*static-directory*
:= as(<directory-locator>,
get-attr(node, #"static-directory") | *static-directory*);
*static-directory* := subdirectory-locator(wiki-root-directory, "www");
*template-directory* := subdirectory-locator(*static-directory*, "dsp");
log-info("Wiki static directory: %s", *static-directory*);

Expand All @@ -86,9 +88,9 @@ define sideways method process-config-element
*rst2html* := get-attr(node, #"rst2html")
| error("The 'rst2html' attribute must be specified in the 'wiki' "
"config file element.");
*rst2html-template* := get-attr(node, #"rst2html-template")
| error("The 'rst2html-template' attribute must be specified in the 'wiki' "
"config file element.");
*rst2html-template* := as(<string>,
merge-locators(as(<file-locator>, "rst2html-template.txt"),
wiki-root-directory));
end method process-config-element;

define method process-administrator-configuration
Expand Down Expand Up @@ -344,18 +346,11 @@ define function add-wiki-responders

end function add-wiki-responders;

// --static-directory <dir>
add-option(*command-line-parser*,
make(<parameter-option>,
names: #("static-directory"),
help: "Directory containing wiki static files"));

// Called after config file loaded.
define function initialize-wiki
(server :: <http-server>)
let directory = get-option-value(*command-line-parser*, "static-directory");
if (directory)
*static-directory* := as(<directory-locator>, directory);
*template-directory* := subdirectory-locator(*static-directory*, "dsp");
if (~get-option-value(*command-line-parser*, "config"))
error("You must specify a config file with the --config option.");
end;
add-wiki-responders(server);
preload-wiki-data();
Expand Down
13 changes: 3 additions & 10 deletions dylan/wiki.dylan
Expand Up @@ -11,16 +11,9 @@ define taglib wiki () end;
define class <wiki-dsp> (<dylan-server-page>)
end;


// These two variables should reflect the layout of the subdirectories
// in the wiki project directory. The default values are setup to work
// if you cd to wiki/ and run the wiki executable.

define variable *static-directory* :: <directory-locator>
= subdirectory-locator(working-directory(), "www");

define variable *template-directory* :: <directory-locator>
= subdirectory-locator(*static-directory*, "dsp");
// These are both set to something else when the config file is loaded.
define variable *static-directory* :: <directory-locator> = working-directory();
define variable *template-directory* :: <directory-locator> = working-directory();


define method make
Expand Down

0 comments on commit c2717a8

Please sign in to comment.