Permalink
Browse files

finished 'create' action

  • Loading branch information...
1 parent ed5b26e commit 706e12070008597d4e249a59889403761f5f3327 @bkidwell committed Dec 5, 2011
Showing with 47 additions and 5 deletions.
  1. +1 −1 mdepub/__init__.py
  2. +42 −3 mdepub/actions/create.py
  3. +1 −1 mdepub/actions/newid.py
  4. +3 −0 template/__init__.py
View
@@ -33,7 +33,7 @@ def new_id():
options['filename'] = filename.clean(options['title'])
log.debug("Filename: %s", options['filename'])
else:
- options = yaml.load("")
+ options = yaml.load("dummy: 0")
log.debug("options.yaml not found")
arguments = ArgumentParser().parse_args()
View
@@ -1,12 +1,51 @@
import logging
-import os.path
import mdepub
-from mdepub import project_path
+from mdepub import options
from mdepub.filename import getFN
+from mdepub.filename import clean
+import os
+from datetime import date
+import sys
+import shutil
+from os.path import join, dirname, exists
+from template import template_path
+import re
log = logging.getLogger('create')
def run():
log.debug("run()")
-
+ print "Book title?"
+ title = raw_input("> ")
+ print "Author(s)?"
+ author = raw_input("> ")
+ print "Path to new book project files?\n[default: current directory]"
+ path = raw_input("> ")
+
+ today = re.sub("^0", "", date.today().strftime("%d %b %Y"))
+ uuid = mdepub.new_id()
+ filename = options.get("filename") or clean(title)
+
+ log.debug("Creating project in \"%s\".", path)
+ if not exists(path):
+ os.makedirs(path)
+ os.chdir(path)
+
+ if exists("options.yaml"):
+ log.fatal("An mdepub project file already exists in this path.")
+ sys.exit(1)
+
+ shutil.copyfile(join(template_path, "book.css"), "{}.css".format(filename))
+
+ with open(join(template_path, "book.md"), 'r') as f: txt = f.read()
+ 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()
+ with open("options.yaml", 'w') as f:
+ f.write(
+ txt.format(Title=title, Author=author, Date=today, uuid=uuid)
+ )
View
@@ -26,7 +26,7 @@ def run():
r'\g<1>uuid:\g<2>' + str(new_id()) + r'\g<4>',
txt
)
- print txt
+ #print txt
with open("options.yaml", "w") as f: f.write(txt)
else:
# add new uuid field to end of file
View
@@ -0,0 +1,3 @@
+import os.path
+
+template_path = os.path.dirname(__file__)

0 comments on commit 706e120

Please sign in to comment.