Navigation Menu

Skip to content

Commit

Permalink
fix unicode arguments (cc @felixfontein)
Browse files Browse the repository at this point in the history
Signed-off-by: Chris Warrick <kwpolska@gmail.com>
  • Loading branch information
Kwpolska committed May 20, 2015
1 parent 35b57a8 commit da075a0
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
21 changes: 14 additions & 7 deletions nikola/__main__.py
Expand Up @@ -48,7 +48,7 @@
from . import __version__
from .plugin_categories import Command
from .nikola import Nikola
from .utils import sys_decode, get_root_dir, req_missing, LOGGER, STRICT_HANDLER, ColorfulStderrHandler
from .utils import sys_decode, sys_encode, get_root_dir, req_missing, LOGGER, STRICT_HANDLER, ColorfulStderrHandler

if sys.version_info[0] == 3:
import importlib.machinery
Expand All @@ -71,20 +71,27 @@ def main(args=None):
if args is None:
args = sys.argv[1:]

oargs = args
args = [sys_decode(arg) for arg in args]


conf_filename = 'conf.py'
conf_filename_bytes = b'conf.py'
conf_filename_changed = False
for index, arg in enumerate(args):
if arg[:7] == b'--conf=':
if arg[:7] == '--conf=':
del args[index]
del oargs[index]
conf_filename = arg[7:]
conf_filename_bytes = sys_encode(arg[7:])
conf_filename_changed = True
break

quiet = False
if len(args) > 0 and args[0] == b'build' and b'--strict' in args:
if len(args) > 0 and args[0] == 'build' and '--strict' in args:
LOGGER.notice('Running in strict mode')
STRICT_HANDLER.push_application()
if len(args) > 0 and args[0] == b'build' and b'-q' in args or b'--quiet' in args:
if len(args) > 0 and args[0] == 'build' and '-q' in args or '--quiet' in args:
nullhandler = NullHandler()
nullhandler.push_application()
quiet = True
Expand Down Expand Up @@ -112,7 +119,7 @@ def main(args=None):
loader = importlib.machinery.SourceFileLoader("conf", conf_filename)
conf = loader.load_module()
else:
conf = imp.load_source("conf", conf_filename)
conf = imp.load_source("conf", conf_filename_bytes)
config = conf.__dict__
except Exception:
if os.path.exists(conf_filename):
Expand All @@ -129,7 +136,7 @@ def main(args=None):

invariant = False

if len(args) > 0 and args[0] == b'build' and b'--invariant' in args:
if len(args) > 0 and args[0] == 'build' and '--invariant' in args:
try:
import freezegun
freeze = freezegun.freeze_time("2038-01-01")
Expand All @@ -153,7 +160,7 @@ def main(args=None):
DN = DoitNikola(site, quiet)
if _RETURN_DOITNIKOLA:
return DN
_ = DN.run(args)
_ = DN.run(oargs)

if site.invariant:
freeze.stop()
Expand Down
2 changes: 1 addition & 1 deletion nikola/utils.py
Expand Up @@ -1149,7 +1149,7 @@ def get_root_dir():
root = os.getcwd()

while True:
if os.path.exists(os.path.join(root, 'conf.py')):
if os.path.exists(os.path.join(root, b'conf.py')):
return root
else:
basedir = os.path.split(root)[0]
Expand Down

0 comments on commit da075a0

Please sign in to comment.