Now pecan create works.
This commit is contained in:
@@ -11,14 +11,15 @@ class CreateCommand(BaseCommand):
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
arguments = ({
|
arguments = ({
|
||||||
|
'command': 'destination',
|
||||||
|
'help': 'the destination to create the new project'
|
||||||
|
}, {
|
||||||
'command': 'template_name',
|
'command': 'template_name',
|
||||||
'help': 'a registered Pecan template',
|
'help': 'a registered Pecan template',
|
||||||
'nargs': '?',
|
'nargs': '?',
|
||||||
'default': DEFAULT_SCAFFOLD
|
'default': DEFAULT_SCAFFOLD
|
||||||
},)
|
})
|
||||||
|
|
||||||
def run(self, args):
|
def run(self, args):
|
||||||
super(CreateCommand, self).run(args)
|
super(CreateCommand, self).run(args)
|
||||||
print "NOT IMPLEMENTED"
|
BaseScaffold().copy_to(args.destination)
|
||||||
print args.template_name
|
|
||||||
BaseScaffold().copy_to(args.template_name)
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import sys
|
import sys
|
||||||
import os
|
import os
|
||||||
import re
|
|
||||||
import pkg_resources
|
import pkg_resources
|
||||||
|
from string import Template
|
||||||
from pecan.compat import native_, bytes_
|
from pecan.compat import native_, bytes_
|
||||||
|
|
||||||
DEFAULT_SCAFFOLD = 'base'
|
DEFAULT_SCAFFOLD = 'base'
|
||||||
@@ -23,10 +23,13 @@ class PecanScaffold(object):
|
|||||||
|
|
||||||
@property
|
@property
|
||||||
def variables(self):
|
def variables(self):
|
||||||
return {}
|
return {
|
||||||
|
'package': self.dest
|
||||||
|
}
|
||||||
|
|
||||||
def copy_to(self, dest, **kwargs):
|
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):
|
class BaseScaffold(PecanScaffold):
|
||||||
@@ -101,6 +104,10 @@ def copy_dir(source, dest, variables, out_=sys.stdout):
|
|||||||
dest_full)
|
dest_full)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
f = open(dest_full, 'wb')
|
||||||
|
f.write(content)
|
||||||
|
f.close()
|
||||||
|
|
||||||
|
|
||||||
def makedirs(directory):
|
def makedirs(directory):
|
||||||
parent = os.path.dirname(os.path.abspath(directory))
|
parent = os.path.dirname(os.path.abspath(directory))
|
||||||
@@ -115,19 +122,9 @@ def substitute_filename(fn, variables):
|
|||||||
return fn
|
return fn
|
||||||
|
|
||||||
|
|
||||||
def render_template(self, content, variables):
|
def render_template(content, variables):
|
||||||
""" Return a bytestring representing a templated file based on the
|
""" Return a bytestring representing a templated file based on the
|
||||||
input (content) and the variable names defined (vars)."""
|
input (content) and the variable names defined (vars)."""
|
||||||
fsenc = sys.getfilesystemencoding()
|
fsenc = sys.getfilesystemencoding()
|
||||||
content = native_(content, fsenc)
|
content = native_(content, fsenc)
|
||||||
return bytes_(
|
return bytes_(Template(content).substitute(variables), fsenc)
|
||||||
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)
|
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ except ImportError:
|
|||||||
from setuptools import setup, find_packages
|
from setuptools import setup, find_packages
|
||||||
|
|
||||||
setup(
|
setup(
|
||||||
name = '${project}',
|
name = '${package}',
|
||||||
version = '0.1',
|
version = '0.1',
|
||||||
description = '',
|
description = '',
|
||||||
author = '',
|
author = '',
|
||||||
@@ -17,7 +17,6 @@ setup(
|
|||||||
],
|
],
|
||||||
test_suite = '${package}',
|
test_suite = '${package}',
|
||||||
zip_safe = False,
|
zip_safe = False,
|
||||||
paster_plugins = ${egg_plugins},
|
|
||||||
include_package_data = True,
|
include_package_data = True,
|
||||||
packages = find_packages(exclude=['ez_setup'])
|
packages = find_packages(exclude=['ez_setup'])
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user