Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
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 0f909fa
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 8 deletions.
20 changes: 13 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,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
Expand Down Expand Up @@ -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):
Expand All @@ -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")
Expand All @@ -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()
Expand Down
7 changes: 6 additions & 1 deletion nikola/utils.py
Expand Up @@ -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]
Expand Down

0 comments on commit 0f909fa

Please sign in to comment.