summaryrefslogtreecommitdiff
path: root/panfry
diff options
context:
space:
mode:
Diffstat (limited to 'panfry')
-rwxr-xr-xpanfry/cli.py14
-rwxr-xr-xpanfry/document.py40
-rwxr-xr-xpanfry/main.py20
-rwxr-xr-xpanfry/util.py3
4 files changed, 48 insertions, 29 deletions
diff --git a/panfry/cli.py b/panfry/cli.py
index 9beae43..6045e31 100755
--- a/panfry/cli.py
+++ b/panfry/cli.py
@@ -85,6 +85,18 @@ Args:
default: False
help: 'Do not generate full level table of contents'
+ assets:
+ flags: [--assets]
+ action: store_true
+ default: False
+ help: 'Only copy assets to pub (do not regenerate document)'
+
+ clean:
+ flags: [--clean]
+ action: store_true
+ default: False
+ help: 'Remove pub path and all contents before generating'
+
Parser:
help:
@@ -101,6 +113,8 @@ Subparsers:
- pub_path
- templates_path
- simple_toc
+ - assets
+ - clean
- css
"""
diff --git a/panfry/document.py b/panfry/document.py
index 4379f6e..7bc65c2 100755
--- a/panfry/document.py
+++ b/panfry/document.py
@@ -11,12 +11,13 @@ from panfry.page import TextFile, Page
class Document:
def __init__(self, path):
- self.src_path = path
- self.meta = self.get_meta(path)
- self.pages = self.get_pages(path)
+ self.src_path = os.path.join(path, 'src')
+ self.meta = self.get_meta(self.src_path)
+ self.pages = self.get_pages(self.src_path)
self.full_toc = True
self.css_file = 'css/style.css'
+ self.assets_dir = 'assets'
@property
def set_simple_toc(self):
@@ -74,7 +75,6 @@ class Document:
def get_pages(self, path):
pages = []
filelist = self.toc.lines
- print filelist
for filename in filelist:
print("Reading in %s..." % filename)
if not filename: # blank line in toc
@@ -187,28 +187,21 @@ class Document:
doc = pandoc.Document()
doc.markdown = src
+ print("epub_path: %s" % epub_path)
pandoc.set_cwd(os.path.abspath(self.src_path))
doc.to_file(epub_path)
pandoc.set_cwd(None)
return self.epub_filename
- def publish_css(self, pub_path):
- src = os.path.join(self.src_path, 'css')
- dst = os.path.join(pub_path, 'css')
- if os.path.isdir(src):
- copy(src, dst)
-
- def publish_images(self, pub_path):
- src_path = self.src_path
- if os.path.exists(os.path.join(src_path, 'images/html')):
- src = os.path.join(src_path, 'images/html')
- else:
- src = os.path.join(src_path, 'images')
-
- dst = os.path.join(pub_path, 'images')
- if os.path.exists(src):
- copy(src, dst)
+ def publish_assets(self, pub_path):
+ if not os.path.isdir(self.assets_dir):
+ return
+ for asset in os.listdir(self.assets_dir):
+ src = os.path.join(self.assets_dir, asset)
+ dst = os.path.join(pub_path, asset)
+ if os.path.isdir(src):
+ copy(src, dst)
def publish_html(self, pub_path):
pandoc.set_cwd(None)
@@ -235,8 +228,9 @@ class Document:
if not 'index.md' in self.pages:
src = os.path.join(self.pages[0].htmlfile)
ref = os.path.join(pub_path, 'index.html')
+ if os.path.exists(ref):
+ os.remove(ref)
os.symlink(src, ref)
- ###### Copy any images to publish directory
- self.publish_css(pub_path)
- self.publish_images(pub_path)
+ ###### Copy any assets to publish directory
+ self.publish_assets(pub_path)
diff --git a/panfry/main.py b/panfry/main.py
index e09b653..0b88c0a 100755
--- a/panfry/main.py
+++ b/panfry/main.py
@@ -1,5 +1,6 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
+from __future__ import print_function
import os
import shutil
import panfry.cli
@@ -27,22 +28,31 @@ def get_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))
if env.simple_toc:
document.set_simple_toc
+ if env.clean and os.path.exists(env.pub_path):
+ print("Cleanup, removing %s..." % env.pub_path)
+ shutil.rmtree(env.pub_path)
+ if not os.path.exists(env.pub_path):
+ os.mkdir(env.pub_path)
+
+ if env.assets:
+ print("Publishing assets only...", end=' ')
+ document.publish_assets(env.pub_path)
+ print("done.")
+ exit(0)
+
+
###### Create PDF
pdffile = document.publish_pdf(env.pub_path)
print("Wrote PDF: %s" % pdffile)
###### Create epub
epubfile = document.publish_epub(env.pub_path)
- print("Wrote PDF: %s" % epubfile)
+ print("Wrote epub: %s" % epubfile)
###### Create HTML
document.publish_html(env.pub_path)
diff --git a/panfry/util.py b/panfry/util.py
index 5909eef..c4bab42 100755
--- a/panfry/util.py
+++ b/panfry/util.py
@@ -1,12 +1,13 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import os
+import distutils.dir_util as dir_util
import shutil
def copy(src, dst, ignore=None):
if os.path.isdir(src):
- shutil.copytree(src, dst, True, ignore)
+ dir_util.copy_tree(src, dst)
else:
shutil.copy(src, dst)