ee62f412c6ef

Modified main execution

Checking for arguments has been moved to the executable and render_files takes
the source and destination as arguments. These default to '.' and './build' for
the d executable.

Moving argument checking to the executable and passing source and destination into
d.render_files allows custom executables, like the included 'bin/da' example.
[view raw] [browse files]
author Mattijs Hoitink <mattijs@monkeyandmachine.com>
date Mon, 06 Feb 2012 15:45:14 +0100
parents 54c639244dda
children 95130cb61163
branches/tags (none)
files bin/d bin/da d/base.py

Changes

--- a/bin/d	Mon Feb 06 15:24:53 2012 +0100
+++ b/bin/d	Mon Feb 06 15:45:14 2012 +0100
@@ -4,10 +4,15 @@
 
 # Ugly hack so I can code in peace.
 try:
-    from d.base import main
+    from d.base import render_files
 except ImportError:
     sys.path.append(os.path.abspath(os.path.join(__file__, '..', '..')))
-    from d.base import main
+    from d.base import render_files
 
 if __name__ == '__main__':
-    main()
+    if len(sys.argv) > 1:
+        sys.stderr.write("d doesn't take any arguments.\n")
+        sys.stderr.write("Just cd into your docs/ directory, run d, and move on.\n")
+        sys.exit(1)
+    else:
+        render_files('.', './build')
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/bin/da	Mon Feb 06 15:45:14 2012 +0100
@@ -0,0 +1,17 @@
+#!/usr/bin/env python
+
+import sys, os
+
+# Ugly hack so I can code in peace.
+try:
+    from d.base import render_files
+except ImportError:
+    sys.path.append(os.path.abspath(os.path.join(__file__, '..', '..')))
+    from d.base import render_files
+
+if __name__ == '__main__':
+    if len(sys.argv) < 3:
+        sys.stderr.write("da requires 2 arguments: da SOURCE DESTINATION\n")
+        sys.exit(1)
+    else:
+        render_files(sys.argv[1], sys.argv[2])
--- a/d/base.py	Mon Feb 06 15:24:53 2012 +0100
+++ b/d/base.py	Mon Feb 06 15:45:14 2012 +0100
@@ -232,7 +232,10 @@
     return _render(title, footer, path, target, 'index', toc)
 
 
-def render_files():
+def render_files(source, destination):
+    SOURCE_LOC = source
+    BUILD_LOC = destination
+
     _ensure_dir(BUILD_LOC)
     _ensure_dir(j(BUILD_LOC, '_dmedia'))
 
@@ -247,12 +250,3 @@
         chapters.append((filename, chapter_title))
 
     render_index(title, footer, chapters)
-
-
-def main():
-    if len(sys.argv) > 1:
-        sys.stderr.write("d doesn't take any arguments.\n")
-        sys.stderr.write("Just cd into your docs/ directory, run d, and move on.\n")
-        sys.exit(1)
-    else:
-        render_files()