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: if six.PY3:
r = input(prompt) r = input(prompt)
else: else:
# FIXME: why use this with @decoding_strings?
r = raw_input(prompt).decode('utf-8') r = raw_input(prompt).decode('utf-8')
return r return r
@ -50,7 +51,10 @@ def decoding_strings(f):
out = f(*args, **kwargs) out = f(*args, **kwargs)
if isinstance(out, six.string_types) and not six.PY3: if isinstance(out, six.string_types) and not six.PY3:
# todo: make encoding configurable? # 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 out
return wrapper return wrapper
@ -243,7 +247,14 @@ needed by Pelican.
if mkfile: if mkfile:
try: try:
with codecs.open(os.path.join(CONF['basedir'], 'Makefile'), 'w', 'utf-8') as fd: 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) template = string.Template(line)
fd.write(template.safe_substitute(CONF)) fd.write(template.safe_substitute(CONF))
fd.close() fd.close()
@ -258,7 +269,12 @@ needed by Pelican.
conf_shell[key] = value conf_shell[key] = value
try: try:
with codecs.open(os.path.join(CONF['basedir'], 'develop_server.sh'), 'w', 'utf-8') as fd: 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) template = string.Template(line)
fd.write(template.safe_substitute(conf_shell)) fd.write(template.safe_substitute(conf_shell))
fd.close() fd.close()

View file

@ -53,7 +53,7 @@ regenerate: clean
$$(PELICAN) -r $$(INPUTDIR) -o $$(OUTPUTDIR) -s $$(CONFFILE) $$(PELICANOPTS) $$(PELICAN) -r $$(INPUTDIR) -o $$(OUTPUTDIR) -s $$(CONFFILE) $$(PELICANOPTS)
serve: serve:
cd $$(OUTPUTDIR) && python -m pelican.server cd $$(OUTPUTDIR) && $(PY) -m pelican.server
devserver: devserver:
$$(BASEDIR)/develop_server.sh restart $$(BASEDIR)/develop_server.sh restart

View file

@ -65,7 +65,7 @@ function start_up(){
pelican_pid=$$! pelican_pid=$$!
echo $$pelican_pid > $$PELICAN_PID echo $$pelican_pid > $$PELICAN_PID
cd $$OUTPUTDIR cd $$OUTPUTDIR
python -m pelican.server & $PY -m pelican.server &
srv_pid=$$! srv_pid=$$!
echo $$srv_pid > $$SRV_PID echo $$srv_pid > $$SRV_PID
cd $$BASEDIR cd $$BASEDIR