Now pecan create works.

This commit is contained in:
Ryan Petrello
2012-03-14 18:13:23 -07:00
parent 6ede5714ca
commit 0df3ea4ecd
3 changed files with 18 additions and 21 deletions

View File

@@ -11,14 +11,15 @@ class CreateCommand(BaseCommand):
"""
arguments = ({
'command': 'destination',
'help': 'the destination to create the new project'
}, {
'command': 'template_name',
'help': 'a registered Pecan template',
'nargs': '?',
'default': DEFAULT_SCAFFOLD
},)
})
def run(self, args):
super(CreateCommand, self).run(args)
print "NOT IMPLEMENTED"
print args.template_name
BaseScaffold().copy_to(args.template_name)
BaseScaffold().copy_to(args.destination)

View File

@@ -1,7 +1,7 @@
import sys
import os
import re
import pkg_resources
from string import Template
from pecan.compat import native_, bytes_
DEFAULT_SCAFFOLD = 'base'
@@ -23,10 +23,13 @@ class PecanScaffold(object):
@property
def variables(self):
return {}
return {
'package': self.dest
}
def copy_to(self, dest, **kwargs):
copy_dir(self.template_dir, dest, self.variables)
self.dest = dest
copy_dir(self.template_dir, self.dest, self.variables)
class BaseScaffold(PecanScaffold):
@@ -101,6 +104,10 @@ def copy_dir(source, dest, variables, out_=sys.stdout):
dest_full)
)
f = open(dest_full, 'wb')
f.write(content)
f.close()
def makedirs(directory):
parent = os.path.dirname(os.path.abspath(directory))
@@ -115,19 +122,9 @@ def substitute_filename(fn, variables):
return fn
def render_template(self, content, variables):
def render_template(content, variables):
""" Return a bytestring representing a templated file based on the
input (content) and the variable names defined (vars)."""
fsenc = sys.getfilesystemencoding()
content = native_(content, fsenc)
return bytes_(
substitute_double_braces(content, variables), fsenc)
def substitute_double_braces(content, values):
double_brace_pattern = re.compile(r'{{(?P<braced>.*?)}}')
def double_bracerepl(match):
value = match.group('braced').strip()
return values[value]
return double_brace_pattern.sub(double_bracerepl, content)
return bytes_(Template(content).substitute(variables), fsenc)

View File

@@ -7,7 +7,7 @@ except ImportError:
from setuptools import setup, find_packages
setup(
name = '${project}',
name = '${package}',
version = '0.1',
description = '',
author = '',
@@ -17,7 +17,6 @@ setup(
],
test_suite = '${package}',
zip_safe = False,
paster_plugins = ${egg_plugins},
include_package_data = True,
packages = find_packages(exclude=['ez_setup'])
)