Skip to content
Permalink
Browse files

Merge pull request #1738 from getnikola/fix-unicode-arguments

fix unicode arguments
  • Loading branch information
ralsina committed May 22, 2015
2 parents 833f3e4 + 2fbbf4a commit 0f909fafd0448cbbb6a42634b2895ad65fff89da
Showing with 19 additions and 8 deletions.
  1. +13 −7 nikola/__main__.py
  2. +6 −1 nikola/utils.py
@@ -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
@@ -71,20 +71,26 @@ 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
@@ -112,7 +118,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):
@@ -129,7 +135,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")
@@ -153,7 +159,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()
@@ -1148,8 +1148,13 @@ def get_root_dir():
"""Find root directory of nikola installation by looking for conf.py"""
root = os.getcwd()

if sys.version_info[0] == 2:
confname = b'conf.py'
else:
confname = 'conf.py'

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

0 comments on commit 0f909fa

Please sign in to comment.
You can’t perform that action at this time.