summaryrefslogtreecommitdiff
path: root/panfry/main.py
diff options
context:
space:
mode:
authorScott Bahling <sbahling@mudgum.net>2013-03-17 21:26:02 +0100
committerScott Bahling <sbahling@mudgum.net>2013-03-17 21:26:02 +0100
commitbf0b3f2a096832a9063f7816dcc14a0607f67271 (patch)
treeefff29003b44d8c471587f751740b6f9eac48478 /panfry/main.py
downloadpanfry-bf0b3f2a096832a9063f7816dcc14a0607f67271.tar.gz
panfry-bf0b3f2a096832a9063f7816dcc14a0607f67271.tar.xz
panfry-bf0b3f2a096832a9063f7816dcc14a0607f67271.zip
initial commit
Diffstat (limited to 'panfry/main.py')
-rwxr-xr-xpanfry/main.py46
1 files changed, 46 insertions, 0 deletions
diff --git a/panfry/main.py b/panfry/main.py
new file mode 100755
index 0000000..1a7acf7
--- /dev/null
+++ b/panfry/main.py
@@ -0,0 +1,46 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+import os
+import shutil
+import panfry.cli
+from panfry.templater import Templater
+from panfry.document import Document
+
+
+def get_env():
+ env = panfry.cli.init_argparser().parse_args()
+ if not os.path.isdir(env.src_path):
+ print("%s directory not found. Aborting..." % env.src_path)
+ exit(1)
+
+ env.pub_path = os.path.abspath(env.pub_path)
+
+ if not env.templates_path:
+ env.templates_path = os.path.join(env.src_path, 'templates')
+
+ if not os.path.isdir(env.templates_path):
+ print("No templates path found. Aborting...")
+ exit(1)
+
+ return env
+
+def main():
+ env = get_env()
+ if os.path.exists(env.pub_path):
+ shutil.rmtree(env.pub_path)
+ os.mkdir(env.pub_path)
+
+ document = Document(env.src_path)
+ document.set_templater(Templater(env.templates_path))
+
+ ###### Create PDF
+ pdffile = document.publish_pdf(env.pub_path)
+ print("Wrote PDF: %s" % pdffile)
+
+ ###### Create HTML
+ document.publish_html(env.pub_path)
+
+ exit(0)
+
+if __name__ == "__main__":
+ main()