Fix encoding issue in the init subcommand (fix #50).

This commit is contained in:
Simon Conseil
2013-12-21 22:27:10 +01:00
parent 1385341b5a
commit 9ddd49be4c
2 changed files with 16 additions and 4 deletions

View File

@@ -49,15 +49,17 @@ from .settings import read_settings
_DEFAULT_CONFIG_FILE = 'sigal.conf.py'
def init():
@arg('path', nargs='?', help='Path of the sample config file')
def init(path):
"""Copy a sample config file in the current directory."""
from pkg_resources import resource_string
path = path or 'sigal.conf.py'
conf = resource_string(__name__, 'templates/sigal.conf.py')
with io.open('sigal.conf.py', 'w', 'utf-8') as f:
f.write(conf)
print("Sample config file created: sigal.conf.py")
with io.open(path, 'w', encoding='utf-8') as f:
f.write(conf.decode('utf8'))
print("Sample config file created: {}".format(path))
@arg('source', nargs='?', help='Input directory')

10
tests/test_cli.py Normal file
View File

@@ -0,0 +1,10 @@
# -*- coding: utf-8 -*-
import os
from sigal import init
def test_init(tmpdir):
config_file = str(tmpdir.join('sigal.conf.py'))
init(path=config_file)
assert os.path.isfile(config_file)