diff piecrust/commands/builtin/util.py @ 100:69d5eecfa449

Better `prepare` command, with templates and help topics.
author Ludovic Chabant <ludovic@chabant.com>
date Sat, 13 Sep 2014 23:31:21 -0700
parents 28958565a17b
children 2823ea40cfac
line wrap: on
line diff
--- a/piecrust/commands/builtin/util.py	Sat Sep 13 14:47:01 2014 -0700
+++ b/piecrust/commands/builtin/util.py	Sat Sep 13 23:31:21 2014 -0700
@@ -6,7 +6,6 @@
 import yaml
 from piecrust.app import CONFIG_PATH
 from piecrust.commands.base import ChefCommand
-from piecrust.sources.base import IPreparingSource, MODE_CREATING
 
 
 logger = logging.getLogger(__name__)
@@ -66,55 +65,6 @@
             shutil.rmtree(cache_dir)
 
 
-class PrepareCommand(ChefCommand):
-    def __init__(self):
-        super(PrepareCommand, self).__init__()
-        self.name = 'prepare'
-        self.description = "Prepares new content for your website."
-
-    def setupParser(self, parser, app):
-        # Don't setup anything if this is a null app
-        # (for when `chef` is run from outside a website)
-        if app.root_dir is None:
-            return
-
-        subparsers = parser.add_subparsers()
-        for src in app.sources:
-            if not isinstance(src, IPreparingSource):
-                logger.debug("Skipping source '%s' because it's not "
-                             "preparable." % src.name)
-                continue
-            if src.is_theme_source:
-                logger.debug("Skipping source '%s' because it's a theme "
-                             "source." % src.name)
-                continue
-            p = subparsers.add_parser(src.item_name)
-            src.setupPrepareParser(p, app)
-            p.set_defaults(source=src)
-
-    def run(self, ctx):
-        app = ctx.app
-        source = ctx.args.source
-        metadata = source.buildMetadata(ctx.args)
-        rel_path, metadata = source.findPagePath(metadata, MODE_CREATING)
-        path = source.resolveRef(rel_path)
-        name, ext = os.path.splitext(path)
-        if ext == '.*':
-            path = '%s.%s' % (name,
-                    app.config.get('site/default_auto_format'))
-        if os.path.exists(path):
-            raise Exception("'%s' already exists." % path)
-
-        logger.info("Creating page: %s" % os.path.relpath(path, app.root_dir))
-        if not os.path.exists(os.path.dirname(path)):
-            os.makedirs(os.path.dirname(path), 0o755)
-        with open(path, 'w') as f:
-            f.write('---\n')
-            f.write('title: %s\n' % 'Unknown title')
-            f.write('---\n')
-            f.write("This is a new page!\n")
-
-
 class ImportCommand(ChefCommand):
     def __init__(self):
         super(ImportCommand, self).__init__()