make pelican-quickstart and the Makefile it generates support py3k.

This commit is contained in:
Chenguang Wang 2013-02-01 15:35:48 -08:00 committed by Alexis Métaireau
commit 5e4622b229
3 changed files with 21 additions and 5 deletions

View file

@ -37,6 +37,7 @@ def _input_compat(prompt):
if six.PY3:
r = input(prompt)
else:
# FIXME: why use this with @decoding_strings?
r = raw_input(prompt).decode('utf-8')
return r
@ -50,7 +51,10 @@ def decoding_strings(f):
out = f(*args, **kwargs)
if isinstance(out, six.string_types) and not six.PY3:
# todo: make encoding configurable?
return out.decode(sys.stdin.encoding)
if six.PY3:
return out
else:
return out.decode(sys.stdin.encoding)
return out
return wrapper
@ -243,7 +247,14 @@ needed by Pelican.
if mkfile:
try:
with codecs.open(os.path.join(CONF['basedir'], 'Makefile'), 'w', 'utf-8') as fd:
for line in get_template('Makefile'):
mkfile_template_name = 'Makefile'
py_v = 'PY=python'
if six.PY3:
py_v = 'PY=python3'
template = string.Template(py_v)
fd.write(template.safe_substitute(CONF))
fd.write('\n')
for line in get_template(mkfile_template_name):
template = string.Template(line)
fd.write(template.safe_substitute(CONF))
fd.close()
@ -258,7 +269,12 @@ needed by Pelican.
conf_shell[key] = value
try:
with codecs.open(os.path.join(CONF['basedir'], 'develop_server.sh'), 'w', 'utf-8') as fd:
for line in get_template('develop_server.sh'):
lines = list(get_template('develop_server.sh'))
py_v = 'PY=python\n'
if six.PY3:
py_v = 'PY=python3\n'
lines = lines[:4] + [py_v] + lines[4:]
for line in lines:
template = string.Template(line)
fd.write(template.safe_substitute(conf_shell))
fd.close()