Permalink
Browse files

Changing template package to allow mdepub to be run from a Zip file.

  • Loading branch information...
1 parent b9d2bc3 commit a1c6dc7744e396fcf91ee61cd971ee5bf3362f97 @bkidwell committed Jan 29, 2012
Showing with 12 additions and 6 deletions.
  1. +6 −4 mdepub/actions/create.py
  2. +6 −2 mdepub/template/__init__.py
@@ -8,9 +8,9 @@
import sys
import shutil
import mdepub
+from mdepub import template
from mdepub.filename import clean
from mdepub.filename import getFN
-from mdepub.template import template_path
log = logging.getLogger('create')
@@ -39,15 +39,17 @@ def run():
log.fatal("An mdepub project file already exists in this path.")
sys.exit(1)
- shutil.copyfile(join(template_path, "book.css"), "{}.css".format(filename))
+ css_content = template.get_file_content("book.css")
+ with open("{}.css".format(filename), 'w') as f:
+ f.write(css_content)
- with open(join(template_path, "book.md"), 'r') as f: txt = f.read()
+ txt = template.get_file_content("book.md")
with open("{}.md".format(filename), 'w') as f:
f.write(
txt.format(Title=title, Author=author)
)
- with open(join(template_path, "options.yaml"), 'r') as f: txt = f.read()
+ txt = template.get_file_content("options.yaml")
with open("options.yaml", 'w') as f:
f.write(
txt.format(Title=title, Author=author, Date=today, uuid=uuid)
@@ -1,5 +1,9 @@
"""Module containing template files for creating a new project."""
-import os.path
+import pkgutil
+import sys
-template_path = os.path.dirname(__file__)
+def get_file_content(filename):
+ """Get contents of file named by filename, in template package."""
+
+ return pkgutil.get_data(__name__, filename)

0 comments on commit a1c6dc7

Please sign in to comment.